1
public class GeneratePDF {
public static void main(String[] args) {
    try {
        String k = "<html><body> This is my Project </body></html>";
        OutputStream file = new FileOutputStream(new File("E:\\Test11.pdf"));
        Document document = new Document();
        PdfWriter writer = PdfWriter.getInstance(document, file);
        document.open();
        InputStream is = new ByteArrayInputStream(k.getBytes());
        XMLWorkerHelper.getInstance().parseXHtml(writer, document, is);
        document.close();
        file.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
}

This is my code for convert HTML to Pdf for Static and small content Html its working fine But for dynamic and long Html content it com.itextpdf.tool.xml.exceptions.RuntimeWorkerException this Excpetion please help me where am doing Wrong .

Aman Kumar
  • 323
  • 4
  • 5
  • 11

1 Answers1

0

The problem is that you have invalid html.

Try converting it using the HTMLWorker class

Community
  • 1
  • 1
MaVRoSCy
  • 17,747
  • 15
  • 82
  • 125
  • can u please Integarte with My code so that i can click on Button and its download save as Pdf – Aman Kumar Jul 24 '13 at 08:25
  • http://stackoverflow.com/questions/17828805/how-to-download-file-save-as-pdf-in-jsp please check this – Aman Kumar Jul 24 '13 at 08:29
  • add this below your jsp code : File f = new File("C:\\Test.pdf"); response.addHeader("Content-Disposition", "attachment; filename=\"Test.pdf\""); InputStream inputStream = new FileInputStream(f); BufferedOutputStream output = new BufferedOutputStream(response.getOutputStream()); byte by[] = new byte[32768]; int index; if (inputStream != null) { index = inputStream.read(by, 0, 32768); } else { index = -1; } while (index != -1) { output.write(by, 0, index); index = inputStream.read(by, 0, 32768); } output.flush(); – MaVRoSCy Jul 24 '13 at 08:38