Split PDF files
Welcome to the Split PDF guide. This guide will teach you how to Split one PDF in two or more PDF files easily.
Remember that all Tool Guides takes into account that you have previous knowledge about the Basics to process a PDF with our REST API. We strongly recommend you to read the related guide before start with this one.
The are several ways to split a PDF but the most simple is by defining ranges of pages to split:
The function setRanges() can define multiple page ranges to split your document. You’ll have as a result a packaged file to download with as much files as ranges you have set.
According to this code example, the final output will be of two zipped PDFs. One with the pages from 2 to 4 and the other with pages from 6 to 8.
Note that if you set a range greater than the maximum page number of your document, you will get as much pages as can be splitter from this document. But if your range starts in a page number greater than the number of pages of your document, you will get and error and the Process will fail.
We have seen how to split a document by page ranges but there are more ways to split, see the following:
Split by fixed ranges
setFixedRange(n) will split your PDF every N pages. If you set a bigger fixed range number than your document number of pages, you will get an error.
Split by removing pages
setRemovePages() let you set ranges of pages to be removed from your document and returns as a result a unique PDF without the specified pages. Note that if you set a range as big as the number of pages of your document you will get an error.
Merge after an Split
When you split a document by setting specific ranges you can merge all this ranges together in a single file with setMergeAfter(). You will get as a result a unique PDF file.