Merge PDF documents programmatically
ConvertAPI provides a PDF Merge tool available as a REST API service. In addition, we provide a Python SDK for effortless integration into your project. It is accessible via pip, and the source code can be found on GitHub. Simply sign up for a free account, grab your API secret key, install our Pyhon library, and you are good to go!
Install the ConvertAPI library into the Python project
Install using pip:
pip install --upgrade convertapi
Or install from the source with:
python setup.py install
Merge PDF files using Python
Once you have the library installed, you can use this code example to join multiple PDF files using Python programming language:
import convertapi
import os
import tempfile
# Code snippet is using the ConvertAPI Python Client: https://github.com/ConvertAPI/convertapi-python
# Read more about PDF Merge API: https://www.convertapi.com/pdf-to-merge
convertapi.api_secret = 'your-api-secret'
convertapi.convert('merge', {
Files: [
'/path/to/sample-1.pdf',
'/path/to/sample-2.pdf',
'/path/to/sample-3.pdf'
]
}, from_format = 'pdf').save_files('/path/to/dir')
That's all it takes to implement a PDF merge functionality into the Python project. You can combine local PDF files together with the files hosted on a server accessible via the URL, or the files uploaded to our server accessible by FileId.
Advanced techniques
You can find a complete list of conversion parameters on our interactive demo tool page. More advanced techniques and examples can be found in our GitHub examples folder. Happy coding!