How do you Split a PDF by Size?

Question:
I need to split a PDF based on the size of the file. Say I have a 100 KB file and the max size of each page needs to be 20KB - how can I do this?

Answer:
This can definitely be accomplished using the Apryse SDK. Take a look at the following methods by which this might be accomplished:

Method 1:

  1. Save the state of the document after each page is read so that the size may be observed.

  2. When the current size exceeds the max size per page (i.e. 20KB), discard the last save and return / store the previous save.

  3. Re-do the current page as the first of a new PDF.

Method 2:

  1. Save after each page insertion using e_incremental. This is a fast save which always grows the file (appends data only).

  2. When the desired max size per page is exceeded, go back to the previous save.

  3. Save one last time using e_linearized.

  4. Re-do the current page as the first of a new PDF.

Notes:

  • Take a look at our PDFPage Sample here.

  • The different save options for use with the Apryse SDK may be viewed here.

  • More information regarding a PDFTron.Page object may be viewed here.

  • If your design requirements allow for the size of each page to occasionally grow somewhat over the size limit per page, you can optimize this splitting functionality by keeping the last page that caused the size limit per page to exceed, and thus assume that the e_linearized will almost always bring the file back below the max size per page (with no guarantee).