How to get indirect reference to a page object with CGPDF?
According to Adobe's "Document management - Portable Document Format - Part 1: PDF 1.7" (Pdf32000_2008.pdf), section 12.3.2.1 states:
A destination defines a particular view of a document, consisting of the following items:
The page of the document that shall be displayed
The location of the document window on that page
The magnification (zoom) factor
Example:
[page /XYZ left top zoom]
But in my code
CGPDFArrayGetObject(dArray, 0, &dObj)
is a CGPDFDictionaryRef
.
93 0 obj
<< /Type /Annot
/Subtype /Link
/Rect [71 717 190 734]
/Border [16 16 1]
/A << /Type /Action
/S /GoTo
/D [3 0 R /FitR –4 399 199 533]
>>
>>
endobj
How can I obtain 3 0 R
from /D [3 0 R /FitR –4 399 199 533]
?
How can I get an indirect reference to a page object like [page /XYZ left top zoom]
's page object?
Here is my code:
CGPDFPageRef pdfPage = CGPDFDocumentGetPage(pdfRef, pageNum);
CGPDFDictionaryRef pageDictionary = CGPDFPageGetDictionary(pdfPage);
CGPDFArrayRef outputArray;
if(CGPDFDictionaryGetArray(pageDictionary, "Annots", &outputArray))
{
int arrayCount = 0;
arrayCount = CGPDFArrayGetCount(outputArray );
if(arrayCount>0)
{
for( int j = 0; j < arrayCount; ++j )
{
CGPDFObjectRef aDictObj;
if(CGPDFArrayGetObject(outputArray, j, &aDictObj))
{
CGPDFDictionaryRef annotDict;
if(CGPDFObjectGetValue(aDictObj, kCGPDFObjectTypeDictionary, &annotDict))
{
CGPDFDictionaryRef aDict;
if(CGPDFDictionaryGetDictionary(annotDict, "A", &aDict))//page 1 returns here
{
CGPDFArrayRef dArray;
if(CGPDFDictionaryGetArray(aDict, "D", &dArray))
{
CGPDFObjectRef dObj;
if(CGPDFArrayGetObject(dArray, 0, &dObj)){
CGPDFDictionaryRef annotDict;
if(CGPDFObjectGetValue(dObj, kCGPDFObjectTypeDictionary, &annotDict))
{
}
}
}
}
}
开发者_JAVA技巧 }
}
}
}
thank you very much for you replay~ but i have a question where can I know this object number is 3?
CGPDFArrayGetObject(dArray, 0, &dObj)
get a CGPDFDictionaryRef, but I didn't find field is "3 0 R"
and another question, If I know is "3 0 R"
where can I find by searching your PDF for 3 0 obj
thank you reply, thank you very very very much ... I hope get your answer agian!
First, you're quoting the wrong example from table 151, page 366 of the PDF Reference document, because it doesn't match your case:
[page /XYZ left top zoom]
The real example which matches your case is:
[page /FitR left bottom right top]
meaning:
Display the page designated by page, with its contents magnified just enough to fit the rectangle specified by the coordinates left, bottom, right, and top entirely within the window both horizontally and vertically. If the required horizontal and vertical magnification factors are different, use the smaller of the two, centering the rectangle within the window in the other dimension.
because your case is quoted as:
[3 0 R /FitR –4 399 199 533]
Now, what the example refers to as page
, in your case becomes 3 0 R
. The latter is a reference to object number 3 (generation 0) which you can find by searching your PDF for 3 0 obj
. This is the place that defines object number 3, which should name what your looked-for page
for your destination is.
Update: If your real document indeed does contain the snippet [3 0 R /FitR –4 399 199 533]
, then the same document should also contain another part which defines the page object (indirectly referred to) as 3 0 obj
. This part defines the page object and could read like this:
3 0 obj
<< /Type /Page
/Parent 11 0 R
/MediaBox [ 0 0 597.6 842.4 ]
/Contents 31 0 R
/Group <<
/Type /Group
/S /Transparency
/CS /DeviceRGB
>>
/Resources 23 0 R
>>
endobj
Note, how this object again does refer to three other objects: 11 0 R
, 31 0 R
and 23 0 R
. The latter two point to objects 31 and 23, which hold the page's contents (31) and the resources (23), f.e. fonts, used by it. The first one points to the parent object (11) of this page.
Note 2: The numbering of objects does not need to be sequentially as objects appear in the PDF file. The (almost) only condition is that the numbering is uniq.
Alas, while the answers are leading, it is still not clear what we need. A code snippet that reveals the page number or name we have to jump to would do the trick.
Check the code in github in vfr/Reader. They appear to have figured all these links out. It sure isn't clear from the PDF doc what's going on.
精彩评论