In this post, we will provide a basic example that explains how to convert a HTML document to a PDF file using the Java iText library. Converting a HTM file to PDF document would be a simple task if you have all the required libraries with you. In addition to using iText, we will use some more APIs to achieve this conversion. I'm fascinated towards an API, popularly known as Flying Saucer. I will be using R8 version of this API and you can download the additional JAR files from the following location. You will be able to appreciate the conversion process as this library makes the transformation of HTML to PDF a fairly quick task with very minimal code. It internally uses iText and so I believe you can still retain your iText functionality and build the conversion on top of this. We will see some examples for this as we move on.
To begin converting HTML to PDF using iText, make sure that you have the following JAR files in your classpath after you have downloaded the XML/XHTML and CSS renderer. The files I'm after are listed below (along with iText);
1) core-renderer.jar
2) core-renderer-minimal.jar
3) xml-apis-xerces-2.9.1.jar
We can get started now. The step by step guide to convert HTML to PDF is provided below;
Step-1: Prepare a HTML Hello World file for testing. (You can very well use your HTML code instead of this. More advanced examples later). If you are looking for something quick, you can use the HTML provided below;
Step-2: We begin by defining an input HTML file and convert it into an URL. We also define an output stream where the PDF document would be produced. Refer to the code below that explains how to do this in Java;
Step-3:We now use the iTextRenderer class defined in org.xhtmlrenderer.pdf.ITextRenderer and use the "createPDF" method of this class to generate the PDF. Now, the iTextRenderer class needs to know the location to pick up the incoming HTM file. This is provided by using the "setDocument" method of the class. Just four lines of code and you get the new PDF file.
The complete code to produce a PDF from a HTML document by converting the HTML to PDF using Java iText is provided below;
To begin converting HTML to PDF using iText, make sure that you have the following JAR files in your classpath after you have downloaded the XML/XHTML and CSS renderer. The files I'm after are listed below (along with iText);
1) core-renderer.jar
2) core-renderer-minimal.jar
3) xml-apis-xerces-2.9.1.jar
We can get started now. The step by step guide to convert HTML to PDF is provided below;
Step-1: Prepare a HTML Hello World file for testing. (You can very well use your HTML code instead of this. More advanced examples later). If you are looking for something quick, you can use the HTML provided below;
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Example To Convert HTML to PDF in Java iText</title>
<style type="text/css"> b { color: blue; } </style>
</head>
<body>
<b>Hello World</b>
We have successfully transformed a HTML File to PDF document in Java!!
<br/>
<b>This solution and example works </b>
</body>
</html>
Step-2: We begin by defining an input HTML file and convert it into an URL. We also define an output stream where the PDF document would be produced. Refer to the code below that explains how to do this in Java;
String File_To_Convert = "test.htm";
String url = new File(File_To_Convert).toURI().toURL().toString();
System.out.println(""+url);
String HTML_TO_PDF = "ConvertedFile.pdf";
OutputStream os = new FileOutputStream(HTML_TO_PDF);
Step-3:We now use the iTextRenderer class defined in org.xhtmlrenderer.pdf.ITextRenderer and use the "createPDF" method of this class to generate the PDF. Now, the iTextRenderer class needs to know the location to pick up the incoming HTM file. This is provided by using the "setDocument" method of the class. Just four lines of code and you get the new PDF file.
ITextRenderer renderer = new ITextRenderer();
renderer.setDocument(url);
renderer.layout();
renderer.createPDF(os);
os.close();
Step-4: While creating the PDF we can get either IOException (if input file could not be located) or DocumentException and these needs to be caught.The complete code to produce a PDF from a HTML document by converting the HTML to PDF using Java iText is provided below;
import java.io.*;
import com.lowagie.text.DocumentException;
import org.xhtmlrenderer.pdf.ITextRenderer;
public class FirstDoc {
public static void main(String[] args)
throws IOException, DocumentException {
String File_To_Convert = "test.htm";
String url = new File(File_To_Convert).toURI().toURL().toString();
System.out.println(""+url);
String HTML_TO_PDF = "ConvertedFile.pdf";
OutputStream os = new FileOutputStream(HTML_TO_PDF);
ITextRenderer renderer = new ITextRenderer();
renderer.setDocument(url);
renderer.layout();
renderer.createPDF(os);
os.close();
}
}
This basic example tutorial produces a PDF as shown in the image below;HTML to PDF in Java iText |
Hello, I tried your example and got the following exception when converting my html document to pdf .
ReplyDeleteERROR: 'The element type "br" must be terminated by the matching end-tag "
".'
Exception in thread "main" org.xhtmlrenderer.util.XRRuntimeException: Can't load
the XML resource (using TRaX transformer). org.xml.sax.SAXParseException: The e
lement type "br" must be terminated by the matching end-tag "".
at org.xhtmlrenderer.resource.XMLResource$XMLResourceBuilder.createXMLRe
source(XMLResource.java:191)
at org.xhtmlrenderer.resource.XMLResource.load(XMLResource.java:71)
at org.xhtmlrenderer.swing.NaiveUserAgent.getXMLResource(NaiveUserAgent.
java:211)
at org.xhtmlrenderer.pdf.ITextRenderer.loadDocument(ITextRenderer.java:1
34)
at org.xhtmlrenderer.pdf.ITextRenderer.setDocument(ITextRenderer.java:13
8)
at FirstDoc.main(FirstDoc.java:16)
Caused by: javax.xml.transform.TransformerException: org.xml.sax.SAXParseExcepti
on: The element type "br" must be terminated by the matching end-tag "".
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transfor
m(TransformerImpl.java:719)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transfor
m(TransformerImpl.java:313)
at org.xhtmlrenderer.resource.XMLResource$XMLResourceBuilder.createXMLRe
source(XMLResource.java:189)
... 5 more
Caused by: org.xml.sax.SAXParseException: The element type "br" must be terminat
ed by the matching end-tag "".
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Ab
stractSAXParser.java:1231)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transfor
mIdentity(TransformerImpl.java:636)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transfor
m(TransformerImpl.java:707)
... 7 more
can you help?
Hi,
ReplyDeleteYou are getting this exception because you are using a <br> tag in your HTML that is not closed. Use </br> or <br/> and try it again. It should work.
Does anyone know if you can have the HTML input be a page of the format jobAppView.do?id=42 ? I have an online job application form that I need to capture to a pdf file....
ReplyDeleteThanks,
-Terri
@Terri
ReplyDeleteWhen you try this example, can you tell me the exception you are getting on the screen?
which jar file used for ITextRenderer renderer = new ;
ReplyDeleterenderer.setDocument(url);
renderer.layout();
renderer.createPDF(os);
1) core-renderer.jar
ReplyDelete2) core-renderer-minimal.jar
3) xml-apis-xerces-2.9.1.jar
are the files..
where i have to put above files
DeleteERRO: 'White spaces are required between publicId and systemId.'
ReplyDeleteplumbing.exception WARNING:: Unhandled exception. Can't load the XML resource (using TRaX transformer). org.xml.sax.SAXParseException: White spaces are required between publicId and systemId.
Exception in thread "main" org.xhtmlrenderer.util.XRRuntimeException: Can't load the XML resource (using TRaX transformer). org.xml.sax.SAXParseException: White spaces are required between publicId and systemId.
at org.xhtmlrenderer.resource.XMLResource$XMLResourceBuilder.createXMLResource(XMLResource.java:191)
at org.xhtmlrenderer.resource.XMLResource.load(XMLResource.java:71)
at org.xhtmlrenderer.swing.NaiveUserAgent.getXMLResource(NaiveUserAgent.java:118)
at org.xhtmlrenderer.pdf.ITextRenderer.loadDocument(ITextRenderer.java:98)
at org.xhtmlrenderer.pdf.ITextRenderer.setDocument(ITextRenderer.java:102)
at flyingsaucerpdf.TesteHTML.main(TesteHTML.java:21)
Caused by: javax.xml.transform.TransformerException: org.xml.sax.SAXParseException: White spaces are required between publicId and systemId.
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown Source)
at org.xhtmlrenderer.resource.XMLResource$XMLResourceBuilder.createXMLResource(XMLResource.java:189)
... 5 more
Caused by: org.xml.sax.SAXParseException: White spaces are required between publicId and systemId.
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(Unknown Source)
... 8 more
Can you help?
@Luiz,
ReplyDeleteCan you post your HTML / Java code? Also,the version of Jar files you used?
Bom dia . @YellowRose
ReplyDeletedescobri a causo do problema.
São os acentos em algumas palavras.
Você tem alguma sugestão para corrigir isto?
meu email é luiz641@hotmail.com
qualquer coisa me manda email direto.
@Luiz, can you post one simple example HTML so that I can try and fix it for you?
ReplyDeleteHello,
ReplyDeleteI tried your example and it works great on a windows pc.
Now I want to run it on a linux 64-bit machine with java 64 and it crashes with the following exception.
java.lang.NoSuchMethodError: com.lowagie.text.pdf.BaseFont.getCharBBox(C)
Do you have an idea how to solve this problem?
Thanks in advance.
LStrike
@LStrike,
ReplyDeleteCan you post your Java code and the HTML you used for conversion? I will have a look.
hello,
ReplyDeleteIf i declare the style in the starting of html.it is not getting reflected in my PDF.what should I need to do inorder to generate the PDF with all stylings
Apurva
@Apurva, please post your HTML code.
ReplyDeleteHi I am getting following error. Could you put me in right direction what I am I doing wrong?
ReplyDeleteplumbing.load.xml-entities WARNING:: Could not open XML catalog from URI 'resources/schema/xhtml/catalog-xhtml-1.0.xml'
plumbing.load.xml-entities WARNING:: Could not open XML catalog from URI 'resources/schema/xhtml/catalog-xhtml-1.1.xml'
plumbing.load.xml-entities WARNING:: Could not open XML catalog from URI 'resources/schema/docbook/catalog-docbook.xml'
FATAL ERROR: 'java.io.IOException: Stream closed'
:Stream closed
plumbing.load INFO:: Loaded document in ~16ms
plumbing.exception WARNING:: Could not parse default stylesheet
java.lang.NullPointerException
at org.xhtmlrenderer.simple.extend.XhtmlCssOnlyNamespaceHandler.findFirstChild(XhtmlCssOnlyNamespaceHandler.java:241)
at org.xhtmlrenderer.simple.extend.XhtmlCssOnlyNamespaceHandler.getStylesheets(XhtmlCssOnlyNamespaceHandler.java:331)
at org.xhtmlrenderer.context.StyleReference.getStylesheets(StyleReference.java:247)
at org.xhtmlrenderer.context.StyleReference.setDocumentContext(StyleReference.java:104)
at org.xhtmlrenderer.pdf.ITextRenderer.setDocument(ITextRenderer.java:130)
at org.xhtmlrenderer.pdf.ITextRenderer.setDocument(ITextRenderer.java:106)
at org.xhtmlrenderer.pdf.ITextRenderer.setDocument(ITextRenderer.java:102)
at JavaAgent.NotesMain(Unknown Source)
at lotus.domino.AgentBase.runNotes(Unknown Source)
at lotus.domino.NotesThread.run(Unknown Source)
@Vinay,can you post your HTML code?
ReplyDeletehi, i had tried ur example but it is showing the following exception, can u help me out..
ReplyDeleteException in thread "main" java.lang.NoSuchMethodError: com.lowagie.text.Rectangle.getHeight()F
at org.xhtmlrenderer.pdf.ITextRenderer.writePDF(ITextRenderer.java:339)
at org.xhtmlrenderer.pdf.ITextRenderer.createPDF(ITextRenderer.java:315)
at org.xhtmlrenderer.pdf.ITextRenderer.createPDF(ITextRenderer.java:246)
at FirstDoc.main(FirstDoc.java:18)
hi, i had tried ur example and it worked, but for strict HTML(i mean XHTML). i want to develop an application(using java) which converts the webpage to an pdf document(like how www.web2pdfconverter.com does), i tried ur way but the html code of the web pages is not strict HTML, can u help me out..? Thanks in advance.
ReplyDelete@Ajay,
ReplyDeleteDid you use the same HTML code that I have provided? What version of JAR files you used?
when i define styles in the starting of html, styles are not reflecting.. Am not able to post my html here. Its not allowed.
ReplyDeleteyou need to do some tweaks to support stylesheet..I'm working on this. Connect to this site and you will get an update shortly.
ReplyDelete@Ajay Maybe you can try to convert from HTML to XHTML using jTidy and then use iText with the XHTML generated.
ReplyDeletei m getting Exception Can't load the XML resource (using TRaX transformer). java.io.IOException: Stream closed
ReplyDeleteCan't load the XML resource (using TRaX transformer). java.io.IOException: Stream closed
ReplyDelete@Naval, post your java version, version of jar files and code. I will have a look.
ReplyDeletenow i have again try and using jdk 1.4 and i have download all the Jar file from your provided Location and getting the problem "Can't load the XML resource (using TRaX transformer). java.io.IOException: Stream closed"
ReplyDeleteDoes your HTML file reside in the same directory as your java code? Can you post the code please?
ReplyDeleteI have been looking into this and it looks like you must have a valid HTML.
ReplyDeleteusually there are rare cases where you have a 100% valid html..
so iText needs to be improved much more to really work in "real-life" production quality applications.
for eg. if you try to use http://www.chinadaily.com/
it will fail with bunch of exceptions similar to all of above exception.
here is the I text official demo page which also fails to convert!
http://demo.itextsupport.com/xmlworker/
ps: It says provide feed back, but didn't find actual link to provide one!
HI.. I am Manju Vani
ReplyDeleteI tried ur exmaple its giving the out put but it is giving the following error plz help me in resolving this error.
java.io.IOException: Stream closed
at java.io.BufferedInputStream.getInIfOpen(Unknown Source)
at java.io.BufferedInputStream.read1(Unknown Source)
at java.io.BufferedInputStream.read(Unknown Source)
at sun.nio.cs.StreamDecoder.readBytes(Unknown Source)
at sun.nio.cs.StreamDecoder.implRead(Unknown Source)
at sun.nio.cs.StreamDecoder.read(Unknown Source)
at java.io.InputStreamReader.read(Unknown Source)
at org.xhtmlrenderer.css.parser.Lexer.zzRefill(Lexer.java:1634)
at org.xhtmlrenderer.css.parser.Lexer.yylex(Lexer.java:1865)
at org.xhtmlrenderer.css.parser.CSSParser.next(CSSParser.java:1778)
at org.xhtmlrenderer.css.parser.CSSParser.la(CSSParser.java:1790)
at org.xhtmlrenderer.css.parser.CSSParser.stylesheet(CSSParser.java:157)
at org.xhtmlrenderer.css.parser.CSSParser.parseStylesheet(CSSParser.java:87)
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.setDocumentContext(StyleReference.java:107)
at org.xhtmlrenderer.pdf.ITextRenderer.setDocument(ITextRenderer.java:175)
at org.xhtmlrenderer.pdf.ITextRenderer.setDocument(ITextRenderer.java:142)
at org.xhtmlrenderer.pdf.ITextRenderer.setDocument(ITextRenderer.java:138)
Hello, I tried your example and got the following exception when converting my html document to pdf .
ReplyDeleteException in thread "main" java.lang.NoSuchMethodError: com.lowagie.text.pdf.BaseFont.getCharBBox(I)[I
at org.xhtmlrenderer.pdf.ITextFontResolver$FontDescription.setMetricDefaults(ITextFontResolver.java:696)
at org.xhtmlrenderer.pdf.ITextFontResolver$FontDescription.(ITextFontResolver.java:627)
at org.xhtmlrenderer.pdf.ITextFontResolver.addCourier(ITextFontResolver.java:427)
at org.xhtmlrenderer.pdf.ITextFontResolver.createInitialFontMap(ITextFontResolver.java:407)
at org.xhtmlrenderer.pdf.ITextFontResolver.(ITextFontResolver.java:52)
at org.xhtmlrenderer.pdf.ITextRenderer.(ITextRenderer.java:115)
at org.xhtmlrenderer.pdf.ITextRenderer.(ITextRenderer.java:102)
at FirstDoc.main(FirstDoc.java:14)
I am Using following Jars
1. core-renderer.jar
2. core-renderer-R8-final.jar
3. core-renderer-R8pre2-sources.jar
4. flyingsaucer-renderer.jar
5. itext-2.0.8.jar
6. xhtmlrenderer-core-renderer-minimal.jar
7. xml-apis-xerces_2_7_1.jar
I have tried this code and I am getting the following error:
ReplyDeletexception in thread "main" java.lang.NoClassDefFoundError: com/lowagie/text/pdf/PdfTemplate
at org.xhtmlrenderer.pdf.ITextRenderer.(ITextRenderer.java:108)
at org.xhtmlrenderer.pdf.ITextRenderer.(ITextRenderer.java:102)
at models.CreatePdf.main(CreatePdf.java:28)
Caused by: java.lang.ClassNotFoundException: com.lowagie.text.pdf.PdfTemplate
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 3 more
Java Result: 1
Any assistance would be appreciated.
Exception in thread "main" java.lang.NoSuchMethodError: com.lowagie.text.pdf.BaseFont.getCharBBox(I)[I
ReplyDeleteis due to improper iText jar version:
use iText-2.0.8.jar
Hi Amarendra I have used iText-2.0.8.jar but still getting same issue.Please guide..vdubey.p@gail.com
DeleteHello I am vivek yadav
ReplyDeleteI am working on grails and using rendering plugin for generate pdf. behind the sceen it also use itext to create pdf. I want to add my own font how is it possible.
You can email me if you have any solution regarding this.
my email id is :
vivek@jellyfishtechnologies.com
Hi Vivek ,
DeleteCan you please do let me know if you got any solution?
vdubey.p@gmail.com
Thanks,
Ved
The type com.lowagie.text.DocumentException cannot be resolved. It is indirectly referenced from required .class files
ReplyDeletehi..
ReplyDeletei'm tried this example in android but it will display error for "configure the build path"...so plz help me..
The type com.lowagie.text.DocumentException cannot be resolved. It is indirectly referenced from required .class files
I have a table on my page and sometimes, this table has just been cut in half by page transition. would like to avoid this?
ReplyDeleteHi! Thank you for a good article! I run your example, but I get an error ERROR: 'Stream closed'
ReplyDeleteException in thread "main" org.xhtmlrenderer.util.XRRuntimeException: Can't load the XML resource (using TRaX transformer). java.io.IOException: Stream closed
at org.xhtmlrenderer.resource.XMLResource$XMLResourceBuilder.createXMLResource(XMLResource.java:191)
at org.xhtmlrenderer.resource.XMLResource.load(XMLResource.java:71)
at org.xhtmlrenderer.swing.NaiveUserAgent.getXMLResource(NaiveUserAgent.java:212)
at org.xhtmlrenderer.pdf.ITextRenderer.loadDocument(ITextRenderer.java:137)
at org.xhtmlrenderer.pdf.ITextRenderer.setDocument(ITextRenderer.java:141)
at Converts.Html2Pdf.IText.HtmlToPdf.main(HtmlToPdf.java:14)
Caused by: javax.xml.transform.TransformerException: java.io.IOException: Stream closed
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown Source)
at org.xhtmlrenderer.resource.XMLResource$XMLResourceBuilder.createXMLResource(XMLResource.java:189)
... 5 more
Caused by: java.io.IOException: Stream closed
at java.io.BufferedInputStream.getInIfOpen(Unknown Source)
at java.io.BufferedInputStream.fill(Unknown Source)
at java.io.BufferedInputStream.read(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager$RewindableInputStream.read(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(Unknown Source)
... 8 more
Tell me please how to fix it? Thank you!
it would be a useful example if you actually provided the libraries (as a download). Without those, it is just guess work because there is so many versions of those libraries out there that I cannot find the correct one.
ReplyDeleteHi,
ReplyDeleteI am using these all jars and everything is fine and pdf generated successfully
but, when running same code on Windows10 then getting alignment issues (some contents comming in next page) which was fine when running in Windows7
1) core-renderer.jar
2) core-renderer-minimal.jar
3) xml-apis-xerces-2.9.1.jar
so, to execute on Windows10, I have to change new jar means latest jar for Win10 ?
please help me out.
Exception in thread "main" java.lang.NoSuchMethodError: com.lowagie.text.pdf.BaseFont.getCharBBox(C)[I
ReplyDeleteat org.xhtmlrenderer.pdf.ITextFontResolver$FontDescription.setMetricDefaults(ITextFontResolver.java:679)
at org.xhtmlrenderer.pdf.ITextFontResolver$FontDescription.(ITextFontResolver.java:610)
at org.xhtmlrenderer.pdf.ITextFontResolver.addCourier(ITextFontResolver.java:410)
at org.xhtmlrenderer.pdf.ITextFontResolver.createInitialFontMap(ITextFontResolver.java:390)
at org.xhtmlrenderer.pdf.ITextFontResolver.(ITextFontResolver.java:52)
at org.xhtmlrenderer.pdf.ITextRenderer.(ITextRenderer.java:83)
at org.xhtmlrenderer.pdf.ITextRenderer.(ITextRenderer.java:70)
at com.jcg.examples.ItextHtmlToPDFExample.main(ItextHtmlToPDFExample.java:31) Please help
Hi,
ReplyDeleteGetting below exception while executing the code in above mentioned format:
Exception in thread "main" java.lang.NoSuchMethodError: com.lowagie.text.pdf.BaseFont.getCharBBox(C)[I
at org.xhtmlrenderer.pdf.ITextFontResolver$FontDescription.setMetricDefaults(ITextFontResolver.java:679)
at org.xhtmlrenderer.pdf.ITextFontResolver$FontDescription.(ITextFontResolver.java:610)
at org.xhtmlrenderer.pdf.ITextFontResolver.addCourier(ITextFontResolver.java:410)
at org.xhtmlrenderer.pdf.ITextFontResolver.createInitialFontMap(ITextFontResolver.java:390)
at org.xhtmlrenderer.pdf.ITextFontResolver.(ITextFontResolver.java:52)
at org.xhtmlrenderer.pdf.ITextRenderer.(ITextRenderer.java:83)
at org.xhtmlrenderer.pdf.ITextRenderer.(ITextRenderer.java:70)
at OSM.Pdf.main(Pdf.java:78)
Exception in thread "main" java.lang.NoSuchMethodError: com.lowagie.text.pdf.BaseFont.getCharBBox(C)[I
ReplyDeleteat org.xhtmlrenderer.pdf.ITextFontResolver$FontDescription.setMetricDefaults(ITextFontResolver.java:679)
at org.xhtmlrenderer.pdf.ITextFontResolver$FontDescription.(ITextFontResolver.java:610)
at org.xhtmlrenderer.pdf.ITextFontResolver.addCourier(ITextFontResolver.java:410)
at org.xhtmlrenderer.pdf.ITextFontResolver.createInitialFontMap(ITextFontResolver.java:390)
at org.xhtmlrenderer.pdf.ITextFontResolver.(ITextFontResolver.java:52)
at org.xhtmlrenderer.pdf.ITextRenderer.(ITextRenderer.java:83)
at org.xhtmlrenderer.pdf.ITextRenderer.(ITextRenderer.java:70)
at OSM.Pdf.main(Pdf.java:78)
I am getting the below error:
ReplyDeleteorg.xhtmlrenderer.layout.SharedContext: method ()V not found
HI i executed your code but i see the below error
ReplyDeleteI amusing Java 8.
Exception in thread "main" java.lang.NoSuchMethodError: org.xhtmlrenderer.layout.SharedContext: method ()V not found
at org.xhtmlrenderer.pdf.ITextRenderer.(ITextRenderer.java:107)
at org.xhtmlrenderer.pdf.ITextRenderer.(ITextRenderer.java:98)
at CreatePDF.testpdf(CreatePDF.java:257)
at CreatePDF.main(CreatePDF.java:23)
let me know jar versions to be used.
Can anyone help me to get away from this erro.
ReplyDeleteorg.xhtmlrenderer.util.XRRuntimeException: Can't load the XML resource (using TRaX transformer). java.io.IOException: Stream closed
i am not getting the image in my pdf, but the there is image in my html page.
ReplyDeletei am using the same code given above