Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id D6F2E200CC2 for ; Wed, 5 Jul 2017 17:57:06 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id D5721163BAE; Wed, 5 Jul 2017 15:57:06 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 0EF6B163BAF for ; Wed, 5 Jul 2017 17:57:05 +0200 (CEST) Received: (qmail 14980 invoked by uid 500); 5 Jul 2017 15:57:05 -0000 Mailing-List: contact dev-help@pdfbox.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@pdfbox.apache.org Delivered-To: mailing list dev@pdfbox.apache.org Received: (qmail 14916 invoked by uid 99); 5 Jul 2017 15:57:03 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 05 Jul 2017 15:57:03 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 45F07180352 for ; Wed, 5 Jul 2017 15:57:03 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -99.202 X-Spam-Level: X-Spam-Status: No, score=-99.202 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, RP_MATCHES_RCVD=-0.001, SPF_PASS=-0.001, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id K7zcgR9M-LSK for ; Wed, 5 Jul 2017 15:57:01 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTP id 2237560D12 for ; Wed, 5 Jul 2017 15:57:01 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 6903DE08C6 for ; Wed, 5 Jul 2017 15:57:00 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 23D9D2462C for ; Wed, 5 Jul 2017 15:57:00 +0000 (UTC) Date: Wed, 5 Jul 2017 15:57:00 +0000 (UTC) From: "Tilman Hausherr (JIRA)" To: dev@pdfbox.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (PDFBOX-3852) Overlay a pdf file which is 750 pages ends up in OutOfMemoryError MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Wed, 05 Jul 2017 15:57:07 -0000 [ https://issues.apache.org/jira/browse/PDFBOX-3852?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16074992#comment-16074992 ] Tilman Hausherr commented on PDFBOX-3852: ----------------------------------------- I was able to run your test code with my modification (which uses two maps) with -Xmx1200m. This is a bit much for this type of operation. Your watermark file is quite large, the reason is that the font is not subsetted. But that isn't the cause... I was wrong when I wrote "I also doubt that your change in createStream helps much, these are tiny streams.". The default constructor of COSStream() creates a new memory scratch file... which is ....WTF!? an array with 100000 entries!!! I'll fix this, although in a different way than in your patch. > Overlay a pdf file which is 750 pages ends up in OutOfMemoryError > ----------------------------------------------------------------- > > Key: PDFBOX-3852 > URL: https://issues.apache.org/jira/browse/PDFBOX-3852 > Project: PDFBox > Issue Type: Bug > Components: PDModel > Affects Versions: 2.0.6 > Environment: Unbuntu, jetty > Reporter: ryuukei > Assignee: Tilman Hausherr > Labels: Overlay > Attachments: 750-pages.pdf, McAfee.pdf, Overlay.patch, watermarked.pdf > > > We found an issue and solution to fix it, you guys might would be interested to have a look and see whether it is worth applying the attached patch to benefit more pdfbox users. :-) And a bit more detail this error happens based on jetty running time memory setting, and pdf file size. > * Application platform: > Unbuntu, jetty > * The test case to produce this issue: > Add simple overlay to all pages (in this case it is 750 pages). The processPages function eats up the JVM memories while applying the overlay to the file. > * sample code for using pdfbox overlay: > {code} > PDDocument document = PDDocument.load( pdf ); > HashMap overlayGuide = new HashMap(); > for (int i = 0; i < pagenunber; i++) > { > // "watermarked.pdf" meat to be a file which contains watermarks on the page > overlayGuide.put(i+1, "watermarked.pdf"); > } > Overlay overlay = new Overlay(); > overlay.setInputPDF( document ); > overlay.setOverlayPosition( Overlay.Position.FOREGROUND ); > PDDocument overlayResult = overlay.overlay( overlayGuide ); > {code} > * Error log: > {code} > INFO | jvm 1 | main | 2017/07/03 13:06:23 | java.lang.OutOfMemoryError: Java heap space > STATUS | wrapper | main | 2017/07/03 13:06:23 | Filter trigger matched. Restarting JVM. > INFO | jvm 1 | main | 2017/07/03 13:06:23 | at org.apache.pdfbox.io.ScratchFile.(ScratchFile.java:128) > INFO | jvm 1 | main | 2017/07/03 13:06:23 | at org.apache.pdfbox.io.ScratchFile.getMainMemoryOnlyInstance(ScratchFile.java:143) > INFO | jvm 1 | main | 2017/07/03 13:06:23 | at org.apache.pdfbox.cos.COSStream.(COSStream.java:55) > INFO | jvm 1 | main | 2017/07/03 13:06:23 | at org.apache.pdfbox.multipdf.Overlay.createStream(Overlay.java:***) > INFO | jvm 1 | main | 2017/07/03 13:06:23 | at org.apache.pdfbox.multipdf.Overlay.processPages(Overlay.java:364) > INFO | jvm 1 | main | 2017/07/03 13:06:23 | at org.apache.pdfbox.multipdf.Overlay.overlay(Overlay.java:128) > {code} > * Solution > Apply MemoryUsageSetting to Overlay, allows Overlay to use file as temp output. > * Update for the Overlay usage: > {code} > PDDocument document = PDDocument.load( pdf ); > HashMap overlayGuide = new HashMap(); > for (int i = 0; i < pagenunber; i++) > { > overlayGuide.put(i+1, "watermarked.pdf"); > } > Overlay overlay = new Overlay(); > overlay.setInputPDF( document ); > overlay.setOverlayPosition( Overlay.Position.FOREGROUND ); > // set overlay to use temp file as out rather than memory > MemoryUsageSetting memoryUsageSetting = MemoryUsageSetting.setupTempFileOnly( ); > memoryUsageSetting.setTempDir( new File ( "someTempWorkingDir" ) ); > overlay.setMemoryUsageSetting( memoryUsageSetting ); > PDDocument overlayResult = overlay.overlay( overlayGuide ); > {code} -- This message was sent by Atlassian JIRA (v6.4.14#64029) --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org For additional commands, e-mail: dev-help@pdfbox.apache.org