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