HTML to PDF / DOCX / RTF Java converter library › Forums › PD4ML v3 Archived Forums (Read Only) › PD4ML Tips & Tricks › How to render multiple Notes Documents to single PDF output?
- This topic has 1 reply, 2 voices, and was last updated Nov 25, 2009
07:15:43 byPD4ML.
-
AuthorPosts
-
June 16, 2009 at 20:52#26206
Hi,
Is there sample code to render multiple Notes documents (selected from a Notes view) to a single output pdf? Each Notes Document should be separated by a page break within the output pdf file.
Any examples or pointers are greatly appreciated.
Thanks
SVNovember 25, 2009 at 07:15#27332I would implement the multi-doc converter this way (replace the correspondingreference agent https://pd4ml.com/i/PdfAgentR7.java methods with the following):
public void NotesMain() { try { Session session = getSession(); AgentContext agentContext = session.getAgentContext(); System.out.println("AGENT start."); Database db = agentContext.getCurrentDatabase(); String xsl = null; if (readXslFromJar) { xsl = getXsl(); } else { DocumentCollection dcx = db.search("@Contains(Form; "" + xslDocumentFormName + "")"); Document xsldoc = dcx.getFirstDocument(); if (xsldoc != null) { xsl = xsldoc.getItemValueString(xslDocumentFieldName); } else { throw new IOException( "Can not find " + xslName); } } // System.out.println("XSL: " + xsl); // collect selected documents DocumentCollection dc = agentContext.getUnprocessedDocuments(); URL[] urls = new URL[dc.getCount()]; int ind = 0; Document doc = dc.getFirstDocument(); while (doc != null) { Document tmp = db.createDocument(); RichTextItem rti = tmp.createRichTextItem("PD4MLBody"); doc.renderToRTItem(rti); DxlExporter dxl = session.createDxlExporter(); dxl.setConvertNotesBitmapsToGIF(true); dxl.setOutputDOCTYPE(false); String xml = dxl.exportDxl(tmp); String xml = getTestDxl(); System.out.println("DXL FORM: " + xml); System.out.println("TRANS: " + System.getProperty("java.version")); System.out.println("TRANS: " + System.getProperty("java.vm.version")); System.out.println("TRANS: " + System.getProperty("java.vm.vendor")); System.out.println("TRANS: " + System.getProperty("java.vm.name")); long start = System.currentTimeMillis(); String html = transformXML(xml, xsl); long middle = System.currentTimeMillis(); System.out.println("XSL transformation: " + (middle-start) + "ms"); System.out.println("HTML: " + html); File htmlFile = File.createTempFile("pd4dxl", ".html"); java.io.FileOutputStream fos = new java.io.FileOutputStream( htmlFile ); fos.write( html.getBytes() ); urls[ind++] = htmlFile.toURL(); doc = dc.getNextDocument(); } File pdf = File.createTempFile("pd4ml", ".pdf"); java.io.FileOutputStream fos = new java.io.FileOutputStream(pdf); generatePDF( urls, fos, PD4Constants.A4, "java:/fonts", "<font color="green" face="tahoma">DXL to PDF convesion result." + " $[page] of $[total]</font>"); System.out.println("PDF file " + pdf.toURL() + " is generated" ); System.out.println("AGENT done."); } catch (SAXException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } public static final void generatePDF(URL[] urls, OutputStream fos, Dimension format, String fontsDir, String footerBody) throws Exception { PD4ML pd4ml = new PD4ML(); pd4ml.setPageInsets(new Insets(20, 10, 10, 10)); pd4ml.setHtmlWidth(1000); pd4ml.setPageSize(format); if (fontsDir != null && fontsDir.length() > 0) { pd4ml.useTTF(fontsDir, true); } if (footerBody != null && footerBody.length() > 0) { PD4PageMark footer = new PD4PageMark(); footer.setAreaHeight(-1); footer.setHtmlTemplate(footerBody); pd4ml.setPageFooter(footer); } pd4ml.render( urls, fos); fos.flush(); fos.close(); }The code is schematic and needs to be optimized.
After the resulting PDF is stored/sent/etc, the TEMP directory needs to be cleaned up. So it makes sence to register object references, created by the calls
File htmlFile = File.createTempFile("pd4dxl", ".html"); File pdf = File.createTempFile("pd4ml", ".pdf");and to remove them later, close to the agent code end.
-
AuthorPosts
The forum ‘PD4ML Tips & Tricks’ is closed to new topics and replies.
