_Please provide all mandatory information!_
I use Page.showPDFpage copy page from another pdf,but new page display not same with old page from a special pdf document. Maybe it's page size is too large (width: 42cm height:29.7cm)
old_pdf = fitz.open('./temp/old.pdf')
new_pdf = fitz.open()
for old_page in old_pdf.pages():
new_page = new_pdf.newPage(
old_page.number,
old_page.rect.width,
old_page.rect.height
)
new_page.showPDFpage(old_page.rect, old_pdf, old_page.number)
new_pdf.save('new.pdf')
other pdf not found this problem


For example, the output of print(sys.version, "\n", sys.platform, "\n", fitz.__doc__) would be sufficient (for the first two bullets).
3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)]
win32
PyMuPDF 1.18.3: Python bindings for the MuPDF 1.18.0 library.
Version date: 2020-11-09 07:36:17.
Built for Python 3.7 on win32 (64-bit).
Add any other context about the problem here.
The problem here is that the input page is _rotated_.
So you should either rotate new_page in the same way, or specify the rotation parameter in showPDFpage.
Presumably rotate=90 in this case.
You definitely must use showPDFpage(new_page.rect, ..., because the old one is rotated.
To be on the safe side:
This script works fine:
import fitz
src = fitz.open("old.pdf")
spage = src[0]
oldrot = spage.rotation
spage.setRotation(0)
doc = fitz.open()
npage = doc.newPage(width=spage.rect.width, height=spage.rect.height)
npage.showPDFpage(
npage.rect,
src,
0,
)
npage.setRotation(oldrot)
doc.save("new.pdf")
Yes your script works fine. it solve my problem,thank you very much! 馃憤
Most helpful comment
Yes your script works fine. it solve my problem,thank you very much! 馃憤