-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pagedest (addlink) not working as intended with positional parameters . #1453
Comments
@chukuwa-isobe, |
Dear pubpub-zz, Upload in.pdf and out.pdf. from PyPDF2 import PdfFileWriter, PdfFileReader
from PyPDF2.generic import RectangleObject
inFile = r"xxxxxxxxxxxxxxxx\in.pdf"
outFile = r"xxxxxxxxxxxxxxxx\out.pdf"
pdf_writer = PdfFileWriter()
pdf_reader = PdfFileReader(open(inFile, "rb"))
num_of_pages = pdf_reader.getNumPages()
for page in range(num_of_pages):
current_page = pdf_reader.getPage(page)
pdf_writer.addPage(current_page)
pdf_writer.addLink(0, 1, [57, 721, 186, 731], [1, 1, 1], "/XYZ", 0, 0, 0) # 1st BOX
pdf_writer.addLink(
pagenum=0,
pagedest=1,
rect=RectangleObject([98, 708, 130, 718]),
border=[1, 1, 1],
fit="/XYZ",
) # 2nd BOX
with open(outFile, "wb") as o:
pdf_writer.write(o) Is it not a good way to write? |
Is there any progress on this? When I try to run the "Add Link" example(s) from the documentation they don't work either... |
Is this a feature that has been removed from PdfWriter? |
To follow PEP8, lots of names have been changed - in this case, For the link-specific annotations, see https://pypdf.readthedocs.io/en/stable/user/adding-pdf-annotations.html#link |
@stefan6419846 Thank you very much. I will check it out. |
I have confirmed that it still occurs.
|
IndirectObject should be specified, but a page number was specified. It seems that page numbers are specified only for remote pages. Wrong: /Dest [ 1 /XYZ 0.0 0.0 0.0 ] Below is an excerpt from the PDF 1.7 specification.
|
It seems to be necessary to reference the IndirectObject of the page and set it when add_annotation is executed, but I think it would be difficult to make adjustments unless the reference to the IndirectObject is determined at write time, instead of being determined there. I haven't read the code in much detail, so if I were to implement it, it would be quite a bit later. I am hoping someone will implement this. |
If I create a link with positional, it jumps to an unintended page.
Environment
$ python -m platform Windows-10-10.0 $ python -c "import PyPDF2;print(PyPDF2.__version__)" 2.10.7
Code + PDF
I want to use the "fit" option, so I write it positional.
Then when I click the link it jumps from page 1 to page "3".
When I open the link properties with Acrobat, the link destination is set to page "2", and after closing the properties with OK without updating anything, clicking the link again correctly jumps to page "2".
It's hard to open the properties of all created links and click OK, so please give me an idea how to solve it.
Traceback
This is the complete Traceback I see:
TODO
The text was updated successfully, but these errors were encountered: