Creating, customizing, and sharing text highlights and interactive annotations

618 views
Skip to first unread message

Aaron Gravesdale

unread,
Dec 11, 2013, 6:26:37 PM12/11/13
to

Q:

We are currently developing an application that reads PDF and provides annotations on top of it.

We would like to know whether it would be possible to do the following using your kit:
1. User can highlight text using his finger like he would in any regular text. See example below:
2. Extract the highlighted text to external resource (i.e. save the extracted text in an external file).
3. Get the position of the highlighted text.
4. Add a note icon beside that highlighted text.
5. Make the highlighted text interactive - i.e. when clicking on it, I will be able to open an overlay layer.
6. Provided that we extracted the highlighted text, we would like to display that annotation to another user using our app. Using your kit, I would like to be able to programmatically highlight that text and be able to hook to an event when it is clicked on.




A:

PDFNet should be able to handle all the mentioned requirements.

In general, sharing annotation data between documents with PDFNet is best performed through the XFDF file format as described in the following article:

http://blog.pdftron.com/2013/07/19/document-collaboration-with-pdfnet/

This XFDF format works across all PDFNet platforms, as well as Acrobat.  Additional sample code showing the basics of importing and exporting annotations with XFDF is available at:

http://www.pdftron.com/pdfnet/samplecode.html#FDF

Because PDFNet already provides a file format for moving annotations between documents, some of your other requirements may be unnecessary --- e.g., you probably want to avoid extracting text into your own file format, if you can simply store the annotation inside the XFDF instead.  That said, PDFNet does provide support for each of the individual requirements you list.

Specifically:

> User can highlight text using his finger like he would in any regular text.

PDFNet mobile platforms support highlight annotations out-of-the-box. We provide source code to implement all annotation tools (including text highlighting) and you are free to modify the code as required. To highlight text in the demo viewer, first select the text, then tap on the selection. A pop-up menu will appear where you can select the "highlight" option.

> Get the position of the highlighted text.

Given a user's selection of a highlight annotation at a specific coordinate, you can get its bounding box with
PDFViewCtrl.getAnnotationAt().GetRect().  Also, during text selection, you can obtain the position of the selected
region with PDFViewCtrl.GetSelection():

http://www.pdftron.com/pdfnet/PDFNetC/da/dca/classpdftron_1_1_p_d_f_1_1_p_d_f_view_ctrl.html#ab488d24749f7b0cba7dff0e2aba4c20c

> Extract the highlighted text to external resource (i.e. save the
extracted text in an external file).

Probably the simplest option is to use XFDF (as described above), however you can serialize the information in an alternate representation. For example, you can obtain text under highlight using TextExtractor.GetTextUnderAnnot(annot):

http://www.pdftron.com/pdfnet/PDFNetC/d3/d88/classpdftron_1_1_p_d_f_1_1_text_extractor.html#a6da304d82307150a5eff1b596e3b9c73

You can also extract full text from the page (including positioning information) as shown in TextExtract sample at:

http://www.pdftron.com/pdfnet/samplecode.html#TextExtract

> Add a note icon beside that highlighted text.

If you wish to use a custom icon, you will need to set the annotation's appearance stream, which could in your case be an image. For an example of how to set an annotation's appearance stream, please see: 

https://groups.google.com/forum/#!searchin/pdfnet-sdk/SetAppearance

You can also associate a pop-up annotation with a highlight (or any other markup annotation) with markup_annot.SetPopup():

http://www.pdftron.com/pdfnet/PDFNetC/de/d19/classpdftron_1_1_p_d_f_1_1_annots_1_1_markup.html#abf0ace1e6d2b053958aa3f7ebdf3c72a

> I would like to be able to programmatically highlight that text and be able to hook to an event when it is clicked on.

Because we provide source code for all Tools and GUI elements you are free to tweak code, hook-in custom events, and make other customizations.


Support

unread,
Dec 11, 2013, 6:28:10 PM12/11/13
to pdfne...@googlegroups.com

Q:


Thanks for the detailed explanation!

I do have a few more questions:

  1. Do you support search within PDF?
  2. If so, do you highlight the results? Is there a customizable search results form?
  3. Do you support all encodings including Hebrew and Arabic?
  4. Do you support right to left PDF documents?

----------
A:  

>  Do you support search within PDF?

Yes. To get started, please see FindText() method in PDFViewCtrl (http://www.pdftron.com/pdfnet/mobile/iOSHTMLDoc/src/interface_p_d_f_view_ctrl.html, http://www.pdftron.com/pdfnet/mobile/Javadoc/pdftron/PDF/PDFViewCtrl.html).


There is also a more low-level class ‘pdftron.PDF.TextSearch’ that can be used to search PDF based on regular expressions. The search results include positioning information, ambient strings, etc. For an example of how to use TextSearch see http://www.pdftron.com/pdfnet/samplecode.html#TextSearch.


Another relevant class is 'pdftron.PDF.TextExtractor'  (http://www.pdftron.com/pdfnet/samplecode.html#TextExtract) which can provide positioning info for each glyph, word, line, block etc.



> If so, do you highlight the results? Is there a customizable search results form?


PDFViewCtrl.FindText() automatically highlights results. You can also use TextSearch to make a custom search form.


> Do you support all encodings including Hebrew and Arabic?


Yes, we support all Unicode including Hebrew and Arabic.


> Do you support right to left PDF documents?


Yes, you would need to call PDFViewCtrl.SetRightToLeftLanguage(true) to switch text selection to right to left mode.

Reply all
Reply to author
Forward
0 new messages