wojtekmaj / react-pdf

Display PDFs in your React app as easily as if they were images.
https://projects.wojtekmaj.pl/react-pdf
MIT License
9.51k stars 892 forks source link

pdfInfo.structureTree is missing #1466

Closed BennyAlex closed 1 year ago

BennyAlex commented 1 year ago

Before you start - checklist

Description

hello, I am relaying on the structure property of _pdfInfo when the onLoadSuccess callback is called:

  const onDocumentLoadSuccess = useCallback(
    async (data) => {
      console.log('onDocumentLoadSuccess', data);
      setStructureTree(data._pdfInfo.structureTree);
      setLoaded(true);
    },
    [props.onLoadSuccess, bboxes]
  );

In older versions this was working fine, now the property isn't there any more.

There is nothing written about this change in the changelogs. Is there another way of accessing this information in the latest version?

Its still in a beta version of 6.0. I also want to use vite, so I need a newer version.

Steps to reproduce

looking at the data thats comming onLoadSuccess.

Expected behavior

Have the structure available, or another way of accessing it, thats documented in the changelogs

Actual behavior

Prop is silently gone.

Additional information

No response

Environment

wojtekmaj commented 1 year ago

_pdfInfo is an internal, undocumented object that is a subject to change even between minor versions, so I would advise not to rely on that.

BennyAlex commented 1 year ago

@wojtekmaj Yeah I see, unfortunatelly I am using verapdf-js-viewer to show bounding boxes of errors. I am trying to fix their project currently, since its using a beta v6 version and thus not compatible with vite...

Is there no way of adding it back or is there an official way of getting the structureTree? Cant find anything for this.

wojtekmaj commented 1 year ago

I'm not really familiar with structureTree, but I can see that page has a getStructTree method, maybe that would help?

BennyAlex commented 1 year ago

I cant get it to work. Is it hard to add this back? Or make the tree available as normal prop for onDocumentLoadSuccess ?

wojtekmaj commented 1 year ago

_pdfInfo is a private field in a feedback provided by pdf.js library. You will need to ask them how are you supposed to get this information from PDFDocumentProxy / PDFPageProxy objects.

BennyAlex commented 1 year ago

They say, this libary modified it: https://github.com/mozilla/pdf.js/issues/16352

I think I get crazy soon, I am working really hard just to get this to work...