2
A
回答
0
使用以下功能将UIButton放在PDF链接上。这将在您的UIView上绘制按钮。你必须传递你的页面作为参数。目前它将绘制带有类型为UIButtonTypeRoundedRect的按钮,然后将其更改为自定义,以便将其隐藏。最初按钮可能会被绘制在除链接之外的其他位置,因此您需要根据您的要求调整x/y位置。
-(void)drawLinks:(CGPDFPageRef)thisPage
{
CGPDFDictionaryRef pageDictionary = CGPDFPageGetDictionary(thisPage);
CGPDFArrayRef outputArray;
if(!CGPDFDictionaryGetArray(pageDictionary,"Annots", &outputArray))
{
return;
}
int arrayCount = CGPDFArrayGetCount(outputArray);
if(!arrayCount)
{
//continue;
}
for(int j = 0; j < arrayCount; ++j)
{
CGPDFObjectRef aDictObj;
if(!CGPDFArrayGetObject(outputArray, j, &aDictObj))
{
return;
}
CGPDFDictionaryRef annotDict;
if(!CGPDFObjectGetValue(aDictObj, kCGPDFObjectTypeDictionary, &annotDict)) {
return;
}
CGPDFDictionaryRef aDict;
if(!CGPDFDictionaryGetDictionary(annotDict, "A", &aDict)) {
return;
}
CGPDFStringRef uriStringRef;
if(!CGPDFDictionaryGetString(aDict, "URI", &uriStringRef)) {
return;
}
CGPDFArrayRef rectArray;
if(!CGPDFDictionaryGetArray(annotDict, "Rect", &rectArray)) {
return;
}
int arrayCount = CGPDFArrayGetCount(rectArray);
CGPDFReal coords[4];
for(int k = 0; k < arrayCount; ++k) {
CGPDFObjectRef rectObj;
if(!CGPDFArrayGetObject(rectArray, k, &rectObj)) {
return;
}
CGPDFReal coord;
if(!CGPDFObjectGetValue(rectObj, kCGPDFObjectTypeReal, &coord)) {
return;
}
coords[k] = coord;
}
char *uriString = (char *)CGPDFStringGetBytePtr(uriStringRef);
NSString *uri = [NSString stringWithCString:uriString encoding:NSUTF8StringEncoding];
CGRect rect = CGRectMake(coords[0],coords[1],coords[2],coords[3]);
CGPDFInteger pageRotate = 0;
CGPDFDictionaryGetInteger(pageDictionary, "Rotate", &pageRotate);
CGRect pageRect = CGRectIntegral(CGPDFPageGetBoxRect(thisPage, kCGPDFMediaBox));
if(pageRotate == 90 || pageRotate == 270)
{
CGFloat temp = pageRect.size.width;
pageRect.size.width = pageRect.size.height;
pageRect.size.height = temp;
}
rect.size.width -= rect.origin.x;
rect.size.height -= rect.origin.y;
CGAffineTransform trans = CGAffineTransformIdentity;
trans = CGAffineTransformTranslate(trans, 0, pageRect.size.height);
trans = CGAffineTransformScale(trans, 1.0, -1.0);
rect = CGRectApplyAffineTransform(rect, trans);
UIButton *btnTmp = [UIButton buttonWithType:UIButtonTypeRoundedRect]; // After testing put here UIButtonTypeCustom
[btnTmp addTarget:self action:@selector(urlOpen:) forControlEvents:UIControlEventTouchUpInside];
rect.origin.x = rect.origin.x + 78; //I have adjusted this as per my requirement
rect.origin.y = rect.origin.y + 108; // I have adjusted this as per my requirement
btnTmp.frame = rect;
btnTmp.titleLabel.text = uri;
[self.superview addSubview:btnTmp];
}
}
相关问题
- 1. 查找PDF文档中的超链接?
- 2. 访问pdf(iPhone)中的超链接?
- 3. 从PDF文档删除超链接(iTextSharp)
- 4. 将超链接添加到PDF文档
- 5. 如何显示包含超链接的PDF文档? (在iOS上)
- 6. iPhone中PDF的超链接
- 7. 使用xsl fo创建PDF文档中的超链接
- 8. PDF文档中的Mailto链接
- 9. 无法访问iPhone中的pdf链接
- 10. Safari中Word文档的超链接
- 11. 从pdf文件中读取超链接
- 12. 访问gridview列中的超链接
- 13. 如何访问中继器中的超链接控件c#.net
- 14. 如何扫描PDF文档中的链接?
- 15. 如何使用itext替换PDF中的超链接文本
- 16. TFS 2012文档超链接
- 17. 如何使用PowerShell编辑Word文档中的超链接?
- 18. 访问 - 超链接不链接
- 19. 超链接访问颜色
- 20. 超链接到在访问
- 21. 如何访问asp.net中BulletedList的超链接?
- 22. 如何从_RowEditing Sub访问gridview中的超链接控件?
- 23. 从gridview中的超链接打开pdf
- 24. 提取PDF中的超链接到Excel
- 25. pdf中的动态超链接
- 26. 如何在sphinx文档中创建内部超链接
- 27. 在Umbraco中访问/显示链接文档类型的属性
- 28. 将文档保存为PDF时,VBA超链接不起作用
- 29. PDF文档超链接JavaScript来改变父窗口URI
- 30. 超链接狮身人面像PDF文档
谢谢jennis,但我想在一个卷曲页面pdf设置网站链接的链接,但这段代码没有在我的应用程序中运行。 – parag
此代码适用于任何pdf页面。你遇到什么问题? –
感谢jennish的回复.jennish你有例子然后发送给我...我必须在这个pdf文件上设置一个链接,并且我还可以在pdf中使用curl页面效果。如果你有演示或示例代码请给我链接。 – parag