Determine PDF file size - Split PDF file on the basis of size using Aspose.PDF for Java

Was wondering if Splitting a PDF by size has been implemented yet as asked about previously below.

@danwise

The logged ticket in referenced thread was resolved and investigation of the ticket resulted that the only way to know the size of the resulting document is to save the document - as many final calculations and optimizations are done only on saving process. You can save the document to ByteArrayOutputStream and check the size of the resulting stream. Please, see code snippet bellow:

com.aspose.pdf.Document document = new com.aspose.pdf.Document();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
for (int page = startPartPage; page < endPartPage; page++) {
//here I want to check the size of "document" object

document.getPages().add(originalDocument.getPages().get_Item(page));

stream.reset();
document.save(stream);

System.out.println("size: " + stream.size());

}
document.setOptimizeSize(true);
document.save(testdata + "PDFJAVA_36221/out"+ version + ".pdf");

Yeah I did see that. That’s more of a hack than anything else.

If there’s a way to request an enhancement, can you add a request to officially support split by size. I realize it won’t be acted on right away. But it’s a large hole in Aspose.PDFs functionality.

Right now we’ll be using IText instead of Aspose due to Asposes poor merge/split support.

Thanks!


This Topic is created by shahzadlatif using Email to Topic tool.

@danwise

Thanks for sharing your feedback.

We have logged an investigation ticket as PDFJAVA-39932 in our issue tracking system in order to further investigate whether determining the PDF file size at the time of generation is possible or not. We will surely implement such a feature in the API as soon as its possibility is analyzed and let you know once the ticket is resolved. Please be patient and give us some time.

We apologize for the inconvenience.