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 (BOB member since 2005-02-18)