Introduction to PDF Transformation

FastPDF is not just about rendering HTML templates into PDFs; it also provides an array of features that allow you to manipulate and fine-tune your PDFs. In this section, we'll take a closer look at some of these capabilities and show you how to make the most of them.

Before starting, make sure you have read the Quickstart guide, and that you have your API key ready.

Merging PDFs

FastPDF provides a simple API to merge multiple PDFs into a single PDF document. In this tutorial, we'll show you how to use the FastPDF API to merge three PDF documents.

Create an instance of the client. You'll need to pass your FastPDF API key to the constructor. You can find your API key in your account settings:

Register your token

from fastpdf import PDFClient

client = PDFClient("API_KEY")

Prepare a list of the PDF files you want to merge. As for all SDK calls they can be either local file paths or file-like objects:

Build a List of merge candidates PDFs

file_paths = ['path/to/first.pdf', 'path/to/second.pdf', 'path/to/third.pdf']

Use the merge method of the client to merge the PDFs. This method takes the list of file paths and returns the content of the merged PDF as bytes:

Merging the PDFs

merged_pdf_content = client.merge(file_paths)

If you want to save the result to a file, you can use the save method:

Saving the result

client.save(merged_pdf_content, "path/to/merged.pdf")

That's it! You've successfully merged three PDFs into a single one using the FastPDF API.

You can merge a maximum of 100 files at once, and the order of the files in the merged PDF will be the same as the order in the list you provide to the merge method.

Here's the complete code:

Merge PDFs

from fastpdf import PDFClient

client = PDFClient("your-api-key")

file_paths = ['path/to/first.pdf', 'path/to/second.pdf', 'path/to/third.pdf']
merged_pdf_content = client.merge(file_paths)

client.save("path/to/merged.pdf", merged_pdf_content)