PD4ML v4 Forums PD4ML v3 Archived Forums (Read Only) PD4ML Tips & Tricks How to render multiple Notes Documents to single PDF output?

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #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
    SV

    #27332

    I would implement the multi-doc converter this way (replace the correspondingreference agent http://pd4ml.com/i/PdfAgentR7.java methods with the following):

    [language=java:9u9s00sk]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”,
    DXL to PDF convesion result.” +
    ” $[page] of $[total]
    “);

    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();
    }[/language:9u9s00sk]

    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.

Viewing 2 posts - 1 through 2 (of 2 total)

The forum ‘PD4ML Tips & Tricks’ is closed to new topics and replies.