Linearize existing large PDF documents

Skip Navigation LinksHome  /  Support  /  Forums  /  DynamicPDF Merger for Java (v5.x)  /  Display Thread

DynamicPDF Merger for Java (v5.x) Forum

Hello,

We are currently looking at Java options to linearize and secure PDF documents that are sent in emails, are printed and also rendered on the Web. I have used some sample code to linearize documents using the PdfFormat.LINEARIZED setting. This works fine for smaller documents, but for larger ones, we are running into outofmemory errors since we are using the FileInputStream object to open the exiting PDFs. I would like to know what other options are avaiable in the API for doing this? Please advice


Sample code looks like

        public static void pdfWebFast(String in_filename) {
                
                long time = System.currentTimeMillis();
                Document dyna  = new Document ();
                dyna.setPdfFormat(PdfFormat.LINEARIZED);
                FileInputStream inStream = null;
                try {
                        inStream = new FileInputStream(in_filename);
                } catch (FileNotFoundException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                }
                try {
                        PdfDocument pdfDocument = new PdfDocument(inStream);
                        for (int i = 1 ; i <= pdfDocument.getPages().getSize(); i++)        {
                                ImportedPage page = new ImportedPage(pdfDocument.getPage(i));
                                dyna.getPages().add(page);
                        }
                        
                        dyna.draw(in_filename+"x");
                        try {
                                inStream.close();
                        } catch (IOException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                        }
                        File file = new File(in_filename+"x");
                        File file2 = new File(in_filename);
                        file2.delete();
                        boolean success = file.renameTo(file2);
                        System.out.println("Time taken for PDF linerization is::"+(System.currentTimeMillis() - time));
                } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
}
Posted by a ceTe Software moderator
Hello,

Can you please let us know what is size of the input PDF document which you are using for merging? Also please send over the full stack trace of the error message, input PDF document with which you are getting error while merging and linearizing to our support team at support@cete.com so that they can look into this issue further.


Thanks,
ceTe Software Support Team.
Posted by a ceTe Software moderator
Hello,

A new version (v6.0) of DynamicPDF for Java has been released that has bug fixes that address the out of memory and stack over flow issues with huge files. Here is the download link for the new version:
http://www.DynamicPDF.com/Products/DynamicPDFForJava/Download.csp

Thanks,
ceTe Software Support Team.

All times are US Eastern Standard time. The time now is 8:37 AM.