Java – HTML table in PDF format using iText

I'm using htmlworker in Java to parse some HTML code and insert it into PDF using iText I create a document by calling a new document (PageSize. A4,40,40); This should specify margins 40px in all respects, but when I insert parsed HTML code that contains a table wider than the page, the right margin does not work and the table reaches the right boundary of the page... All margins are OK except the correct edge Any suggestions?

Relevant codes:

Document document = new Document(PageSize.A4,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));

Solution

It should work

Try this code to see if the problem persists The table should not exceed the margins Tables used with HTML workers always get 100% of the width of their containers

Document document = new Document(PageSize.A4,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();
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>