Try setting a higher -Xmx value; set a lower dpi, 78 is too big if you just need a thumbnail, it may be possible to calculate the dpi based on the page cropbox. Or look at your PDFs and make a guess based on what images you get. I'd expect something around 20-30 for A4 pages.

Tilman

Am 20.09.2018 um 08:55 schrieb paolodiro...@gmail.com:
Hi!

I have the same issue with some PDF and this is my code.

@Async(value = "asyncExecutor")
        public void createThumbnailForPDF(File filePDF, String jobNumber)
        {
                try
                {
                        if (filePDF != null && jobNumber != null && 
!jobNumber.isEmpty())
                        {

                                jobNumber = jobNumber.trim();
                                long fileSizeInBytes = filePDF.length();
                                long fileSizeInKB = fileSizeInBytes / 1024;
                                long fileSizeInMB = fileSizeInKB / 1024;
                                if (fileSizeInMB > PDF_MAX_SIZE)
                                {
                                        log.error("File too large. PDF_MAX_SIZE: " + 
PDF_MAX_SIZE + ". Thumbnail not created. Jobnumber: " + jobNumber);
                                        return;
                                }

                                try
                                {
                                        String fileName = filePDF.getName();
                                        String extension = 
fileName.substring(fileName.lastIndexOf("."));
                                        if (!StringUtils.isEmpty(extension) && 
extension.equalsIgnoreCase(".pdf"))
                                        {
                                                PDDocument documentPDF = null;
                                                PDFRenderer pdfRenderer = null;
                                                BufferedImage bim = null;
                                                try
                                                {
                                                        documentPDF = 
PDDocument.load(filePDF);
                                                        if (documentPDF != null)
                                                        {

                                                                try
                                                                {
                                                                        log.info("PDF document 
loaded. Jobnumber: " + jobNumber + ". PDF Title: " + 
documentPDF.getDocumentInformation().getTitle());
                                                                } catch 
(Exception e)
                                                                {
                                                                        
log.error("Error reading document title property.", e.getMessage());
                                                                }

                                                                pdfRenderer = 
new PDFRenderer(documentPDF);
                                                                if (pdfRenderer 
!= null)
                                                                {
                                                                        bim = 
pdfRenderer.renderImageWithDPI(0, 78f, ImageType.RGB);
                                                                        if (bim 
!= null)
                                                                        {
                                                                                
// thumbnail 200
                                                                                
int newHeight200 = (int) getNewHeight(bim.getWidth(), bim.getHeight(), 200);
                                                                                
BufferedImage buff200 = resizeImage(bim, 200, newHeight200);
                                                                                if (buff200 != 
null) ImageIO.write(buff200, "jpg", new 
File(applicationProperties.getDocumentWithSubfolderRootPath() + File.separator + jobNumber + 
File.separator + jobNumber + "_200.jpg"));

                                                                                
// thumbnail 100
                                                                                
int newHeight100 = (int) getNewHeight(bim.getWidth(), bim.getHeight(), 100);
                                                                                
BufferedImage buff100 = resizeImage(bim, 100, newHeight100);
                                                                                if (buff100 != 
null) ImageIO.write(buff100, "jpg", new 
File(applicationProperties.getDocumentWithSubfolderRootPath() + File.separator + jobNumber + 
File.separator + jobNumber + "_100.jpg"));

                                                                        }
                                                                        else
                                                                        {
                                                                                
log.error("Thumbnail creation, Bitmap is null. Jobnumber: " + jobNumber);
                                                                        }

                                                                }

                                                        }
                                                        else
                                                                log.error("Thumbnail 
creation, failed to load PDF. Jobnumber: " + jobNumber);

                                                } catch (IOException io)
                                                {
                                                        log.error("Thumbnail 
creation, IoException while loading PDF. Jobnumber: " + jobNumber, io.getMessage());
                                                } catch (Exception e)
                                                {
                                                        log.error("Failded to create 
thumbnails. Jobnumber: " + jobNumber, e.getMessage());
                                                } finally
                                                {
                                                        try
                                                        {
                                                                if (documentPDF 
!= null) documentPDF.close();
                                                                if (bim != null)
                                                                {
                                                                        
bim.flush();
                                                                        bim = 
null;
                                                                }
                                                                pdfRenderer = 
null;

                                                                

                                                        } catch (IOException e)
                                                        {
                                                                log.error("Error 
while empty the variables after thumbnails creation." + e.getMessage());
                                                        }
                                                }
                                        }
                                        else
                                        {
                                                log.info("Current file is not a 
PDF");
                                        }

                                } catch (Exception e)
                                {
                                        log.error("Failded to create thumbnails. 
Jobnumber: " + jobNumber, e);
                                }
                        }

                } catch (Exception e)
                {
                        log.error("createThumbnailForPDF something went wrong during 
thumbnails creation.", e.getMessage());
                }
        }

I think that the code is pretty much correct. So the only solution is to 
increase the memory of the JVM?

Regards,
Paolo


On 2016/08/28 11:30:43, Tilman Hausherr <thaush...@t-online.de> wrote:
Am 28.08.2016 um 10:53 schrieb or...@beeriprint.co.il:
looks like MemoryUsageSetting.setupTempFileOnly() has no affect ?
do I use it incorrectlly ?
You're using it correctly. The solution is below:

** I can overcome this problem with -Xmx1500m but had to increase my physical 
memory.. , and.., I have much bigger files (250000 pages)

Additionally, if you're doing rendering, take care not to keep the
result images in memory.


Tilman


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@pdfbox.apache.org
For additional commands, e-mail: users-h...@pdfbox.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@pdfbox.apache.org
For additional commands, e-mail: users-h...@pdfbox.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@pdfbox.apache.org
For additional commands, e-mail: users-h...@pdfbox.apache.org

Reply via email to