Merge Files
PSPDFKit Processor lets you merge multiple files together using the importDocument
operation. This is useful when you want to concatenate multiple documents and create a large document or add cover pages to an existing document.
Before you get started, make sure Processor is up and running.
Merging a Document into a File on Disk
Send a request to the /process
endpoint, attaching an input file and the operations JSON:
curl -X POST http://localhost:5000/process \ -F file=@/path/to/example.pdf \ -F cover=@/path/to/cover.pdf \ -F operations='{ "operations": [ { "type": "importDocument", "document": "cover", "beforePageIndex": "first" } ] }' \ -o result.pdf
POST /process HTTP/1.1 Content-Type: multipart/form-data; boundary=customboundary --customboundary Content-Disposition: form-data; name="file"; filename="example.pdf" Content-Type: application/pdf <PDF data> --customboundary Content-Disposition: form-data; name="cover"; filename="cover.pdf" Content-Type: application/pdf <PDF data> --customboundary Content-Disposition: form-data; name="operations" Content-Type: application/json { "operations": [ { "type": "importDocument", "document": "cover", "beforePageIndex": "first" } ] } --customboundary--
This will add all of the pages of the imported document before the first page of the input file.
Merging Document into a File from a URL
Send a request to the /process
endpoint, attaching a URL pointing to an input file and the operations JSON:
curl -X POST http://localhost:5000/process \ -F url=https://pspdfkit.com/downloads/examples/paper.pdf \ -F cover=@/path/to/cover.pdf \ -F operations='{ "operations": [ { "type": "importDocument", "document": "cover", "beforePageIndex": "first" } ] }' \ -o result.pdf
POST /process HTTP/1.1 Content-Type: multipart/form-data; boundary=customboundary --customboundary Content-Disposition: form-data; name="url" https://pspdfkit.com/downloads/examples/paper.pdf --customboundary Content-Disposition: form-data; name="cover"; filename="cover.pdf" Content-Type: application/pdf <PDF data> --customboundary Content-Disposition: form-data; name="operations" Content-Type: application/json { "operations": [ { "type": "importDocument", "document": "cover", "beforePageIndex": "first" } ] } --customboundary--
This will add all of the pages of the imported document before the first page of the input file.