I'd like to add a text/string at a specific position to each page to an existing PDFs (multiple pages) in "PDF/A-1b" standard.
I've read the documentation but I can't work it out (probably do not understand it enough so far) how to use streams and how to create the XObject.
Is there a small working example how to add a new string?
It can be an overlay, can be just another content element.
This one doesn't work, since I just created a pikepdf string object, no XObject, which leads to:
TypeError: other object is not something we can convert to Form XObject
import pikepdf
file_name ="example.pdf"
print(f"Current file: {file_name}")
pdf = pikepdf.Pdf.open(file_dict[each_pdf]["path"])
print("Number of pages:", len(pdf.pages))
some_text = pikepdf.objects.String('Some date like 20220629')
destination_page = pikepdf.Page(pdf.pages[0])
destination_page.add_overlay(some_text, pikepdf.Rectangle(0, 0, 300, 300))
pdf.save("example_with_text.pdf")
pdf.close()
Ok, got it. I've read about a way to 'stamp' the same object to all pages - couldn't find it again.
This solution fits my problem:
Wasn't me though, it's just a small adaption of an example from jbarlow83 himself.
If there're ways to improve it, please let me know.