Which product are you using?
PDF.js Express Version
Detailed description of issue
{ I’m working on a Java JSP Struts project which has previously implemented PDF.js for previewing documents. Because of the the PDF.js library didn’t support watermarks option I decided to move to PDF.js Express.
The getImage.do
will go to the GetImageAction.java
page and generate and get the PDF file,
I have added the previous implementation code below.
I have tried to add the previous location URL path like this
encodeURIComponent('${pageContext.request.contextPath}/getImage.do?imageDocID='+document.getElementById('imageDocID').value);
but this is not a file path, so the webViewer shows this error by identifying .do as the file extension.
File extension do%3fimagedocid%3dww222244 is not supported. Please see http://r.pdftron.com/fileformats for a full list of file formats supported by WebViewer. If this file is actually valid then you can pass the 'extension' option with the intended file extension e.g. const doc = await Core.createDocument("http://domain/file11243. php", [extension: "pdf"})
the initialDoc value is %2FWEB_SSD%2FgetImage.do%3FimageDocID%3DWW222244
}
So do you any other method to add the initialDoc value as my previously implemented method?
Expected behaviour
{ I want to view the generating PDF via the pdf.js express viewer.}
Does your issue happen with every document, or just one?
{Every Document}
Link to document
{The document is created as a byte stream, So I don’t have any document location to add it the initialDoc property.}
Code snippet
The below code snippet is the previous implementation
{
html body
<iframe id="content" style='height: 600px; width: 98%; min-width: 900px;' scrolling="no" src=""></iframe>
script
<script type="text/javascript">
$(document).ready(function() {
var base='web/viewer.html?file=';
var subUrl=encodeURIComponent('${pageContext.request.contextPath}/getImage.do?imageDocID='+document.getElementById('imageDocID').value);
var url=base+subUrl+'#page=1';
$('#content').attr('src',url);
});
</script>
struts-config
<action
path="/getImage"
type="web.ead.webapp.ssd.common.action.GetImageAction"
scope="request">
</action>
GetImageAction.java
public class GetImageAction extends GenericAction {
static Object imageServerLock = new Object();
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException, Exception {
UserProfile userProfile = (UserProfile) request.getSession().getAttribute("UserProfile");
ActionForward actionForward = null;
String imageDocID = request.getParameter("imageDocID");
if (actionForward == null)
{
byte[] appletData = ImageManager.getMod2TifImage(imageDocID);
ObjectOutputStream outputToApplet = new ObjectOutputStream(response.getOutputStream());
outputToApplet.writeObject(appletData);
outputToApplet.flush();
outputToApplet.close();
actionForward = null;
}
return actionForward;
ActionForward actionForward = null;
try{
actionForward = super.execute(mapping, form, request, response);
String imageDocID = request.getParameter("imageDocID");
System.out.println(new Timestamp(System.currentTimeMillis()).toString() + "\trequest.getRemoteAddr() "
+ request.getRemoteAddr()
+ " Utility.getClientIp(request) : "
+ Utility.getClientIp(request) + " - " + imageDocID
+ " UserProfileID: " + userProfile.getUserProfileID());
byte[] image = null;
synchronized (imageServerLock) {
if(request.getSession().getAttribute("IMAGE-"+imageDocID) != null)
image = (byte[]) request.getSession().getAttribute("IMAGE-"+imageDocID);
if (actionForward == null) {
byte[] dest = addWatemark(image);
try{
PdfReader reader = new PdfReader(dest);
int pages = reader.getNumberOfPages();
}catch(Exception ex){
ex.printStackTrace();
image = ImageManager.optimizePDF(image);
dest = addWatemark(image);
}
response.setContentType("application/pdf");
OutputStream outs = response.getOutputStream();
outs.write(dest);
outs.close();
actionForward = null;
if(request.getSession().getAttribute("IMAGE-"+imageDocID) != null)
request.getSession().removeAttribute("IMAGE-"+imageDocID);
}
}
}catch(Exception e){
e.printStackTrace();
}
LoggerUtils.info(this.getClass().getName() + " - execute method --> Exit");
return actionForward;
}
}