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

Remove mentions of "HPA Design" and update metadata #58

Merged
merged 5 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
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
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()