PDF HTML table using iText

I am parsing some HTML using HTMLWorker in Java and then pasting it into PDF using iText. I create a document by calling new Document(PageSize.A4, 40, 40, 40, 40); , which should indicate a margin of 40px from all sides, but when I paste the parsed HTML code that contains a table wider than the page, the right edge does not work, and the table reaches the right border of the page ... All fields are fine, except for the correct one. .. any suggestions?

corresponding code:

 Document document = new Document(PageSize.A4, 40, 40, 40, 40); HashMap<String, Object> map = new HashMap<String, Object>(); map.put(HTMLWorker.FONT_PROVIDER, new MyFontFactory10()); HTMLWorker worker = new HTMLWorker(document); worker.setProviders(map); worker.parse(new StringReader(VARIABLE_CONTAINING_HTML_CODE)); 
+4
source share
1 answer

It should work. Can you provide information on the iText version and what the HTML code looks like. Images can make the table extensible outside the field (by the way, these are not pixels).

Try this code and see if the problem remains. The table should not expand beyond the page margin. Tables used with HTMLWorker always get 100% width of their container.

 Document document = new Document(PageSize.A4, 40, 40, 40, 40); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("c:/TEST.pdf")); document.open(); HTMLWorker worker = new HTMLWorker(document); String code = "<table border=1><tr><td>Test</td><td>Test</td></tr></table>"; worker.parse(new StringReader(code)); document.close(); 
+1
source

All Articles