diff --git a/PyPDF2/merger.py b/PyPDF2/merger.py index 27702add3..f15827632 100644 --- a/PyPDF2/merger.py +++ b/PyPDF2/merger.py @@ -65,9 +65,12 @@ class PdfFileMerger(object): :param bool strict: Determines whether user should be warned of all problems and also causes some correctable problems to be fatal. Defaults to ``True``. + :param bool overwriteWarnings: Determines whether to override Python's + ``warnings.py`` module with a custom implementation (defaults to + ``True``). """ - def __init__(self, strict=True): + def __init__(self, strict=True, overwriteWarnings=True): self.inputs = [] self.pages = [] self.output = PdfFileWriter() @@ -75,6 +78,7 @@ def __init__(self, strict=True): self.named_dests = [] self.id_count = 0 self.strict = strict + self.overwriteWarnings = overwriteWarnings def merge(self, position, fileobj, bookmark=None, pages=None, import_bookmarks=True): """ @@ -130,7 +134,7 @@ def merge(self, position, fileobj, bookmark=None, pages=None, import_bookmarks=T # Create a new PdfFileReader instance using the stream # (either file or BytesIO or StringIO) created above - pdfr = PdfFileReader(fileobj, strict=self.strict) + pdfr = PdfFileReader(fileobj, strict=self.strict, overwriteWarnings=self.overwriteWarnings) if decryption_key is not None: pdfr._decryption_key = decryption_key diff --git a/PyPDF2/pdf.py b/PyPDF2/pdf.py index 6de140145..2ad522de0 100644 --- a/PyPDF2/pdf.py +++ b/PyPDF2/pdf.py @@ -250,17 +250,17 @@ def addAttachment(self, fname, fdata): :param str fname: The filename to display. :param str fdata: The data in the file. - + Reference: https://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/PDF32000_2008.pdf Section 7.11.3 """ - + # We need 3 entries: # * The file's data # * The /Filespec entry # * The file's name, which goes in the Catalog - + # The entry for the file """ Sample: @@ -272,7 +272,7 @@ def addAttachment(self, fname, fdata): stream Hello world! endstream - endobj + endobj """ file_entry = DecodedStreamObject() file_entry.setData(fdata) @@ -291,14 +291,14 @@ def addAttachment(self, fname, fdata): """ efEntry = DictionaryObject() efEntry.update({ NameObject("/F"):file_entry }) - + filespec = DictionaryObject() filespec.update({ NameObject("/Type"): NameObject("/Filespec"), NameObject("/F"): createStringObject(fname), # Perhaps also try TextStringObject NameObject("/EF"): efEntry }) - + # Then create the entry for the root, as it needs a reference to the Filespec """ Sample: 1 0 obj @@ -309,13 +309,13 @@ def addAttachment(self, fname, fdata): /Names << /EmbeddedFiles << /Names [(hello.txt) 7 0 R] >> >> >> endobj - + """ embeddedFilesNamesDictionary = DictionaryObject() embeddedFilesNamesDictionary.update({ NameObject("/Names"): ArrayObject([createStringObject(fname), filespec]) }) - + embeddedFilesDictionary = DictionaryObject() embeddedFilesDictionary.update({ NameObject("/EmbeddedFiles"): embeddedFilesNamesDictionary @@ -329,7 +329,7 @@ def appendPagesFromReader(self, reader, after_page_append=None): """ Copy pages from reader to writer. Includes an optional callback parameter which is invoked after pages are appended to the writer. - + :param reader: a PdfFileReader object from which to copy page annotations to this writer object. The writer's annots will then be updated @@ -373,7 +373,7 @@ def updatePageFormFieldValues(self, page, fields): def cloneReaderDocumentRoot(self, reader): ''' Copy the reader document root to the writer. - + :param reader: PdfFileReader from the document root should be copied. :callback after_page_append '''