Viewing 1 post (of 1 total)
  • Author
    Posts
  • #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 DocumentManagerHandler

    public 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);
    }
    

Viewing 1 post (of 1 total)

The forum ‘Troubleshooting’ is closed to new topics and replies.