【发布时间】:2014-04-15 03:00:07
【问题描述】:
我在 iOS 中使用 UIGraphicsBeginPDFContextToFile 创建 PDF,我想在其中添加指向其他页面和其他网站的 URL 链接。下面是代码:这里 pdfObj 是一个将文本绘制到 PDF 的自定义类。成功创建 PDF 后,如果单击“转到第 1 章”和“转到 URL”区域,则不会发生任何事情
UIGraphicsBeginPDFContextToFile(documentDirectoryFilename, CGRectZero, nil);
UIGraphicsBeginPDFPage();
//Page 1
UIGraphicsAddPDFContextDestinationAtPoint(@"Chapter1", CGPointMake(0, 0));
//other draw pdf data....
//Page 2
UIGraphicsBeginPDFPage();
//other draw pdf data....
[pdfObj addHeaderText:@"Go to Chapter 1" atFrame:CGRectMake(50, 50, 200, 44)];
UIGraphicsSetPDFContextDestinationForRect(@"Chapter1", CGRectMake(50, 50, 200, 44));
[pdfObj addHeaderText:@"Go to URL" atFrame:CGRectMake(550, 550, 200, 44)];
UIGraphicsSetPDFContextURLForRect([NSURL urlWithString:@"http://www.myURL.com"], CGRectMake(550, 550, 200, 44));
UIGraphicsEndPDFContext();
请让我知道我在这里犯了什么错误
【问题讨论】:
-
上面的代码运行良好,只是核心图形的 y 坐标是倒置的
标签: ios pdf hyperlink pdf-generation