If you are open to other options then you can use Aspose.PDF Cloud SDK for Python to append/merge PDF documents without creating a new empty PDF file. Currently, the API process files from cloud storage(Amazon S3, DropBox, Google Drive Storage, Google Cloud Storage, Windows Azure Storage, FTP Storage and Aspose Cloud Storage). However, in the future, we have a plan to support the request body(stream).
import os
import asposepdfcloud
from asposepdfcloud.apis.pdf_api import PdfApi
from shutil import copyfile
# Get Client ID and Secret from https://cloud.aspose.com
pdf_api_client = asposepdfcloud.api_client.ApiClient(
ClientSecret='xxxxxxxxxxxxxxxxxxxxx',
ClientId='xxxx-xxxx-xxxx-xxxx-xxxxxxxx')
pdf_api = PdfApi(pdf_api_client)
file_name_list = ['4pages.pdf', '02_pages.pdf', 'Sample.pdf']
for file_name in file_name_list:
pdf_api.upload_file(file_name,file_name)
result_name = 'MergingResult.pdf'
i = 0
for el in file_name_list:
file_name_list[i] = el
i += 1
merge_documents = asposepdfcloud.models.MergeDocuments(file_name_list)
opts = {
"merge_documents" : merge_documents
}
response = pdf_api.put_merge_documents(result_name, **opts)
#download PDF file from storage
response_download = pdf_api.download_file(result_name)
copyfile(response_download, result_name)
print(response_download)
P.S: I'm a developer evangelist at Aspose.