下面的示例代码允许将大纲(或Acrobat术语中的“书签”)添加到现有的
PDF文档
pdfDoc
带标签
n
n
n
这个论点通过了吗
pageNum
void insertOutline( PDFDocument *pdfDoc, NSUInteger pageNum )
{
PDFOutline *otl,
*root;
NSString *label = [NSString stringWithFormat:@"Page %lu", (unsigned long)pageNum + 1];
PDFDestination *destination;
PDFAction *action;
NSPoint point = {FLT_MAX, FLT_MAX};
PDFPage *page;
// Build the outline
page = [pdfDoc pageAtIndex: pageNum];
destination = [[PDFDestination alloc] initWithPage:page atPoint:point];
action = [[PDFActionGoTo alloc] initWithDestination: destination];
root = [pdfDoc outlineRoot];
otl = [[PDFOutline alloc] init];
[otl setLabel: label];
[otl setAction: action];
// Insert the outline
[root insertChild: otl atIndex: pageNum];
// Release resources
[otl release];
[action release];
[destination release];
}
创建的大纲将作为子级添加到
根轮廓
尝试向尚未包含任何大纲的PDF添加大纲时出现问题。
那样的话
root = [pdfDoc outlineRoot];
将导致
root
设置为
NULL
接下来的代码显然失败了。
问题是:
PDF文档