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 ….
- This topic has 10 replies, 3 voices, and was last updated Aug 26, 2014
12:11:22 by PD4ML.
-
AuthorPosts
-
January 4, 2012 at 22:17#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.
January 24, 2012 at 09:08#28753Perhaps 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.
January 24, 2012 at 11:44#28754Could you please publish a sample of your .jspx page?
January 24, 2012 at 13:58#28755I 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="http://pd4ml.com/tlds/pd4ml/2.6"<br /> xmlns:jsp="http://java.sun.com/JSP/Page"<br /> xmlns:c="http://java.sun.com/jsp/jstl/core"><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="http://www.w3.org/1999/xhtml"<br /> xmlns:tiles="http://tiles.apache.org/tags-tiles"<br /> xmlns:form="http://www.springframework.org/tags/form"<br /> xmlns:spring="http://www.springframework.org/tags"<br /> xmlns:roo="urn:jsptagdir:/WEB-INF/tags"<br /> xmlns:security="http://www.springframework.org/security/tags" version="2.0"><br /> <jsp:output doctype-root-element="HTML" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"<br /> doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml-strict.dtd"/><br /> <jsp:directive.page contentType="text/html;charset=UTF-8" /><br /> <jsp:directive.page 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>
January 24, 2012 at 14:09#28756OK, 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
? February 6, 2012 at 13:30#28757Ok, 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" "http://www.w3.org/TR/xhtml1/DTD/xhtml-strict.dtd"><br /> <root>
…..
once theelement 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="http://www.w3.org/TR/xhtml1/DTD/xhtml-strict.dtd"/>
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.February 6, 2012 at 13:34#28758Just 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.
February 6, 2012 at 15:55#28759> 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.
February 7, 2012 at 15:05#28760Thank you very much for your reply.
If possible I’d like an email advice for the beta once the fix is available.
Thanks again.August 26, 2014 at 09:32#28761Was 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?
Thanks
August 26, 2014 at 12:11#28762As 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)
-
AuthorPosts
The forum ‘Troubleshooting’ is closed to new topics and replies.