-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi, I'm facing the following problem using iframe.
I have an iframe which specifies as src attribute the invoking to a servlet which returns a response of application/pdf type.
Having the same input, using Mozilla Firefox (ver. 3.0.8), random it shows a blank frame... sometimes it works... Especially, it seems that the first time after the server has been restarted, it works well, while the next time usually a blank frame is shown.
Using IE 7, it always works well.
Servlet invoked has the purpose to concatenate a list of pdf files (always created successfully on file system) into a single response of application/pdf type.
This is the window containing iframe:
<window title="---" width="90%" height="90%" mode="modal" border="normal" closable="true"> <zscript> labelsPDFDocuments = ... // servlet to invoke plus parameters </zscript> <iframe id="iframe" src="${labelsPDFDocuments}" width="100%" height="100%"/> <attribute name="onCreate"> self.setParent(parentWin); </attribute> <attribute name="onClose"> FileUtil.deleteLabelFiles(labelsPDFDocuments.substring(labelsPDFDocuments.indexOf("=") + 1), "|"); </attribute> </window>
public class LabelViewerServlet extends HttpServlet { private static final long serialVersionUID = -7306259114973684722L; private static final String K_PARM_LABELS = "labels"; private static final String K_HTML_MIME_TYPE = "text/html"; private static final String K_PDF_MIME_TYPE = "application/pdf"; protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { process(request, response); } catch (Exception e) { response.setContentType(K_HTML_MIME_TYPE); response.getOutputStream().println(e.toString()); } } private void process(HttpServletRequest a_request, HttpServletResponse a_response) throws Exception { // gets the list of pdf files to concatenate (they are specified as labels=filename1.pdf|filename2.pdf|filename3.pdf String ls_labelsPDF = a_request.getParameter(K_PARM_LABELS); if (StringUtil.isEmpty(ls_labelsPDF)) throw new Exception("Error..."); StringTokenizer l_lpst = new StringTokenizer(ls_labelsPDF, "|"); ArrayList<InputStream> l_labelsPDF = new ArrayList<InputStream>(5); while (l_lpst.hasMoreTokens()) { String ls_labelPDF = l_lpst.nextToken(); l_labelsPDF.add(new FileInputStream(this.getServletContext().getRealPath("/labels") + "\\" + ls_labelPDF)); } a_response.setContentType(K_PDF_MIME_TYPE); OutputStream l_os = a_response.getOutputStream(); // merging... PdfUtil.mergePdf(l_labelsPDF, l_os); l_os.flush(); l_os.close(); } }
We met this problem before because Acrobat Reader + Firefox are not good couple at that time.
Especially when there's a lot of DOM objects displayed by a Firefox who try to hook Acrobat Reader(really fat) with tons of plug-ins.
Seems they go no match again.
Currently I can only suggest you to keep your page simple, maybe open your PDF in different browser window.
If there's any workaround I'll post it here.
We found this solution (method LabelRequest.request() returns a ByteArrayOutputStream with pdf data):
<window title="---" width="90%" height="90%" mode="modal" border="normal" closable="true"> <zscript> <![CDATA[ void load() { LabelRequest labelRequest = new LabelRequest(...); java.io.ByteArrayOutputStream labelsPDFDocumentsOS = (java.io.ByteArrayOutputStream)labelRequest.request(); byte[] bcontent = labelsPDFDocumentsOS.toByteArray(); // close output stream labelsPDFDocumentsOS.close(); org.zkoss.util.media.AMedia media = new org.zkoss.util.media.AMedia("labels", "pdf", "application/pdf", bcontent); iframe.setContent(media); } ]]> </zscript> <iframe id="iframe" width="100%" height="100%"> <attribute name="onCreate"> Clients.showBusy("Loading...", true); Events.echoEvent("onLater", self, null); </attribute> <attribute name="onLater"> Thread.sleep(2000); Clients.showBusy(null, false); load(); </attribute> </iframe> </window>
Asked: 2009-04-02 08:02:26 +0800
Seen: 1,510 times
Last updated: Apr 06 '09