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#FDFBecause 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#a6da304d82307150a5eff1b596e3b9c73You 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/SetAppearanceYou 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.