PDF annotations and highlights in WebViewer & PDFNet

Q:

I am doing some investigation on using PDFTron WebViewer with Cordova. And for our needs we need to support search highlights(search done on server) and annotations. But we are not able to use xfdf format for highlights and annotations. The format we use is regular xml:

I am able to build highlights(annotations) on this data. But when it comes to annotations here are some problems with getting positions of selection in the text(pos property from xml). Is there a way to get selection position in the text not quads and other stuff that is generated for annotations.

So my questions are following:

  1. Is there a method to load search results and annotations not in xfdf but in xml I provided?

  2. Is there a way to get selection position in text?

  3. If we don’t what to load viewer in iframe we should modify MobileReaderControl our self?


A:

It looks like you are using deprecated Adobe highlights format. The issue with this format (and the reason it is no longer supported) is that it is hard-coded to a specific content stream (for char offsets), or even worse, to a specific text extraction algorithm (for word offsets; this one is especially bad since PDF text extraction algorithms are completely undocumented).

One way you could convert from Adobe highlight XML format to XFDF is via “pdftron.PDF.Highlights.Load(“my.xml”)” –

http://www.pdftron.com/pdfnet/docs/PDFNetC/dc/d85/classpdftron_1_1_p_d_f_1_1_highlights.html

PDFNet will give you corresponding quads or you cab load Highlights into PDFViewCtrl (then extract selection via PDFViewCtrl.GetSelection). You can use quads to create Highlight annotations that you can export to XFDF.

If we don’t what to load viewer in iframe we should modify MobileReaderControl our self?

By default the mobile viewer will redirect and not be displayed in an iframe. If you don’t want the viewer to redirect then you can set the mobileRedirect: false option in the PDFTron.WebViewer constructor, but if you don’t want it to be in an iframe you can just not specify that option.