Save inline PDF doc shows JSP page name not PDF filename

Hi,

Wondering if anyone can help me with a problem I’m having right now. I am currently working on a page to display a full client report as PDF in a webpage. This I’ve managed to achieve by setting the content type to PDF and outputting the binary stream generated by WIDocuments.getPDFView() directly into the ServletOutputStream.

So far, so good : Acrobat viewer loads automatically and the document is displayed.

However, there is no control over the way the Acrobat presents - by default you get the bookmark tabs visible on the left and the full menu bar on the top. If anyone knows how to do anything about this I’d be grateful.

My main problem is that if I use the ‘Save a Copy’ button the filename that is suggested by the Save As dialog box is the name of the JSP page, not the name of the PDF file. Equally, if you select the Email button, you get a email with the link in the subject, and no PDF attachment.

Really ‘interesting’ is that if you change the line

response.setHeader("Content-disposition", "inline; filename=\"" + wiDoc.getName() + ".pdf\"");

to

response.setHeader("Content-disposition", "attachment; filename=\"" + wiDoc.getName() + ".pdf\"");

so that the file is pushed directly to the browser for the user to download, the PDF filename is displayed correctly.

Anyway, code as follows. If anyone has any experience with this I’d be really grateful to hear from you.

I’m using Acrobat 7 Professional.

Cheers
Tom

Just to explain the page: it is called from another page which has opened a document, refeshed it and saved the DocumentStorageToken in a cookie called DST. There is an optional parameter ‘report’ which, if passed, will set the report displayed. By default though, and if no parameter is passed, the first report will be shown.


<%  response.setDateHeader("expires", 0);%>
<%@ page language="java" contentType="application/pdf"%>
<%@ page import ="com.bo.infoview.WIRequestWrapper"%>

//Prep browser to diplay page as PDF
request = WIRequestWrapper.setCharacterEncoding(request, "UTF-8");
response.setHeader("Content-Type", "application/pdf");


<%@ page import = "com.bo.wibean.*, com.bo.rebean.wi.*" %>
<%@ page import = "java.lang.StringBuffer"%>
<%@ page errorPage="tools/userError.jsp"%>
<jsp:useBean id="wiServer" class="com.bo.wibean.WIServerImpl" scope="application"/>

<%
//Validate the page
wiServer.onStartPage(request,response);
WISession wiSession = wiServer.getSession(); 
%>
<%@ include file="tools/validateSession.jsp"%>
<%

Cookie[] cookies   = request.getCookies();
Cookie   tmpCookie = null;  
String   tmpString = null;

for (int i=0; i<cookies.length; i++) {
  tmpCookie = cookies[i];
  if (tmpCookie.getName().equals("DST")) {
    tmpString = tmpCookie.getValue();
  }
}

WIDocument wiDoc = wiSession.getDocumentFromStorageToken(tmpString);
String   sReport = request.getParameter("report");
int      iReport = 0;

if (sReport!=null) { iReport = Integer.parseInt(sReport);}


WIPDFView wiPdfView = wiDoc.getPDFView();

//Use indexes to retrieve a particular page - in this case we'll just retrieve the page
String[] PDFIndexes = wiPdfView.getPDFIndexes();
byte[] binaryContent = wiPdfView.getContent(PDFIndexes[iReport]);
//byte[] binaryContent = wiPdfView.getContent(""); <<This retrieves the whole document

response.setHeader("Content-disposition", "inline; filename=\"" + wiDoc.getName() + ".pdf\"");
response.setContentLength(binaryContent.length);

ServletOutputStream sOS = response.getOutputStream();
sOS.write(binaryContent, 0, binaryContent.length);
sOS.flush();
sOS.close();

wiServer.onEndPage();

%>

Tom Matthews :de: (BOB member since 2005-02-18)

I know this is a longshot since the original message was posted a year and a half ago, but I’m having the exact same problem, and this is the only place I’ve seen a post of the specific issue I’m having.

Tom, if you’re still out there, can you please let me know if you were able to resolve this issue somehow?

Thanks.

Lou Valentine


LouValentine (BOB member since 2007-03-05)

The filename appears to the browser as the name of the resource being retrieved, and browsers often use that name in as the value when you click the “Save button”. So in many cases and browsers the servlet or JSP name calling to view the inline PDF will be used. A way around this would be to move your code to a servlet and include the download file’s name as extra path information to the servlet. Basically, map the URL as follows in the web.xml servlet mapping to accept * or *.pdf in the url pattern:

 <servlet-mapping>
    <servlet-name>ViewControllerServlet</servlet-name>
    <url-pattern>/ViewControllerServlet/*</url-pattern>
</servlet-mapping>

Then add the PDF filename to the call to the servlet like something like the following:

“/ViewControllerServlet/” +docName + “.pdf?operation=pdf&sDoc=”+ sDocName +"&entry="+sEntry;


Rajeev33 (BOB member since 2008-04-28)