iphone – 如何使用CGPDF间接引用页面对象?

根据Adobe的“文档管理 – 可移植文档格式 – 第1部分:PDF 1.7”(
Pdf32000_2008.pdf),第12.3.2.1节规定:

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

例:

[page / XYZ left top zoom]

但在我的代码中

CGPDFArrayGetObject(dArray, 0, &dObj)

是一个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

如何从/ D [3 0 R / FitR -4 399 199 533]获得3 0 R?

如何间接引用页面对象,如[page / XYZ left top zoom]的页面对象?

这是我的代码:

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))
                                {

                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

非常感谢你重播〜但我有一个问题
我在哪里可以知道这个对象编号是3?

CGPDFArrayGetObject(dArray, 0, &dObj)

得到一个CGPDFDictionaryRef,但我没有找到字段是“3 0 R”

还有一个问题,如果我知道的是“3 0 R”

通过在PDF中搜索3 0 obj,我在哪里可以找到

谢谢你的回复,非常感谢你…我希望得到你的答案!

最佳答案 首先,您引用了PDF参考文档第136页表151中的错误示例,因为它与您的案例不符:

[page /XYZ left top zoom]

与您的案例相匹配的真实示例是:

[page /FitR left bottom right top]

含义:

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.

因为您的案例被引用为:

[3 0 R /FitR –4 399 199 533]

现在,该示例所指的是页面,在您的情况下变为3 0 R.后者是对象编号3(第0代)的引用,您可以通过在PDF中搜索3 0 obj来找到它.这是定义对象编号3的位置,该对象应指定您的目标所查找页面的名称.

更新:如果您的真实文档确实包含片段[3 0 R / FitR -4 399 199 533],则同一文档还应包含另一部分,该部分将页面对象(间接称为)定义为3 0 obj.这部分定义了页面对象,可以这样读取:

 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

注意,该对象如何再次引用其他三个对象:11 0 R,31 0 R和23 0 R.后两者指向对象31和23,它们保存页面的内容(31)和资源(23), FE字体,由它使用.第一个指向此页面的父对象(11).

注意2:对象的编号不需要按顺序显示在PDF文件中. (几乎)唯一的条件是编号是uniq.

点赞