Merging PDF files
caution
Services need to be mocked within the context of (automated) testing.
Merging PDF files can be done using the merge_pdf_files
function:
from pathlib import Path
import viktor as vkt
# using File object
file1 = vkt.File.from_path(Path(__file__).parent / "pdf1.pdf")
file2 = vkt.File.from_path(Path(__file__).parent / "pdf2.pdf")
with file1.open_binary() as f1, file2.open_binary() as f2:
merged_pdf = vkt.merge_pdf_files(f1, f2)
# using built-in `open()`
with open(Path(__file__).parent / "pdf1.pdf", "rb") as f1, open(Path(__file__).parent / "pdf2.pdf", "rb") as f2:
merged_pdf = vkt.merge_pdf_files(f1, f2)