Some highlights are not shown

Hi,
I’m trying to highlight text calling PDFDoc.addHighlights and passing xml file with pdf highlights. For some reason some highlights are not shown. As far as I saw - usually it’s first n highlights are missed. For different documents that “n” number is different.

Is it trial version limitation or I do somth. wrong?

Hello, I’m Ron, an automated tech support bot :robot:

While you wait for one of our customer support representatives to get back to you, please check out some of these documentation pages:

Guides:APIs:Forums:

Hello,

Could you please provide us with the code you are using, along with the PDF and the highlight file so that we can try to reproduce the issue on our end?

Thank you in advance for the additional information.

Hi,
Code is very simple -

instance.docViewer.getDocument().getPDFDoc()
.then( (doc) => { doc.addHighlights( hlString ) } )

where hlString it’s a string with xml.

I can’t upload files here, it says “new user can’t upload files”.
I shared it via wetransfer.com - https://we.tl/t-d9lZ8oHm09
Please let me know if this share doesn’t work for you.

For this example WebViewer doesn’t show highlights on the first page (pg=0), but shows all other ones.

BTW, I also tried same example in C# and it works well for all pages.

Could you please provide two screenshots, one showing what you see in WebViewer, and another screenshot clearly indicating what you expected to see. Please also provide the Highlights XML used for the screenshots.

I can answer Ryan’s question:

Could you please provide two screenshots, one showing what you see in WebViewer, and another screenshot clearly indicating what you expected to see. Please also provide the Highlights XML used for the screenshots.

I did some test using the following code:

const hlString = `<XML>
  <Body units=characters>
  <Highlight>
  <loc pg=0 pos=0 len=1>
  <loc pg=1 pos=0 len=1>
  <loc pg=2 pos=0 len=1>
  </Highlight>
  </Body>
  </XML>`

  docViewer.on('documentLoaded', async () => {
    docViewer.getDocument().getPDFDoc().then( (doc) => { doc.addHighlights( hlString ) } )
  });

with document 837488253.PDF (88.7 KB)


I am expecting to see the first character on page 1 got highlighted. But there is not.
image

Only the first character on page2 and 3 get highlighted.
image

I believe @aevtukh is testing with different hlString

const hlString2 = `<XML><Body units=characters color=#ff00ff mode=active version=2><Highlight><loc pg=0 pos=1577 len=6><loc pg=0 pos=1704 len=6><loc pg=0 pos=3109 len=6><loc pg=0 pos=4147 len=6><loc pg=0 pos=4440 len=6><loc pg=0 pos=4860 len=6><loc pg=1 pos=863 len=6><loc pg=2 pos=3949 len=6><loc pg=4 pos=1444 len=6><loc pg=4 pos=2265 len=6></Highlight></Body></XML>

Maybe @aevtukh you can add a screenshot clearly indicating what you expected to see.

My XML is

<XML>
                        <Body units=characters>
                            <Highlight>
                                <loc pg=0 pos=1577 len=6>
                                <loc pg=0 pos=1704 len=6>
                                <loc pg=0 pos=3109 len=6>
                                <loc pg=0 pos=4147 len=6>
                                <loc pg=0 pos=4440 len=6>
                                <loc pg=0 pos=4860 len=6>
                                <loc pg=1 pos=863 len=6>
                                <loc pg=2 pos=3949 len=6>
                                <loc pg=4 pos=1444 len=6>
                                <loc pg=4 pos=2265 len=6>
                            </Highlight>
                        </Body>
                    </XML>

It should highlight word “canada”, so expected result is:

but actual result is page without highlights. On pages 2,3 and 5 it’s ok.

Hi Alexander,

From you code

instance.docViewer.getDocument().getPDFDoc()
.then( (doc) => { doc.addHighlights( hlString ) } )

You are trying to add the highlights at the same time when loading the document. This will cause some race conditions (page 1 was not loaded when you add highlights), and I guess that’s why the highlight is not working on page 1. And this way may also cause other issues if you use other PDFs.

If you want to have this to work, you may need to use requirePage() to make sure that page are loaded before adding highlights. See: Apryse WebViewer Class: PDFDoc for more details.

The best practice is for the server (PDFTron SDK) to add the highlight to the document, and then load it using WebViewer.
For example:
Add a highlight annotation to a PDF in Python
Add a highlight annotation to a PDF in C++

1 Like