Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pdf conversion Using java library

I am willing to convert xhtml files into pdf/a format or pdf files to pdf/a format.. Can anyone please suggest which java library I can use.. Thank you

I will make my example more specific

I have a simple html file xyz.html

<html><body>
hello
<br>
<font style = "Helvetica">hello</font>
<br>
</body></html>

java code :

Document document = new Document(PageSize.A4);
FileOutputStream fout = new FileOutputStream(pdffile);
PdfWriter pdfWriter = PdfWriter.getInstance(document, fout);
pdfWriter.setPDFXConformance(PdfWriter.PDFA1B);
FileReader fr = new FileReader(xyz.html);
document.open();
HashMap<String, Object> Provider = new HashMap<String, Object>();
DefaultFontProvider def = new 
Provider.put(HTMLWorker.FONT_PROVIDER, def);
HTMLWorker htmlWorker = new HTMLWorker(document);
htmlWorker.setProviders(Provider);
htmlWorker.parse(fr);

I get the error com.itextpdf.text.pdf.PdfXConformanceException: All the fonts must be embedded. This one isn't: Helvetica

like image 722
ranjan Avatar asked Aug 29 '12 10:08

ranjan


2 Answers

try the flying soucer: http://code.google.com/p/flying-saucer/

like image 199
CloudyMarble Avatar answered Nov 15 '22 11:11

CloudyMarble


Check for iText library which has support for both Java and .net
http://itextpdf.com/

Few examples in the below link :
http://itextpdf.com/book/examples.php
http://www.rgagnon.com/javadetails/java-html-to-pdf-using-itext.html

This is proprietory but Its really a smart enterprise library and has good customer support.

like image 30
sundar Avatar answered Nov 15 '22 11:11

sundar