I need to make a pdf editor using PyPDF2. but sadly, there are around 4-6 videos around this module and they all show how to edit and manipulate the general screen, not the pdf. so i used the documentation on it's own in order to learn how to use it. i was able to do most stuff with the documentation alone, but once i reached the point of editing text, i couldn't find any way to do so.
here is my current try of editing a pdf's content:
import PyPDF2
pdf_file = open('pdf name goes here', 'rb')
pdf_reader = PyPDF2.PdfReader(pdf_file)
# Get the page that you want to modify
page = pdf_reader.pages[0]
content_object = page["/Contents"].get_object()
content = content_object.get_data()
modified_content = content + b"\n(new text)"
new_content_object = # i don't know how to create the new content object ):
page.__setitem__("/Contents", new_content_object)
pdf_writer = PyPDF2.PdfFileWriter()
pdf_writer.addPage(page)
with open('output.pdf', 'wb') as pdf_output:
pdf_writer.write(pdf_output)
as you can see, my issue is that i don't know how to create a new content object. however, if anybody could suggest me a python module to edit text, i would be very happy. thanks!