HTML to PDF / DOCX / RTF Java converter library Forums PD4ML v3 Archived Forums (Read Only) HTML/CSS rendering issues CSS Selector parsing Error (div:nth-child/pseudo selector)

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


    I am using PD4ML (version: PD4ML 380fx8b1 Pro DMS) for my web app and i tried to use div:nth-child(odd|even) pseudo-css selector but somehow at time of pdfml.render() is throwing nullpointer exception from ss_css2.jar classes. Please check below mentioned exception and details. Please help.

    As you mentioned like below on :

    E:first-child The :first-child pseudo-class Matches element E when E is the first child of its parent
    E:nth-child(even|odd) Structural pseudo-class selector Matches E element, the even or odd child of its parent

    Style sheet that i am using in html :

    You can also try W3Schools example and it’s not working.

    My Sample Java Codes to generate PDF from HTML.

    <%@ page import="*,*,java.util.*,org.zefer.pd4ml.*"%>
    <% String sBodyHTML = "AAA"; if (null != request.getParameter("html")) sBodyHTML = request.getParameter("html"); PD4ML pd4ml = new PD4ML(); Map map = new HashMap();
    map.put(“pd4ml.cache.enable”, “false”);
    pd4ml.setPageInsets(new java.awt.Insets(18, 18, 18, 18));

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    pd4ml.render(new StringReader(“PD4ML using pt

    ” + sBodyHTML + ““), baos);
    byte[] result = baos.toByteArray();
    response.setHeader(“Content-disposition”, “inline; filename=test” + Math.random() + “.pdf”);
    if (!request.isSecure()) {
    response.setHeader(“Pragma”, “no-cache”);
    response.setHeader(“Expires”, “-10000”);
    ServletOutputStream sos = response.getOutputStream();

    Exception :

    Caused by: java.lang.NullPointerException
    at org.w3c.css.sac.CSSParseException.(Unknown Source)
    at com.steadystate.css.parser.SACParser.pseudo(Unknown Source)
    at com.steadystate.css.parser.SACParser.simpleSelector(Unknown Source)
    at com.steadystate.css.parser.SACParser.selector(Unknown Source)
    at com.steadystate.css.parser.SACParser.selectorList(Unknown Source)
    at com.steadystate.css.parser.SACParser.styleRule(Unknown Source)
    at com.steadystate.css.parser.SACParser.styleSheetRuleList(Unknown Source)
    at com.steadystate.css.parser.SACParser.styleSheet(Unknown Source)
    at com.steadystate.css.parser.SACParser.parseStyleSheet(Unknown Source)
    at org.zefer.html.doc.css.CssParser.parseStyleSheet(
    at org.zefer.html.doc.css.CssRuntime.parseStyle(
    at org.zefer.html.doc.PD4MLHtmlParser.buildDocument(
    at org.zefer.pd4ml.PD4ML.render(
    at org.zefer.pd4ml.PD4ML.render(
    at org.apache.jsp.egn.public_.tests.html2pdf_jsp._jspService(
    at org.apache.jasper.runtime.HttpJspBase.service(
    at javax.servlet.http.HttpServlet.service(
    at org.apache.jasper.servlet.JspServletWrapper.service(
    … 28 more

    Please let me know if you are looking for more info.



    W3Schools example defines p:nth-child(2), which is not supported by the current versions of PD4ML. If you change it, for an instance, to p:nth-child(odd) – it renders correctly.

    Also I added your style to my test document and it caused no CSS exception.

    I used PD4ML v385fx2. So I would recommend to give a try to the newest version (and accompanying ss_css2.jar) – there are fully functional trials available for download.



    Thanks for the quick reply. Ok I got you but can you please test it once with version “PD4ML 380fx8b1 Pro DMS” because as per your docs

    New in PD4ML Pro 3.6.1b2

    RTF file format output support
    nth-child(even|odd) CSS selector support

    you are supporting it from version “PD4ML Pro 3.6.1b2”.



    I suspect you use ss_css2.jar from an old version. Replace it with a one taken from 380fx8b1 or, which is better, from (trial) 385fx2. It is an open source lib, we patch it from time to time.

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

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