-1

I have tried using Flying Saucer to convert html to pdf. Somehow it coverts the pain text only. I'm having images (img tags) and I want them too. This is what I did. How do I make this for images?

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(false);
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document doc = builder.parse(new File("sampleData.htm"));

    ITextRenderer renderer = new ITextRenderer();
    renderer.setDocument(doc, "");
    renderer.layout();
    OutputStream os = response.getOutputStream();
    renderer.createPDF(os);

Thank you!

sura2k
  • 7,365
  • 13
  • 61
  • 80

2 Answers2

0

Actually this might be a late reply but I still if it can help someone. Images are not supported internally in itext api. you have to explicitly tell the itext to include tags like like that. I am giving you the link you can refer to http://www.samuelrossille.com/home/category/java for a clear understanding. And if you need any working code I can help you just let me know.

samir
  • 339
  • 6
  • 19
-1

I faced similar issue with another PDF converter some time back. This could the problem when you images are relative to current directory.

Here is what you can do:

String curDir = System.getProperty("user.dir");

Try pasting the images in curDir and remove the relative path. Once this works, you can adjust you paths appropriately.

Chris
  • 5,584
  • 9
  • 40
  • 58