Skip to content

Commit

Permalink
Merge pull request #25 from takis/issue23
Browse files Browse the repository at this point in the history
Add an example creating a PDF with metadata, #23
  • Loading branch information
grewn0uille authored Feb 16, 2024
2 parents 322a602 + f76c97e commit e1468d4
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions docs/common_use_cases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,37 @@ Display text
with open('document.pdf', 'wb') as f:
document.write(f)
Add metadata
------------

.. code-block:: python
import datetime
import pydyf
document = pydyf.PDF()
document.info["Author"] = pydyf.String("Jane Doe")
document.info["Creator"] = pydyf.String("pydyf")
document.info["Keywords"] = pydyf.String("some keywords")
document.info["Producer"] = pydyf.String("The producer")
document.info["Subject"] = pydyf.String("An example PDF")
document.info["Title"] = pydyf.String("A PDF containing metadata")
now = datetime.datetime.now()
document.info["CreationDate"] = pydyf.String(now.strftime("D:%Y%m%d%H%M%S"))
document.add_page(
pydyf.Dictionary(
{
"Type": "/Page",
"Parent": document.pages.reference,
"MediaBox": pydyf.Array([0, 0, 200, 200]),
}
)
)
# 550 bytes PDF
with open("metadata.pdf", "wb") as f:
document.write(f)

0 comments on commit e1468d4

Please sign in to comment.