HTML to PDF / DOCX / RTF Java converter library › Forums › PD4ML v3 Archived Forums (Read Only) › HTML/CSS rendering issues › PDF rendition appears to not honor CSS
- This topic has 9 replies, 2 voices, and was last updated Aug 25, 2009
18:49:25 by dvanwest.
-
AuthorPosts
-
August 24, 2009 at 19:39#26251
We’re running PD4ML version 3.5.1b8.
We have two servlets; one that generates an HTML version of a document, and a second that generates a PDF version of the document, via PD4ML. The second servlet uses the output of the first as its source.
The HTML version of the document honors the referenced CSS, but the PDF version does not. If we remove the CSS references from the document, the HTML version looks identical to the PDF version… which leads me to believe the PDF renderer is not processing the CSS. From the logs it appears that the CSS is being loaded (see below), but we don’t see any evidence in the PDF display.
2009-08-24 13:33:45,919 INFO [STDOUT] version: PD4ML 351b8
2009-08-24 13:33:45,948 INFO [STDOUT] loading CSS file file:/local/ilms-apps/ilms-webres-common/css/ilms_jboss.css
2009-08-24 13:33:45,948 INFO [STDOUT] loading CSS file file:/local/ilms-apps/ilms-webres-common/css/ilms_base.css
2009-08-24 13:33:45,948 INFO [STDOUT] loading CSS file file:/local/ilms-apps/cps-portlet/css/portlet_cps.css
2009-08-24 13:33:45,948 INFO [STDOUT] loading CSS file file:/local/ilms-apps/ilms-webres-common/css/ilms_print.css
2009-08-24 13:33:46,165 INFO [STDOUT] done in 246ms.
Does anyone have any suggestions on how to debug this?
thanks.
August 24, 2009 at 19:57#27480Additional information…
We’ve also tried to load the CSS via the addStyle() methods (both by passing a URL object and by passing the CSS source as a String). Neither of these attempts made any difference to the rendered PDF.
August 25, 2009 at 14:57#27481More information:
-
We’ve removed all CSS from the source document and then tried the following:
Added simple in-line CSS to document. This was rendered correctly by the PDF.
Removed in-line CSS and placed same CSS in an external CSS file. This was correctly rendered when viewing the HTML, but not by the PDF.
Tried adding the simple CSS to PDF via the addStyle() method. Had no effect on PDF.
August 25, 2009 at 16:06#27482Still more information and a question or two…
The server on which this application is running only serves web content via HTTPS. The CSS is also servered via HTTPS, however it does not require authentication. It appears this a problem for PD4ML. If we move the external CSS to another server, which is accessible via HTTP, then the PDF correctly displays.
If PD4ML cannot deal with HTTPS, then we could work around the issue by reading the CSS content and including it via the addStyle() method, however that doesn’t seem to work. Shouldn’t the following apply the indicated style?
pd4ml.addStyle("p { color:red; }", true);
For some reason it does not. Any suggestions?
thanks.
August 25, 2009 at 17:16#27483Oficially PD4ML does not support HTTPS, however on practice it tries to load HTTPS resources with Java’s standard SSL classes.
WebSphere and Weblogic, for example, and may be some others implement their own SSL libraries, not derived from Java’s standard one. As a result it causes ClassCastException. As I see, it is not your case, but there may be other SSL protocol related issues, specific for your environment.
The best workaround for the HTTPS issue is not to use HTTPS for CSS or image references. It is expensive from the performance perspective and causes undesired network transactions. A better approach is to reference the resources with relative links.
If your source HTML documents are read-only and you are not allowed to change HTTPS URLs there, there is also a solution with custom resource loaders. You may implement your own one and to use any SSL library you like:
pd4ml-html-css-pdf-tips-tricks-f7/a-definition-of-custom-resource-loaders-t40.html
Regarding pd4ml.addStyle(“p { color:red; }”, true); – it always worked. We’ll check it once more – probably there are some newly introduced “code optimization issues” in the recent builds.
August 25, 2009 at 17:39#27484Thank you for the update.
We typically do reference the CSS external files via relative URLs. It’s curious, because the images are also loaded via unauthenticated SSL, but they always seem to render in the PDF. There also seems to be some sort of caching at play, which is very frustrating. I’ve disabled the PD4ML cache with:
HashMap map = new HashMap();<br /> map.put("pd4ml.cache.enable","false");<br /> pd4ml.setDynamicParams(map);
I’m testing with both IE v7 an FF 3.5.2.
I’ll try the custom resource loader.
August 25, 2009 at 17:50#27485FYI: addStyle() works only with PD4ML Pro binaries.
August 25, 2009 at 18:23#27486Success!!
Using the custom resource provider worked. The resource string that is passed into the class is formatted as “file:/local/somedir/test.css”, which might work on a Windows box, but doesn’t appear to work on our Unix box. We had to expand to a full URL and then it reads the CSS successfully.
May I suggest that the javadocs include something that indicates which methods are active for the standard versus professional versions.
Thanks for the help.
August 25, 2009 at 18:36#27487@dvanwest wrote:
May I suggest that the javadocs include something that indicates which methods are active for the standard versus professional versions.
PD4ML javadoc includes the info in method description details. Probably a separate document (a kind of PD4ML API method chart) with explicit Pro or Std marks is not a bad idea. I added the request to our TODO list.
August 25, 2009 at 18:49#27488Yes, you’re correct, the information is in the javadocs… it just failed to register with me.
thanks again.
-
AuthorPosts
The forum ‘HTML/CSS rendering issues’ is closed to new topics and replies.