The jar i am using is from the maven repo
The code i am testing is from a previous stack solution
I fear it might be outdated because the libraries are depreciated. When testing the following code:
import java.io.ByteArrayInputStream;
import java.io.FileOutputStream;
import org.w3c.dom.Document;
import org.xhtmlrenderer.pdf.ITextRenderer;
public class test
{
public static void main(String[] args)
{
ITextRenderer renderer = new ITextRenderer();
// if you have html source in hand, use it to generate document object
renderer.setDocumentFromString( "C:/Users/Goran/Documents/Documents/Development/workspace/FlyingSaucer/data/input/report.xhtml" );
renderer.layout();
String fileNameWithPath = "C:/Users/Goran/Documents/Documents/Development/workspace/FlyingSaucer/data/output/" + "PDF-FromHtmlString.pdf";
FileOutputStream fos = new FileOutputStream( fileNameWithPath );
renderer.createPDF( fos );
fos.close();
System.out.println( "File 2: '" + fileNameWithPath + "' created." );
}
}
I have the following error this this line: renderer.createPDF( fos );
The type com.lowagie.text.DocumentException cannot be resolved. It is indirectly referenced from required .class files
Anyone able to shed some light on this, or suggest the best way to create a pdf document in java? I have both XML and XHTML documents available.
EDIT When i add the com.lowagie.text library from the repo
Exception in thread "main" java.lang.NoClassDefFoundError: org/xhtmlrenderer/extend/UserAgentCallback
at test.main(test.java:16)
Caused by: java.lang.ClassNotFoundException: org.xhtmlrenderer.extend.UserAgentCallback
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
Am i even using the right libraries / the most up to date ones?
Can someone who has the most recent libraries or know a repo where they are stored link them?
EDIT 2 Abandoned idea of using flying saucer and using ApacheFop as suggested. Current error is:
Mar 10, 2016 9:58:23 PM org.apache.fop.events.LoggingEventListener processEvent
WARNING: Font "Symbol,normal,700" not found. Substituting with "Symbol,normal,400".
Mar 10, 2016 9:58:23 PM org.apache.fop.events.LoggingEventListener processEvent
WARNING: Font "ZapfDingbats,normal,700" not found. Substituting with "ZapfDingbats,normal,400".
Mar 10, 2016 9:58:23 PM org.apache.fop.events.LoggingEventListener processEvent
INFO: Rendered page #1.