From f3872ad97be473eb109fbda4bc4f0cb67c3de165 Mon Sep 17 00:00:00 2001 From: sfneal Date: Mon, 1 Jul 2024 13:41:20 -0400 Subject: [PATCH 1/5] FIX metadata added in encrypt.py --- pdfconduit/conduit/encrypt.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pdfconduit/conduit/encrypt.py b/pdfconduit/conduit/encrypt.py index 86544ce7..f319ff8e 100644 --- a/pdfconduit/conduit/encrypt.py +++ b/pdfconduit/conduit/encrypt.py @@ -58,8 +58,8 @@ def encrypt(self, decrypt=None): # todo: add metadata adding functionality pdf_writer.addMetadata({ '/Producer': 'pdfconduit', - '/Creator': 'HPA Design', - '/Author': 'HPA Design', + '/Creator': 'pdfconduit', + '/Author': 'Stephen Neal', }) # Write encrypted PDF to file From 11cf3f78cd69f6b91b6568e3e2dac544bd7ba9e1 Mon Sep 17 00:00:00 2001 From: sfneal Date: Mon, 1 Jul 2024 13:42:28 -0400 Subject: [PATCH 2/5] FIX metadata added in merge.py --- pdfconduit/transform/merge.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pdfconduit/transform/merge.py b/pdfconduit/transform/merge.py index aa5e68fd..1ec76850 100644 --- a/pdfconduit/transform/merge.py +++ b/pdfconduit/transform/merge.py @@ -64,10 +64,8 @@ def pdfrw(pdf_files, output): writer.addpages(PdfReader(inpfn).pages) writer.trailer.Info = IndirectPdfDict( - Title='HPA Design', - Author='HPA Design', - Subject='HPA Design', - Creator='HPA Design', + Author='pdfconduit', + Creator='pdfconduit', ) writer.write(output) return output From fef7c42a2b4d26be38b04f9809dc5fe3d40ab666 Mon Sep 17 00:00:00 2001 From: sfneal Date: Mon, 1 Jul 2024 14:13:46 -0400 Subject: [PATCH 3/5] ADD encrypt test method that confirms metadata was added correctly --- tests/test_conduit_encrypt.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/test_conduit_encrypt.py b/tests/test_conduit_encrypt.py index 7f83ad9f..de62869b 100644 --- a/tests/test_conduit_encrypt.py +++ b/tests/test_conduit_encrypt.py @@ -189,6 +189,23 @@ def test_password_byte_string(self): b'\xd0H\xd1R\x9eS]\x18\x84\xcd8V6{\x18KJ\x90\xdf\x01\xe67\xd1n\xca\x06[\xafNd\x90\x0b' ) + @Timer.decorator + def test_encrypted_pdf_has_metadata(self): + encrypted = Encrypt(self.pdf_path, + self.user_pw, + self.owner_pw, + output=self.temp.name, + bit128=True, + suffix='metadata') + + self.assertPdfExists(encrypted) + self.assertEncrypted(encrypted) + + metadata = Info(encrypted.output, self.user_pw).metadata + self.assertEqual(metadata['/Producer'], 'pdfconduit') + self.assertEqual(metadata['/Creator'], 'pdfconduit') + self.assertEqual(metadata['/Author'], 'Stephen Neal') + def _getPdfSecurity(self, encrypted): return Info(encrypted.output, self.user_pw).security From d28bd0b9b6a21670adb63d5945a0df8796249c82 Mon Sep 17 00:00:00 2001 From: sfneal Date: Mon, 1 Jul 2024 14:17:31 -0400 Subject: [PATCH 4/5] FIX metadata adding to merge.py --- pdfconduit/transform/merge.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pdfconduit/transform/merge.py b/pdfconduit/transform/merge.py index 1ec76850..2a31fe9d 100644 --- a/pdfconduit/transform/merge.py +++ b/pdfconduit/transform/merge.py @@ -64,8 +64,9 @@ def pdfrw(pdf_files, output): writer.addpages(PdfReader(inpfn).pages) writer.trailer.Info = IndirectPdfDict( - Author='pdfconduit', + Author='Stephen Neal', Creator='pdfconduit', + Producer='pdfconduit', ) writer.write(output) return output From a8ef4aea95d0bf251199ee1e3ce5578772634742 Mon Sep 17 00:00:00 2001 From: sfneal Date: Mon, 1 Jul 2024 14:17:40 -0400 Subject: [PATCH 5/5] ADD metadata assertions to merge test --- tests/test_transform_merge.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/test_transform_merge.py b/tests/test_transform_merge.py index 5a3d681d..6dee2473 100644 --- a/tests/test_transform_merge.py +++ b/tests/test_transform_merge.py @@ -30,6 +30,10 @@ def test_merge_pypdf3(self): # Assert sum of pages in original pdf files equals sum of pages in merged pdf self.assertEqual(sum([Info(pdf).pages for pdf in self.pdfs]), Info(merged.file).pages) + # Assert metadata was added correctly + metadata = Info(merged.output).metadata + self.assertEqual(metadata['/Producer'], 'PyPDF3') + @Timer.decorator def test_merge_pdfrw(self): """Merge multiple PDF files into a single PDF using the `pdfrw` library.""" @@ -41,6 +45,12 @@ def test_merge_pdfrw(self): # Assert sum of pages in original pdf files equals sum of pages in merged pdf self.assertEqual(sum([Info(pdf).pages for pdf in self.pdfs]), Info(merged.file).pages) + # Assert metadata was added correctly + metadata = Info(merged.output).metadata + self.assertEqual(metadata['/Producer'], 'pdfconduit') + self.assertEqual(metadata['/Creator'], 'pdfconduit') + self.assertEqual(metadata['/Author'], 'Stephen Neal') + if __name__ == '__main__': unittest.main()