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)
- This topic has 3 replies, 2 voices, and was last updated Nov 15, 2013
15:36:39 by PD4ML.
-
AuthorPosts
-
November 15, 2013 at 13:21#26889
Hey,
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 : http://pd4ml.com/cookbook/pd4ml_proprietary_css_features.htm
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 parentStyle sheet that i am using in html :
You can also try W3Schools example and it’s not working.
http://www.w3schools.com/cssref/tryit.asp?filename=trycss3_nth-childMy Sample Java Codes to generate PDF from HTML.
<%@ page import="java.io.*,java.net.*,java.util.*,org.zefer.pd4ml.*"%>
<% String sBodyHTML = "AAA"; if (null != request.getParameter("html")) sBodyHTML = request.getParameter("html"); PD4ML pd4ml = new PD4ML(); Mapmap = new HashMap ();
map.put(“pd4ml.cache.enable”, “false”);
pd4ml.setDynamicParams(map);
pd4ml.setPageSize(PD4ML.LETTER);
pd4ml.setPageInsets(new java.awt.Insets(18, 18, 18, 18));
pd4ml.adjustHtmlWidth();ByteArrayOutputStream baos = new ByteArrayOutputStream();
pd4ml.render(new StringReader(“PD4ML using pt ” + sBodyHTML + ““), baos);
byte[] result = baos.toByteArray();
response.setContentType(“application/pdf”);
response.setHeader(“Content-disposition”, “inline; filename=test” + Math.random() + “.pdf”);
if (!request.isSecure()) {
response.setHeader(“Pragma”, “no-cache”);
response.setHeader(“Expires”, “-10000”);
}
response.setContentLength(result.length);
ServletOutputStream sos = response.getOutputStream();
sos.write(result);
%>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(CssParser.java:56)
at org.zefer.html.doc.css.CssRuntime.parseStyle(CssRuntime.java:159)
at org.zefer.html.doc.PD4MLHtmlParser.buildDocument(PD4MLHtmlParser.java:368)
at org.zefer.pd4ml.PD4ML.render(PD4ML.java:1649)
at org.zefer.pd4ml.PD4ML.render(PD4ML.java:383)
at org.apache.jsp.egn.public_.tests.html2pdf_jsp._jspService(html2pdf_jsp.java:86)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
… 28 morePlease let me know if you are looking for more info.
Thanks.
November 15, 2013 at 14:50#29434W3Schools 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.
November 15, 2013 at 15:31#29435Hey,
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 supportyou are supporting it from version “PD4ML Pro 3.6.1b2”.
Thanks
November 15, 2013 at 15:36#29436I 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.
-
AuthorPosts
The forum ‘HTML/CSS rendering issues’ is closed to new topics and replies.