Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Thanks to Omz, here is a piece of code to retreive a page number for an outline destination in a PDF file :</p> <pre><code>// Get Page Number from an array - (int) getPageNumberFromArray:(CGPDFArrayRef)array ofPdfDoc:(CGPDFDocumentRef)pdfDoc withNumberOfPages:(int)numberOfPages { int pageNumber = -1; // Page number reference is the first element of array (el 0) CGPDFDictionaryRef pageDic; CGPDFArrayGetDictionary(array, 0, &amp;pageDic); // page searching for (int p=1; p&lt;=numberOfPages; p++) { CGPDFPageRef page = CGPDFDocumentGetPage(pdfDoc, p); if (CGPDFPageGetDictionary(page) == pageDic) { pageNumber = p; break; } } return pageNumber; } // Get page number from an outline. Only support "Dest" and "A" entries - (int) getPageNumber:(CGPDFDictionaryRef)node ofPdfDoc:(CGPDFDocumentRef)pdfDoc withNumberOfPages:(int)numberOfPages { int pageNumber = -1; CGPDFArrayRef destArray; CGPDFDictionaryRef dicoActions; if(CGPDFDictionaryGetArray(node, "Dest", &amp;destArray)) { pageNumber = [self getPageNumberFromArray:destArray ofPdfDoc:pdfDoc withNumberOfPages:numberOfPages]; } else if(CGPDFDictionaryGetDictionary(node, "A", &amp;dicoActions)) { const char * typeOfActionConstChar; CGPDFDictionaryGetName(dicoActions, "S", &amp;typeOfActionConstChar); NSString * typeOfAction = [NSString stringWithUTF8String:typeOfActionConstChar]; if([typeOfAction isEqualToString:@"GoTo"]) // only support "GoTo" entry. See PDF spec p653 { CGPDFArrayRef dArray; if(CGPDFDictionaryGetArray(dicoActions, "D", &amp;dArray)) { pageNumber = [self getPageNumberFromArray:dArray ofPdfDoc:pdfDoc withNumberOfPages:numberOfPages]; } } } return pageNumber; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload