Giter VIP home page Giter VIP logo

Comments (6)

JorjMcKie avatar JorjMcKie commented on July 22, 2024

Please provide a reproducing example.
So far your post leads to nothing actionable.

from pymupdf.

Flint-company avatar Flint-company commented on July 22, 2024

Please provide a reproducing example. So far your post leads to nothing actionable.

Hard to do since it's a resume of an existing person and personal data... You have a way to workaround this to provide the example ?

from pymupdf.

JorjMcKie avatar JorjMcKie commented on July 22, 2024

from pymupdf.

JorjMcKie avatar JorjMcKie commented on July 22, 2024

The example PDF shared with me violates the specifications for links / annotations:

image

Instead of giving indirect references as it should be, it provides all the links dirctly in the /Annots array.
IAW it should look like /Annots [4711 0 R 4712 0 R ...]. Instead we find:

/Annots [ <<
        /Type /Annot
        /Subtype /Link
        /Rect [ 248.31678 596.1143 279.57893 605.7143 ]
        /Border [ 0 0 0 ]
        /A <<
          /Type /Action
          /S /URI
          /URI (https://alexialabbe.fr/#projects)
        >>
      >> <<
        /Type /Annot
        /Subtype /Link
        /Rect [ 238.40349 71.17554 260.10389 80.775539 ]
        /Border [ 0 0 0 ]
        /A <<
          /Type /Action
          /S /URI
          /URI (https://blog.codein.fr/guide-rgpd-les-pratiques-essentielles-pour-assurer-la-conformite-de-votre-site-web)
        >>
      >> 
... ]

So pymupdf does recognize the links, but cannot assign an xref to them (xref=0 consequently).
You cannot update / delete links in PyMuPDF using the normal API (delete_link etc.) in such a situation - no way.
But you can edit the page's object definition source using low-level API and kill everything: for this you could delete the whole /Annots array.
This will remove everything (!!!): links, annotations and fields that may be on the page.

doc.xref_set_key(5, "Annots", "null")
            
print(doc.xref_object(5))  # 5 = page xref
            
<<
  /Type /Page
  /Parent 1 0 R
  /MediaBox [ 0 0 540 780 ]
  /Contents 134 0 R
  /Resources <<
    /ExtGState <<
      /Alpha0 10 0 R
      /Alpha1 11 0 R
    >>
    /Font <<
      /Font4 14 0 R
      /Font11 21 0 R
      /Font12 22 0 R
      /Font5 15 0 R
    >>
  >>
  /Annots null
  /Group <<
    /S /Transparency
    /CS /DeviceRGB
  >>
>>

All links are gone!

from pymupdf.

JorjMcKie avatar JorjMcKie commented on July 22, 2024

BTW the example page looks exactly the same, but all hot areas are gone.
Also, the file size (when saving via ez_save()) goes down to 44KB (was 1 MB before).

from pymupdf.

Flint-company avatar Flint-company commented on July 22, 2024

Thanks Jorj !!

from pymupdf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.