Skip to content

Commit

Permalink
Remove mentions of "HPA Design" and update metadata (#58)
Browse files Browse the repository at this point in the history
* FIX metadata added in encrypt.py

* FIX metadata added in merge.py

* ADD encrypt test method that confirms metadata was added correctly

* FIX metadata adding to merge.py

* ADD metadata assertions to merge test
  • Loading branch information
sfneal authored Jul 1, 2024
1 parent 11f83eb commit db60e1b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
4 changes: 2 additions & 2 deletions pdfconduit/conduit/encrypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions pdfconduit/transform/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,9 @@ 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='Stephen Neal',
Creator='pdfconduit',
Producer='pdfconduit',
)
writer.write(output)
return output
17 changes: 17 additions & 0 deletions tests/test_conduit_encrypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 10 additions & 0 deletions tests/test_transform_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand All @@ -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()

0 comments on commit db60e1b

Please sign in to comment.