Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #27025

    We have an application using PD4ML to transform XML and export into PDF. There are issues when it requires SSL resources.
    1. Some XMLs refers to remote SSL xsl file, for example:

    2. Some xsl file refers to remote SSL image files, for example:

    Here are some of our codes to generate 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 dynamicParameters = new HashMap();
    dynamicParameters.put(PD4Constants.PD4ML_PRINT_DIALOG_POPUP, “true”);
    converter.setDynamicParams(dynamicParameters);
    }
    converter.render(new InputStreamReader(sourceStream, “UTF-8”), targetStream);
    }

    The code couldn’t get HTTPS xlt file and couldn’t transform XML. Is there a workaround to solve it with PD4ML?

    Thank you very much.

    #29761

    From your problem description the usage scenario is not quite clear. Do you pass XML+XSL reference directly to PD4ML? In the case it should not work: PD4ML accepts as an input format HTML only (well, also SVG). Before a converting to PDF you need to transform the XML to HTML.

    For a case it cannot load images/CSS by HTTPS:

    PD4ML does not “officially” support HTTPS, however it implements very basic HTTPS resource loader (using the standard JDK classes). For example, WebSphere and Weblogic implement their own versions of HTTPS protocol, and the implementations are not derived from the standard API. That causes ClassCastExceptions on the platforms by attempts to load HTTPS resources.

    In order to workaround such issues PD4ML supports so-called custom resource loaders.

    pd4ml-html-css-pdf-tips-tricks-f7/a-definition-of-custom-resource-loaders-t40.html

    If it is your case, you may implement your own HTTPS loader, utilizes Weblogic SSL classes. I’ve attached our standard SSL loader implementation, which could give you some implementation ideas.

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

    #29760

    Hmm… In the code PD4ML API assumes, that InputStream sourceStream returns HTML.

    There was no PD4ML version, which could implicitly transform XML to HTML. The transformation should be done in advance to PD4ML API call.

    If the comment means XHTML under “XML”, the conversion will work, but anyway any XSL references will be ignored.

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

The forum ‘Troubleshooting’ is closed to new topics and replies.