HTML to PDF / DOCX / RTF Java converter library › Forums › PD4ML v3 Archived Forums (Read Only) › HTML/CSS rendering issues › Multiple Column PDF
- This topic has 2 replies, 2 voices, and was last updated Oct 10, 2016
18:27:09 byPD4ML.
-
AuthorPosts
-
September 1, 2016 at 21:42#27097
Hello. I am trying to render html to pdf such that only a portion of the html content is rendered to pdf in dual column format. I want the output to look like this:
Stuff before the dual-column text
column1text column2text
column1text column2text
… …Here is a sample test:
@Test public void dualColumnTest() throws Exception { PD4ML pd4ml = new PD4ML(); pd4ml.outputFormat(PD4ML.PDF); Insets insets = new Insets(10,10,10,10); pd4ml.setPageInsetsMM(insets); pd4ml.setHtmlWidth(800); pd4ml.adjustHtmlWidth(); Map<String, String> m = new HashMap<String, String>(); m.put(PD4Constants.PD4ML_MEDIA_TYPE_PRINT, "override"); pd4ml.setDynamicParams(m); pd4ml.generateMulticolumn(2, 5, true); String content = "" + "<html><body>" + "Stuff before the dual-column text " + "<div usedualcolumn="true">Lots of text to be placed in dual columns </div>" + "</body></html>"; StringReader htmlInput = new StringReader(content); FileOutputStream pdfOutput = new FileOutputStream("c:/bb/foo.pdf"); pd4ml.render(htmlInput, pdfOutput); }But when I use generateMulticolumn(2,5,true) it sets it for the entire document. How can I select only a portion of the html content for dual column pdf? Thank you!
September 2, 2016 at 18:06#29925I should add that I also tried to get the html properly rendering in browser with dual column. I did it using this head meta:
.printDualColumn { -moz-column-count: 2; -webkit-column-count: 2; column-count: 2; }And then I surrounded the content which needs dual column printing with:
<div class="printDualColumn">It renders correctly in dual column format in the browser from the html. But when I render the html to pdf using pd4ml it does not render in two column.
@Test public void dualColumnTest2() throws Exception { PD4ML pd4ml = new PD4ML(); pd4ml.outputFormat(PD4ML.PDF); Insets insets = new Insets(10,10,10,10); pd4ml.setPageInsetsMM(insets); pd4ml.setHtmlWidth(800); pd4ml.adjustHtmlWidth(); Map<String, String> m = new HashMap<String, String>(); m.put(PD4Constants.PD4ML_MEDIA_TYPE_PRINT, "override"); pd4ml.setDynamicParams(m); String content = "" + "<html>" + "<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><style type="text/css">" + "n.printDualColumn {n" + "tttt-moz-column-count: 2;n" + "tttt-webkit-column-count: 2;n" + "ttttcolumn-count: 2;n" + "ttt}n" + "</style></head>" + "<body>" + "Stuff before the dual-column text " + "<div class="printDualColumn">" + "Lots of text to be placed in dual columns" + "Lots of text to be placed in dual columns" + "Lots of text to be placed in dual columns" + "Lots of text to be placed in dual columns" + "</div>" + "</body></html>"; StringReader htmlInput = new StringReader(content); FileOutputStream htmlInputFile = new FileOutputStream("c:/bb/foo2.html"); htmlInputFile.write(content.getBytes()); FileOutputStream pdfOutput = new FileOutputStream("c:/bb/foo2.pdf"); pd4ml.render(htmlInput, pdfOutput); }Is there something I can do either in the css or in my java code?
October 10, 2016 at 18:27#29926For the time being there is only solution with
<pd4ml:layoutbox>tag. It is not exactly what you need, but in some cases it can be helpful.The tag tries to fit all given content into a specified box and automatically goes multicolumn when it is not possible with a single column.
See pdf-generation-troubleshooting-f4/is-it-possible-to-toggle-multicolumn-from-page-to-page-t255.html
Alternatively you may split your document to single- and multi-column parts, convert them separately and merge the resulting PDFs into a single doc (usin PD4ML’s PDF merge API).
-
AuthorPosts
The forum ‘HTML/CSS rendering issues’ is closed to new topics and replies.
