-
Hi, I'm writing two scripts, one to insert in a PDF certain icons that when clicked open certain locations. The other script is to delete those icon/links I created. I managed to do this but my way looks hack-over-hack to me and just wanted to know if there is in general terms a better strategy, more time- proof. First thing is that I wanted the icons to be vectorial images that give a more professional look. So this seems to force me to go the Page.show_pdf_page() route. Now in the second, link-deletion script the only idea to identify my previously created icon was to use a fake OCG with a fabricated uuid in the name, created only for this purpose. I wonder if there is a better way (to draw a vector icon and delete it later in time). Then I had to dig for the fact that show_pdf_page() insert two xobjects, fish for the xref of the xobject by OCG name, and then try to delete the image. That is also not easy. I had to be in Sherlock mode to find the "img_replace()" method in PyMuPdf utilities separate repo, that does the trick in its way. Also for the links to work I need to create them with Page.insert_link() on top of the icons, but then I need again to be able to identify the links later. I can't recycle the OCG idea at least with high level API primitives. The workable solution ended being exploiting link IDs, (/NM pdf fields),(an undocumented link field, as opposed to say "kind"), and resort to fitz.TOOLS.set_annot_stem(), in one corner of the docs/issue tracker, while facing that links are not annotations in the api but that link ids get written conforming annot_stem() anyway. So I'm open to suggestions of doing better, and if impossible then I can suggest improvements to documentation to make things easier. This all in a constructive spirit and while thanking also the developers for the project and also the responsiveness in bug fixing. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
The standard way to do this is indeed inserting a link. If I understand you correctly, your problem is how to remove such a link later, without leaving a visible trace - even when you have been creative in filling the link's from area with an image or vector drawing. If we so far are in sync: page.add_redact_annot(link["from"])
page.apply_redactions() This will remove the link, any image and any text in that area in one go! So given all of the above, there is no need for introducing Optional Content anywhere.
|
Beta Was this translation helpful? Give feedback.
The standard way to do this is indeed inserting a link.
The "from" key represents the area on the page where viewers react with a "hands" symbol to indicate the "hot area".
You can identify the link as being one of yours via the function
fitz.TOOLS.set_annot_stem()
, as you wrote. You can be as creative as you want with selecting that name prefix in order to make sure you will find your work later.The link's "from" area can cover whatever on the page: text, image, drawing ... or nothing.
So far so good.
If I understand you correctly, your problem is how to remove such a link later, without leaving a visible trace - even when you have been creative in filling the link's from area with an i…