openhtmltopdf icon indicating copy to clipboard operation
openhtmltopdf copied to clipboard

Generate PDF from multiple HTML

Open varshaldavda opened this issue 1 year ago • 1 comments

I am using this library to generate PDF from multiple HTML files. I can do so but it starts new PDF on a new page instead of existing page. Can anyone help me?

Attaching my code here :

PDDocument doc = new PDDocument();
		File file = File.createTempFile("temp_openhtmltopdf_", ".pdf");
		PdfRendererBuilder builder = new PdfRendererBuilder();
		builder.useDefaultPageSize(210, 297, PageSizeUnits.MM);
		builder.useSVGDrawer(new BatikSVGDrawer());
		builder.usePDDocument(doc);
		for (String html : uris) {
			builder.withHtmlContent(html, "UTF-8");
			PdfBoxRenderer renderer = builder.buildPdfRenderer();
			renderer.createPDFWithoutClosing();
		}
		doc.save(file);
		doc.close();

It generates 2 page PDF. I want to start the 2nd page from the ending of the 1st page.

varshaldavda avatar Mar 03 '23 08:03 varshaldavda

Concatenating multiple renderings at their respective bottom positions is doable yet not so straightforward; you have to combine the solutions discussed here:

  • https://github.com/danfickle/openhtmltopdf/issues/662
  • https://github.com/danfickle/openhtmltopdf/pull/666 (see also https://github.com/danfickle/openhtmltopdf/issues/427)

At the moment, concatenating multiple renderings may also produce some undesirable effect, such as font resource duplication (see https://github.com/danfickle/openhtmltopdf/issues/683).

stechio avatar Mar 20 '23 18:03 stechio