Skip to main content

Merging PDF files


Services need to be mocked within the context of (automated) testing.

Merging PDF files can be done using the merge_pdf_files function:

from viktor.utils import merge_pdf_files# using File objectfile1 = File.from_path(Path(__file__).parent / "pdf1.pdf")file2 = File.from_path(Path(__file__).parent / "pdf2.pdf")with file1.open_binary() as f1, file2.open_binary() as f2:    merged_pdf = 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 = merge_pdf_files(f1, f2)