Forum Replies Created

Viewing 1 post (of 1 total)
  • Author
    Posts
  • in reply to: Convert XML to PDF with SSL resources
    #29762

    Thank you for your reply.

    The code is from our legacy project. It takes XML file from database and transform it, output is a PDF file. There is a link to remote HTTPS xslt file in XML, and that xslt file contains URLs to remote HTTPS image. If it is a local xslt file, the code works just fine. Could you shed some light? Here is the code with comments:

    /**
    * Generates a PDF document from an XML file that requires transformation using an
    * XSL stylesheet.
    *
    * @param sourceStream The source XML document stream.
    * @param targetStream The target PDF document stream.
    * @param headerText Text to display as a page header in the target PDF.
    * @param forcePrint Whether or not to force the print dialog to appear when the PDF is loaded.
    *
    * @throws Exception If something goes wrong while transforming the XML or generating the PDF.
    */
    public void generatePdf(InputStream sourceStream, OutputStream targetStream, String headerText, boolean forcePrint) throws Exception {
    PD4ML converter = new PD4ML();
    if (headerText != null) {
    PD4PageMark header = new PD4PageMark();
    Font font = header.getFont();
    Font boldFont = font.deriveFont(Font.BOLD);
    header.setFont(boldFont);
    header.setTitleTemplate(headerText);
    converter.setPageHeader(header);
    }
    PD4PageMark footer = new PD4PageMark();
    footer.setPageNumberTemplate("Page $[page] of $[total]");
    footer.setPageNumberAlignment(PD4PageMark.CENTER_ALIGN);
    converter.setPageFooter(footer);
    converter.setPageSize(PD4Constants.A4);
    converter.setPageInsetsMM(new Insets(10, 10, 10, 10));
    converter.setHtmlWidth(820);
    if (forcePrint) {
    Map<String, String> dynamicParameters = new HashMap<String, String>();
    dynamicParameters.put(PD4Constants.PD4ML_PRINT_DIALOG_POPUP, "true");
    converter.setDynamicParams(dynamicParameters);
    }
    converter.render(new InputStreamReader(sourceStream, "UTF-8"), targetStream);
    }

Viewing 1 post (of 1 total)