pdfrw
pdfrw copied to clipboard
How to add a blank page to a PDF
I'm needing to take a file and add a blank page from scratch that's the same size as the rest of the pages in the file. What's the right way to go about doing this?
Same issue.
Just in case someone still has the issue (arrived here myself looking for the answer):
from pdfrw import PdfDict, PdfReader, PdfWriter
def blankPage(template):
x = PdfDict()
x.Type = PdfName.Page
x.Contents = PdfDict(stream="")
x.MediaBox = template.inheritable.MediaBox
return x
writer = PdfWriter("book.pdf")
pages = PdfReader(base_pdf).pages
writer.addPage(blankPage(pages[0]))
writer.write()
The arg template is an existing page from which you want to copy the dimension ; Alternatively if you already know the dimension in points, MediaBox has this shape: [0, 0, 612.00000, 612.00000] (with 612 pt = 8.5 in)
@gvellut you forgot to import PdfName.