java - FlyingSaucer setNamespaceAware to false -
compiling pdfrender class transforms html pdf got "premature end of file":
import com.lowagie.text.documentexception; import org.xhtmlrenderer.pdf.*; import org.xhtmlrenderer.resource.*; import org.w3c.dom.document; import org.xml.sax.inputsource; import java.io.*; public class pdfrender { public static void main(string[] args) throws ioexception, documentexception { createpdf("/home/user/test.pdf", renderer.class.getresource("/resource/print/test.html").getpath()); } public static void createpdf(string url, string pdf) throws ioexception, documentexception { outputstream os = null; try { os = new fileoutputstream(pdf); itextrenderer renderer = new itextrenderer(); resourceloaderuseragent callback = new resourceloaderuseragent(renderer.getoutputdevice()); callback.setsharedcontext(renderer.getsharedcontext()); renderer.getsharedcontext().setuseragentcallback(callback); document doc = xmlresource.load(new inputsource(url)).getdocument(); renderer.setdocument(doc, url); renderer.layout(); renderer.createpdf(os); os.close(); os = null; } catch(exception e) {} } private static class resourceloaderuseragent extends itextuseragent { public resourceloaderuseragent(itextoutputdevice outputdevice) { super(outputdevice); } protected inputstream resolveandopenstream(string uri) { inputstream = super.resolveandopenstream(uri); return is; } } }
i use setnamespaceaware false snippet, code doesn't use documentbuilderfactory
documentbuilderfactory documentbuilderfactory = documentbuilderfactory.newinstance(); documentbuilderfactory.setnamespaceaware(false);
how can this?
Comments
Post a Comment