Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for "write() missing 1 required positional argument: 'fileobj'" and "No module named pypdf" in basic_merging.py #98

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions samplecode/basic_merging.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from os.path import abspath, dirname, join
from sys import argv, path

from pypdf import PdfFileMerger, PdfFileReader
from PyPDF4 import PdfFileMerger, PdfFileReader

SAMPLE_CODE_ROOT = dirname(__file__)
SAMPLE_PDF_ROOT = join(SAMPLE_CODE_ROOT, "pdfsamples")
Expand Down Expand Up @@ -44,7 +44,8 @@ def main():
output = argv[4].strip()

reader1 = PdfFileReader(files[0])
merger = PdfFileMerger(open(output, "wb"))
merger = PdfFileMerger()
output_file = open(output, "wb")

if reader1.numPages < requiredPages:
print(
Expand All @@ -67,7 +68,7 @@ def main():
# Append entire input3 document to the end of the output document
merger.append(input3)

merger.write()
merger.write(output_file)
print("Output successfully written to", output)

merger.close()
Expand Down