Skip to content

Commit

Permalink
Let PdfFileMerger open the files to be merged itself
Browse files Browse the repository at this point in the history
Before, the files were closed before actually being processed by PdfFileMerger
  • Loading branch information
magula authored Dec 26, 2020
1 parent 60a6ed9 commit c5935e0
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions cms/service/PrintingService.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"""

import contextlib
import cups
import logging
import os
Expand Down Expand Up @@ -189,14 +190,11 @@ def execute(self, entry):
"Failed to create title page with command: %s"
"(error %d)" % (pretty_print_cmdline(cmd), ret))

pdfmerger = PdfFileMerger()
with open(title_pdf, "rb") as file_:
pdfmerger.append(file_)
with open(source_pdf, "rb") as file_:
pdfmerger.append(file_)
result = os.path.join(directory, "document.pdf")
with open(result, "wb") as file_:
pdfmerger.write(file_)
with contextlib.closing(PdfFileMerger()) as pdfmerger:
pdfmerger.append(title_pdf)
pdfmerger.append(source_pdf)
result = os.path.join(directory, "document.pdf")
pdfmerger.write(result)

try:
printer_connection = cups.Connection()
Expand Down

0 comments on commit c5935e0

Please sign in to comment.