HTML to PDF / DOCX / RTF Java converter library › Forums › PD4ML v3 Archived Forums (Read Only) › Troubleshooting › OutOfMemory with page with many large images
- This topic has 0 replies, 1 voice, and was last updated Sep 28, 2015
13:13:44 bygirgen.
Viewing 1 post (of 1 total)
-
AuthorPosts
-
September 28, 2015 at 13:13#27048
Hi,
With a long html page filled with photos, we get OutOfMemory. Raising the memory limit is not an option, it already very high, 8-12 GB. This is a server and we’re using the Java API.
We need a way to let PD4ML render pages an images in a streaming fashion, more memory efficient. It cannot keep the entire rendered PDF, with all hi-res images, in memory.
How can achieve this?
private static PD4ML createPD4ML(int htmlWidth, Insets insetsMM, boolean landscape) throws FileNotFoundException { PD4ML pd4ml = new PD4ML(); pd4ml.setPageInsetsMM(insetsMM); pd4ml.setHtmlWidth(htmlWidth); pd4ml.setPageSize(landscape ? pd4ml.changePageOrientation(PD4Constants.A4) : PD4Constants.A4); pd4ml.enableSmartTableBreaks(true); if (log.isDebugEnabled()) { pd4ml.enableDebugInfo(); } pd4ml.useTTF("java:net/pingpong/tm/fonts", true); return pd4ml; } private static void createPDF(Person person, User user, Course course, HtmlResource htmlResource, File tmpPdf) throws FileNotFoundException, IOException { OutputStream outputStream = new FileOutputStream(tmpPdf); String html = resolvePathsAndFixHtml(person, user, htmlResource, course, true); try { DocumentManagerHandler.writePDFWithHeader(html, outputStream);…
and in DocumentManagerHandlerpublic static void writePDFWithHeader(String html, OutputStream outputStream) throws InvalidParameterException, IOException { PD4ML pd4ml = createPD4ML(DEFAULT_HTML_WIDTH, DEFAULT_INSETS_MM, false); pd4ml.setHtmlWidth(640); PD4PageMark header = new PD4PageMark(); header.setTitleAlignment(PD4PageMark.RIGHT_ALIGN); header.setFont(new Font("sansserif", Font.PLAIN, 11)); header.setAreaHeight(25); header.setTitleTemplate("${title}"); pd4ml.setPageHeader(header); pd4ml.render(new StringReader(html), outputStream); } -
AuthorPosts
Viewing 1 post (of 1 total)
The forum ‘Troubleshooting’ is closed to new topics and replies.
