HTML to PDF / DOCX / RTF Java converter library Forums PD4ML v3 Archived Forums (Read Only) Troubleshooting pd4ml in a .jspx file used with success – up to a point ….

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
  • #26647

    Like many people these days I use .jspx files.

    I have successfully made a perfectly rendered .pdf file by using the pd4ml:transform tag in a classic ‘apache tiles’ default.jspx file.

    As you may know, the default.jspx file is a useful shell that you can place round any number of other nested .jspx files.

    In fact for this reason the default.jspx file would be a perfect place to put my pd4ml:transform tags, where I would use the ‘enable’ attribute to turn pdf production on and off.

    Unfortunately only ‘enable=true’ works.

    If I use ‘enable=false’, I get the dreaded error:
    ‘getOutputStream() has already been called for this response’.

    I have of course read your faqs and know that the transform tag should be placed in a position where any possible white spaces before it have been removed.

    Unfortunately however .jspx files insist on outputting the root xml tag before the transform tag can kick in (I can see this in the compiled class for the .jspx file) but this is only a problem when enable=false. And I need the root xml tag because it contains the url of the .tld file for pd4ml.

    Firstly I was just wondering why there is this problem, because obviously pd4ml should be quiet and mind its own business when enable=false.

    Secondly just wondering if you can think of any possible solution for this.

    Thank you for your time.


    Perhaps my question was too complicated.

    The real question is:
    Has anybody successfully created .pdfs from .jspx files and Apache Tiles?
    If so please post an example, it would be greatly appreciated.

    I can’t get pd4ml:transform to work with enable=false, only with enable=true.

    With enabled=false I get the ‘outputstream already called’ error

    Thank you for your time.


    Could you please publish a sample of your .jspx page?


    I have the latest version of pd4ml 3.8.0

    Here’s the code (just change enable to “true” and it produces a .pdf, but with enable=”false” I get the exception):

    <root xmlns:pd4ml=""<br /> xmlns:jsp=""<br /> xmlns:c=""><pd4ml:transform enable="false"<br /> pageFormat="A4"<br /> pageOrientation="Portrait"<br /> screenWidth="610"<br /> pageInsets="10,50,20,50,points"<br /> enableTableBreaks="true"<br /> inline="false"<br /> fileName="hello.pdf"<br /> debug="true"><pd4ml:usettf from="java:fonts" serif="Times New Roman" sansserif="Arial" monospace="Courier New"/><pd4ml:permissions password="empty" rights="2068" strongEncryption="false"/><html xmlns:html=""<br /> xmlns:tiles=""<br /> xmlns:form=""<br /> xmlns:spring=""<br /> xmlns:roo="urn:jsptagdir:/WEB-INF/tags"<br /> xmlns:security="" version="2.0"><br /> <jsp:output doctype-root-element="HTML" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"<br /> doctype-system=""/><br /> < contentType="text/html;charset=UTF-8" /><br /> < pageEncoding="UTF-8" /><br /> <head><br /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><br /> <meta http-equiv="X-UA-Compatible" content="IE=8" /><br /> <link rel="stylesheet" href="/contabilita/css/int/general.css" type="text/css"/><br /> <link rel="stylesheet" href="/contabilita/css/int/header.css" type="text/css"/><br /> <script type="text/javascript" src="/javascript/mootools141.js"><!-- required by FF and opera --></script><br /> <title>A title</title><br /> </head><br /> <br /> <body><br /> <div id="wrapperVit"><br /> <tiles:insertAttribute name="header" ignore="true" /><br /> <div id="main" style="padding-top: 10px;"><br /> <tiles:insertAttribute name="body"/><br /> </div><br /> </div><br /> </body><br /> <br /> <br /> </html><br /> <br /> <br /> </pd4ml:transform><br /> <br /> </root>


    OK, now try to substitute all occurrences of “pd4ml:” with “pd4mlXXX”, try to open the page in a web browser and open the generated HTML document source.

    Are there any whitespaces before ?


    Ok, done that.

    .jspx files always put the xml version line and the doctype declaration, right at the top, followed by new lines.

    <?xml version="1.0" encoding="UTF-8"?><br /> <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" ""><br /> <root>…..
    once the element begins there are no white spaces.

    You can remove the top xml declaration by including this in the .jspx file
    <jsp:output omit-xml-declaration="yes" />
    and I can remove the doctype declaration if I want to by excluding this line from the code:
    <jsp:output doctype-root-element="HTML" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system=""/>

    which I did, even though obviously these days a doc-type declaration is important.

    Doing that I have source without any white spaces before the transform tag.
    But it still doesn’t work if I put enabled=”false”.

    Please also bear in mind that with enabled=”true” and without omitting the doc-type or any other attempted hack, it produces perfect .pdfs. The only problem is enabled=”false”.

    But for me the enabled true/false functionality would be fundamental.
    Thanks for your help and time.


    Just wondering if you can give me any news at all about this.

    We’ve invested a lot in .jspx files and this unexpected problem is holding us up quite a bit.
    Have you verified the problem and is this something that can be solved?

    Any news would be gratefully received, thanks, so that I can decide what to do.


    > even though obviously these days a doc-type declaration is important.

    Not in PD4ML scenario. By a PDF generation the browser expects to receive PDF bytes only. If the response is leaded by the XML declaration, first: the data is misleading, as it is not “xhtml-strict” in fact; second: the declaration bytes break all object offsets in the document. Acroread can recover it on-a-fly, but it is not safe and by slow systems a pop-up with “rebuilding xref table” (or something like that) may appear.

    PD4ML itself simply ignores the declaration.

    The enable=”false” issue is in our TODO list for the next beta.


    Thank you very much for your reply.

    If possible I’d like an email advice for the beta once the fix is available.
    Thanks again.


    Was this ever fixed?
    I had hoped to get an email advice, but never got one.

    I suppose I shall have to buy 3.9, but if I do, can you confirm that the enabled parameter will work?



    As I see the patch still has not been applied to the main dev branch. Request support pd4ml com for a trial. If it fixes the problem, we’ll provide you with a patched commercial version after a purchase. (And of course the patch will be integrated to forthcoming versions)

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

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