pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alex Sviridov <ooo_satu...@mail.ru>
Subject Re[4]: PDFRenderer, PDDocument memory issue
Date Wed, 01 Jul 2015 11:09:38 GMT
 I decided to show all the code. I also send the pdf file - some file from internet I use for
testing.

Task task = new Task() {
    @Override protected Integer call() throws Exception {
        for (int i=0;i<model.getTotalPages();i++){
            System.out.println("Point a:"+i);
            WritableImage writableImage=model.getPageThumbImage(i);
            System.out.println("Point b:"+i);
            ImageView imageView=new ImageView(writableImage);
            System.out.println("Point c:"+i);
            Label label=new Label(Integer.toString(i+1));
            System.out.println("Point d:"+i);
            VBox vBox=new VBox(imageView,label);
            System.out.println("Point e:"+i);
            vBox.setAlignment(Pos.CENTER);
            vBox.setStyle("-fx-padding:5px 5px 5px 5px;-fx-background-color:red");
            System.out.println("Point f:"+i);
            Platform.runLater(new Runnable() {
                @Override
                public void run() {
                     thumbFlowPane.getChildren().add(vBox);
                }
            });
        }
        return null;
    }
};
new Thread(task).start();

And here is the tail of the output
....
Point a:30
Point b:30
Point c:30
Point d:30
Point e:30
Point f:30
Point a:31

What is scratch file? Sorry, I don't understand you.






Среда,  1 июля 2015, 13:04 +02:00 от Andreas Lehmkühler <andreas@lehmi.de>:
>
>
>> Alex Sviridov < ooo_saturn7@mail.ru > hat am 1. Juli 2015 um 12:58 geschrieben:
>> 
>> 
>>  Thank you for answer. I tried pdfbox-app-2.0.0-20150630.220424-1464.jar the
>> result is the same.
>> 
>> When I create images I add them to javafx FlowPane. However, the problem is
>> not in images because I repeat - I get 400mb when I do
>> pdfDocument=null,pdfRenderer=null.
>> 
>> Bedised, when I do pdfDocument = PDDocument.load(new File(fileName)) I don't
>> have any problems with memory. 
>> 
>> I'm getting problem with memory when I run in for loop getPageThumbImage.
>> 
>> I am sure that the problem is in PdfBox. Please, help me.
>Maybe, but I'm not sure at all.
>
>Try to use the scratch file.
>
>> Среда,  1 июля 2015, 12:48 +02:00 от Andreas Lehmkühler < andreas@lehmi.de
>:
>> >
>> >
>> >> Alex Sviridov <  ooo_saturn7@mail.ru > hat am 1. Juli 2015 um 10:16
>> >> geschrieben:
>> >> 
>> >> 
>> >>  I want to display all page thumbnails. However I came across memory size
>> >> problem with PDFRenderer or PDDocument - I don't know which one. 
>> >> 
>> >> I have the following code:
>> >>    ....
>> >>     private PDDocument pdfDocument;
>> >>     
>> >>     private PDFRenderer pdfRenderer;
>> >> 
>> >>     public WritableImage getPageThumbImage(int page){
>> >>         WritableImage result=null;
>> >>         try {
>> >>             BufferedImage bi=pdfRenderer.renderImageWithDPI(page,
12,
>> >> ImageType.RGB);
>> >>             result=SwingFXUtils.toFXImage(bi, null);
>> >>         } catch (IOException ex) {
>> >>              ....
>> >>         }
>> >>         return result;
>> >>     }
>> >>  .....
>> >> The method getPageThumbImage I run in for loop for every page.I set java
>> >> memory heap to 500mb. 
>> >> And I can get about 30 images using getPageThumbImage (if I set more memory
>> >> I
>> >> get more). 
>> >> In my application I have real time memory graphs and they show that memory
>> >> is
>> >> very fast filled. 
>> >> When there is no more free memory getPageThumbImage hangs - no exception,
>> >> nothing. But the code stops.
>> >> When I do pdfDocument=null,pdfRenderer=null I get about 400mb free memory.
>> >> How
>> >> to solve this problem?
>> >There are 2 possible issues and maybe both are relevant.
>> >
>> >1. PDFBox consumes more or less memory to load a pdf depending on the size
>> >and
>> >the content of the pdf.
>> >
>> >- Are you using the latest 2.0.0-SNAPSHOT? There were some improvements
>> >concerning the memory footprint lately
>> >- Try to use of a scratch file (there are load methods including a boolean
>> >switcht ot activate that)
>> >
>> >2. Your own implementation consumes more or less memory to process those
>> >thumbnails
>> >
>> >- check if you are releasing all resources (ecspecially those images you're
>> >creating) you are using during your process
>> >
>> >HTH,
>> >Andreas
>> >
>> >---------------------------------------------------------------------
>> >To unsubscribe, e-mail:  users-unsubscribe@pdfbox.apache.org
>> >For additional commands, e-mail:  users-help@pdfbox.apache.org
>> >
>> 
>> 
>> -- 
>> Alex Sviridov
>
>BR
>Andreas
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail:  users-unsubscribe@pdfbox.apache.org
>For additional commands, e-mail:  users-help@pdfbox.apache.org
>


-- 
Alex Sviridov
Mime
View raw message