Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Export to pdf - error on html stylesheet

    Good Morning,

    We are currently using the 5.0 Pro Edition version of SmartGWT.
    Our goal is to be able to export to pdf any html (from any webpage) and we do not have any control on the html, if it is correct or not, it might have relative paths etc.

    We are using the ability to export canvases to PDF. We have an HTMLPane in which we set the contents to be the page source of a web page (for example: http://nymag.com/news/features/hillary-clinton-2013-9/).
    When we try to export to pdf we get an error (below we have printed the error). If we remove from the html that we want to export all stylesheet urls (ex: <link type="text/css" rel="stylesheet" href="http://cache.nymag.com/css/screen/main.css" media="all" />) the export will work, but obviously it will not look perfectly because we have removed the styling.
    We wanted to ask you:
    - Is there an option to skip on errors, if any, and export to pdf as much as it can render
    - Is there an option to add the ability to interpret css urls

    Thank you very much.


    === 2017-02-27 16:55:38,061 [c-10] INFO PdfExport - CharSet used: UTF-8
    === 2017-02-27 16:55:38,769 [c-10] DEBUG RPCDMI - Invocation threw exception
    java.lang.StringIndexOutOfBoundsException: String index out of range: 0
    at java.lang.String.charAt(String.java:658)
    at org.xhtmlrenderer.css.parser.CSSParser.isRelativeURI(CSSParser.java:1946)
    at org.xhtmlrenderer.css.parser.CSSParser.getTokenValue(CSSParser.java:1918)
    at org.xhtmlrenderer.css.parser.CSSParser.getTokenValue(CSSParser.java:1883)
    at org.xhtmlrenderer.css.parser.CSSParser.term(CSSParser.java:1560)
    at org.xhtmlrenderer.css.parser.CSSParser.expr(CSSParser.java:1345)
    at org.xhtmlrenderer.css.parser.CSSParser.declaration(CSSParser.java:1282)
    at org.xhtmlrenderer.css.parser.CSSParser.declaration_list(CSSParser.java:746)
    at org.xhtmlrenderer.css.parser.CSSParser.ruleset(CSSParser.java:775)
    at org.xhtmlrenderer.css.parser.CSSParser.stylesheet(CSSParser.java:239)
    at org.xhtmlrenderer.css.parser.CSSParser.parseStylesheet(CSSParser.java:89)
    at org.xhtmlrenderer.context.StylesheetFactoryImpl.parse(StylesheetFactoryImpl.java:78)
    at org.xhtmlrenderer.context.StylesheetFactoryImpl.parse(StylesheetFactoryImpl.java:95)
    at org.xhtmlrenderer.context.StylesheetFactoryImpl.getStylesheet(StylesheetFactoryImpl.java:174)
    at org.xhtmlrenderer.context.StyleReference.readAndParseAll(StyleReference.java:123)
    at org.xhtmlrenderer.context.StyleReference.readAndParseAll(StyleReference.java:127)
    at org.xhtmlrenderer.context.StyleReference.setDocumentContext(StyleReference.java:107)
    at org.xhtmlrenderer.pdf.ITextRenderer.setDocument(ITextRenderer.java:175)
    at org.xhtmlrenderer.pdf.ITextRenderer.setDocument(ITextRenderer.java:142)
    at com.isomorphic.contentexport.PdfExport.getPdfRenderer(PdfExport.java:339)
    at com.isomorphic.contentexport.PdfExport.getPdfObject(PdfExport.java:76)
    at com.isomorphic.rpc.BuiltinRPC.getPdfObject(BuiltinRPC.java:1003)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.isomorphic.base.Reflection.adaptArgsAndInvoke(Reflection.java:975)
    at com.isomorphic.base.Reflection.adaptArgsAndInvoke(Reflection.java:805)
    at com.isomorphic.rpc.RPCDMI.execute(RPCDMI.java:301)
    at com.isomorphic.rpc.RPCDMI.execute(RPCDMI.java:66)
    at com.isomorphic.rpc.RPCRequest.execute(RPCRequest.java:231)
    at com.isomorphic.servlet.IDACall.handleRPCRequest(IDACall.java:328)
    at com.isomorphic.servlet.IDACall.processRPCTransaction(IDACall.java:182)
    at com.isomorphic.servlet.IDACall.processRequest(IDACall.java:152)
    at com.isomorphic.servlet.IDACall._processRequest(IDACall.java:117)
    at com.isomorphic.servlet.IDACall.doPost(IDACall.java:76)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
    at com.isomorphic.servlet.BaseServlet.service(BaseServlet.java:156)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1074)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:74

    #2
    It looks like this is a known issue in one of the libraries that our PDF export process relies on (see this issue report).

    The underlying problem is bad CSS (a meaningless blank url() declaration). We would speculate that if you are trying to export arbitrary web pages to PDF, you will probably run into a lot of small issues like this, where web browsers will handle lots of kinds of bad usage that this server-side export library cannot handle.

    One approach would be to preprocess the CSS and other content in some way, eg by downloading it all first and processing it for errors. This is obviously a fairly large undertaking.

    Another approach would be to find some other exporting library that does a better job of exports with arbitrary content. We chose the libraries we did for exporting controlled content (printable HTML output we designed ourselves), and your use case is quite different, so there may be better options.

    Comment


      #3
      Thank you very much for your answer.

      Comment


        #4
        Hi,

        I never did such a project, but I'm reading the Prince XML changelog every year. It seems to me that you can build very beautiful PDFs with it and that it also is good at parsing bad HTML etc.
        So I'd definitely give it a try if you need to use a different library.

        Best regards
        Blama

        Comment


          #5
          Hello Blama,
          We will have a look. Thank you for the tip.
          Kind regards,
          Andreea

          Comment

          Working...
          X