Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
  • #26424

    Hi all,

    Because my JSP pages are accessed through Struts framework using actions mapped by URLs like “” and this actions are also hidden in the URLs, i can’t actually use the URL to render with pd4ml library (i’m using the demo Pro version to be able to see some results for intregrating the library withing one of our applications).
    So, as a result, from the client side (browser), i’m getting the HTML String of the document of the current page using javascript, and send it to server side of the application as a request parameter.

    A. So, in the HTML string, i have a CSS file reference, which is used in my pages to apply styles. The reference in the HTML string is like the following (which is ofcorce inside the tag):

    On the server side, i’m reading the corresponding request parameter and i get the HTML string. Here i’m calling:

    StringReader htmlReader = new StringReader(htmlString);
    FileOutputStream fos = new FileOutputStream(outTempFile);
    pd4ml.render(htmlReader, fos);

    Problems: as it is now, the CSS is not applyed at all to the resulted PDF document. The pdf document looks likes there is no stylesheet applyed at all. Can someone please tell me if there is any possibility to reference my CSS file in myHTML string in such a maner that the “render” method to be ablee to actually “see it”?

    B. Next, as a workaround, i’ve made a try to apply the stylesheet to the pd4ml object. So, i’m loading the entire CSS file in a String variable and just set it against pd4ml object:

    String cssData = readFileAsString(stylePath);

    Again, there are some problems: the styles are all applyed, except those which set a backround image, like:

    #header {
    background: url(“images/topnav.gif”) center bottom no-repeat;
    height: 102px;
    width: 100%;
    position: absolute;
    z-index: 10;

    None of my styles of this kind are rendered correct. In the rendered pdf docuement, there is no image where it shuld be added as a background CSS style.

    Can someone please give me a shoot if has any idea for A. or B. problems?
    Thank you in advance for the answers.

    PS: if any more details are required, please let me know.


    A good starting point to analyze the problem reasons is to switch debug on:


    I suspect it will output to server’s log traces of attempts to load


    which is obviously incorrect. In order to let PD4ML interpret /broker-module/BL.css as a web path you would need to pass either the servlet context or HTTP request object to PD4ML. It could be done with the following API calls.

    [language=java:1w9ymuy5]useServletContext(ServletContext ctx)
    useHttpRequest(HttpServletRequest httpRequest, HttpServletResponse httpResponse)[/language:1w9ymuy5]


    thanks for the response. i’ve resolved that problem.

    no, i want to add a header and footer to the rendered pdf doc.
    for this i’ dooing the following:

    private PD4PageMark getPageHeader(String htmlString)
    String headerBody = “

    PD4PageMark header = new PD4PageMark();
    header.setAreaHeight( -1 ); // autocompute
    header.setHtmlTemplate( headerBody );
    return header;

    In my html document, in the CSS file i have a stule class which difines the “header” with a background image.
    How can i use the same CSS file when adding a header to the pd4ml object?


    When you define header via API, it does not inherit styles from the main document. So you need to explicitly refer the style from the HTML header code:
    [language=java:14ygxtuv]String headerBody = “” +
    ” +

    header.setHtmlTemplate( headerBody );[/language:14ygxtuv]


    i’ve made the change as you’ve suggested.

    the header works fine now and it is rendered the same as the HTML page header.
    the remaining problem is with the footer:
    like header, the footer is using a style that set an image for the background and width to 100%, but in the footer case, the image is rendered 1. up-side-down and 2. it is too big (left and right margins of the image are somewhere over the margins of the rendered pdf document); this 2nd. issue is also applyed for the case of the header, even if it is not so visible.

    for the html document i’m using
    to be able to fit the html text into the pdf document and this is working.

    how can i do the same for footer?
    private PD4PageMark getPageFooter(String cssTag)
    String footerBody = “” + cssTag + “” +

    PD4PageMark footer = new PD4PageMark();
    footer.setAreaHeight( -1 ); // autocompute
    footer.setHtmlTemplate( footerBody );
    return footer;

    thank you for your help.

    one more problem: after i’ve set the page header and footer with pd4ml.setPageHeader and pd4ml.setPageFooter, the header and footer appears only on the first page of the rendered PDF. I don’t understand why header and footer aren’t rendered for all of the pages! How can i make it work?


    hmm… “up-side-down footer” is an old issue resolved in the recent versions. could you please send a PDF sample to analyze to support pd4ml com


    i’ve just sent to support a sample of PDF which has all the described problems in it.


    For the time being it is not quite clear why it conflicts with background images in footer. Also an absolute positioning in footer was not foreseen when we implemented the feature.

    I would recommend you to use inline footer definitions instead of your current approach.

    You may place

    right after opening tag or before tag of your document. Also do not apply absolute poitioning to the element.

    More infor about footers in PD4ML:


    thanks for your replay.
    we bought the pd4ml pro library, but our problems are still there; even more, now with the licensed pd4ml.jar library the footer image isn’t rendered at all; footer is empty.

    more, i think there is a missunderstanding:
    i’m building the PDF document header and footer with a method like the following:

    private PD4PageMark getPageFooter(String cssTag)
    String footerBody = “” + cssTag + “” +

    PD4PageMark footer = new PD4PageMark();
    footer.setAreaHeight( -1 ); // autocompute
    footer.setHtmlTemplate( footerBody );
    return footer;


    So, i suppose i can’t use pd4ml tags when bulding header and footer like this. Isn’t it?

    So, i’ll get back and repost all of our problems that we are facing right now:
    1. header is rendered over the PDF document margins! (the header is built in exactly the same way as explained for the footer above)
    2. with the licensed library, the footer isn’t rendered at all!!! (footer is built as described above)
    3. header (and i suppose footer too) is rendered only for the first page of the resulted PDF document and not for all the other pages!!! I need the same header and footer in all the pages of the PDF document

    Sorry for pressing, but this problems are becoming urgent.
    Your help is very much appreciated.



    Have you seen a workarounf suggestion in my previous reply?

    You define the footer correctly, but weither it is rendered correctly depends on cssTag value in the code. If there are absolute positioning and adding of as table cell backgrounds – it fails with the current version

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

The forum ‘HTML/CSS rendering issues’ is closed to new topics and replies.