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