1

I am trying to convert html to pdf with iText API(itextpdf.5.5.7.jar, xmlworker 5.5.7.jar), everything is good except the text inside the pre tag.

In html the text inside the pre is good but in PDF the formatting is totally gone and simply coming in normal lines without formatting. I checked the blogs but I did not find correct answer.


Please find the screen shots for HTML and PDF.

HTML screen: HTML screen

PDF screen: PDF screen

this is my code

String pdfFileName="C:\test.pdf";    
com.itextpdf.text.Document document = new com.itextpdf.text.Document();
PdfWriter writer = PdfWriter.getInstance(document,
    new FileOutputStream(pdfFileName));
writer.setInitialLeading(12.5f);
document.open();
HtmlPipelineContext htmlContext = new HtmlPipelineContext(null);
htmlContext.setTagFactory(Tags.getHtmlTagProcessorFactory());
CSSResolver cssResolver = XMLWorkerHelper.getInstance()
        .getDefaultCssResolver(true);       
Pipeline<?> pipeline = new CssResolverPipeline(cssResolver,
        new HtmlPipeline(htmlContext, new PdfWriterPipeline(document,
                writer)));      
XMLWorker worker = new XMLWorker(pipeline, true);        
XMLParser p = new XMLParser(worker);         
File input = new File(completeHtmlFilePath);
p.parse(new InputStreamReader(new FileInputStream(input), "UTF-8"));        
document.close();           
return pdfFileNameWithPath; 
mkl
  • 90,588
  • 15
  • 125
  • 265
  • 2
    For urgent questions, please contact your account manager at iText Group to get [Premium support](http://itextpdf.com/support). If you're not paying for your use of iText, then you should not use the word "urgent". – Bruno Lowagie Mar 02 '16 at 10:49
  • "the formatting is totally gone" - would you upload a screenshot of what is going wrong? – halfer Mar 02 '16 at 12:21

0 Answers0