Q: We are using PDFNet iOS SDK and have a few questions:
We have a few queries regarding highlight implementation and UI customization
- UI Customization:
In the PDFViewCtrl sample code, you have a single pdf view with two scroll views and Safari style PDF page scroll. We need to animate page navigation using UIPageViewController. We also need to support landscape mode i.e. show two pages in the page view controller like the iBooks app and the page view controller needs to be inside a scrollview for zooming. Does your SDK support a optimized single PDF page view which can be added to a custom view hierarchy or do we need to write code to render the PDFNet Page objects ourselves?
- Highlighted text:
We need a little more control over how highlight works. Currently the sample code stores highlights as per PDF specification i.e. as a Markup annotation with Subtype as Highlight and corresponding QuadPoints array. In addition to these, we need to fetch highlighted text for our records. One way of doing this could be to use what is used for copying the text but since code for the Tools is not exposed in the trial version, we want to make sure this is possible.
- Highlight text glitch in Mac Preview:
We found that a highlight save through the sample code does not show up correctly in Mac Preview. It looks correct in Adobe X Pro. I have attached screenshots of both of these scenarios.
I cannot find any iOS specific documentation for PDFViewCtrl or any objective c classes in PDFNetOBJC. I am currently referring to the C documentation which is pretty good, but please let me know if you have any iOS specific references.
I am now trying to add annotations to the pdf page. Can you give me any pointer for creating annotations and add them programmatically, without user interaction.
We specifically need to add some rubber stamp annotations with an image icon instead of default stamp text to specific pages. I found a reference (https://groups.google.com/forum/?fromgroups=#!topic/pdfnet-sdk/kYSFVCEHQPw) but it is not objective c code and i would have to tailor it for iOS.
- Let us know whether the default text selection a part of the PDFNet library or the Tool library because we would like to modify it a bit for our app. If it is a PDFNet implementation let us know whether it can be modified.
) PDFViewCtrl implements a single page mode, which I believe you can use for your purposes. (This mode is a available as an option in the sample app.) You may need to use more than one PDFViewCtrl if you plan to turn pages with two side by side, or come up with a system for moving the PDFViewCtrl to the page that a user is currently interacting with and leave the other purely as an image. (This could be done either by grabbing PDFViewCtrl’s appearance as a bitmap, or rendering pages separately using the PDFDraw class). With the demo version of the SDK you should be able to prototype the page turning behaviour, and if you have any questions about PDFViewCtrl during this process please let me know.
- Getting the highlighted text is certainly possible, and the easiest way is to use the TextExtractor class. The following snippet shows how to get the text under any annotation:
TextExtractor* te = [[[TextExtractor alloc] init] autorelease];
Page* pg = [[m_pdfViewCtrl GetDoc] GetPage:m_my_annot_page_number];
[te Begin:pg clip_ptr:0 flags:e_no_ligature_exp];
NSString* text = [te GetTextUnderAnnot:m_my_annot];
NSLog(@“Text is %@”, text);
- This highlight rendering glitch / crossed selection bug is due to a bug in Preview and Acrobat. Adobe implemented this functionality counter to the spec, however they seem to keep the old behavior for legacy reasons. Apple seems to have the same bug in Preview.
According to ISO 32000 spec the Quads array of a text markup annotation is supposed to use the following vertex ordering:
Acrobat and Preview use the following convention:
which is not compliant. If you would like to follow the Acrobat/Preview convention, you can switch the order of the last two quad points as shown in the figure above. This can be easily done by modifying the tools code that creates the annotation.
We don’t yet have any Objective-C documentation, but hopefully the methods are easy to find with using XCode’s code completion and the C++ documentation. All of our documentation can be found online here: http://www.pdftron.com/pdfnet/documentation.html
Sample code in Obj-C can be found here: http://www.pdftron.com/pdfnet/samplecode.html You will be most interested in the “Stamper” example code.
The UI part of text selection is implemented in tools. The tools code is responsible for determining the page and selection coordinates, and then uses the text selection selectors from PDFViewCtrl to acquire the string that is selected and where to draw the selection rectangles. (Such as SelectX1:Y1:PageNumber1:X2:Y2:PageNumber2. and GetSelection.) Please let me know if any clarification on the separation of responsibilities between the tools and PDFViewCtrl for text selection would be useful.
You can reduce the amount of memory that PDFViewCtrl consumes by setting PDFViewCtrl SetContentBufferSize to zero. Regarding your other questions: