2
votes

Hmm, spending a couple of days trying to get the PDF annotations on my iPad application. I'm using the following code to get the annotations, and yes! it works :) But the rect value is completely different then the IOS rect values. I can't figure it out how to place UIButtons on the spot where the annotation supposed to be. For example, i have an annotation in the top left corner of the pdf file.

My /Annots/Rect values are, 1208.93, 2266.28, 1232.93, 2290.28 (WHAT?!)

How can i translate the PDF /Annots /Rect values to iOS x an y coordinates?

CGPDFPageRef page = CGPDFDocumentGetPage(doc, i+1);

CGPDFDictionaryRef pageDictionary = CGPDFPageGetDictionary(page);

CGPDFArrayRef outputArray;
if(!CGPDFDictionaryGetArray(pageDictionary, "Annots", &outputArray)) {
    return;
.... .... ....}
2
did you find a solution ? I'd LOVE to know what you did as I need to do the same thingEarlGrey
which one are u using ?i meant which framework and how did you make this work?Lithu T.V

2 Answers

1
votes

I think those coordinates are in the "default user coordinate space" of the PDF. You need to apply a transformation that sends them into screen coordinates. You can use CGPDFPageGetDrawingTransform to get such a transformation. Make sure you're using the same transformation for drawing the page and the annotations.

0
votes

I am not sure if this is the problem but the Quartz 2D Coordinate Systems begins at the bottom left.

See Quartz 2D Programming Guide's Coordinate Systems for more information.

Ps. If you got it working, I would like to see the result code for annotating.

EDIT:

Just found this code (not tested):

// flip context so page is right way up
CGContextTranslateCTM(currentContext, 0, paperSize.size.height);
CGContextScaleCTM(currentContext, 1.0, -1.0); 

Source