2010-07-15 30 views
23

我想寫一個簡單的PDF閱讀器,使用基於QuartzDemo的CGPDFDocument
有共同的描繪:(EX在觸摸事件)iPhone,CGPDFDocument - PDF鏈接

-(void)drawInContext:(CGContextRef)context 
{ 
    // PDF page drawing expects a Lower-Left coordinate system, 
    // so we flip the coordinate system before we start drawing. 
    CGContextTranslateCTM(context, 0.0, self.bounds.size.height); 
    CGContextScaleCTM(context, 1.0, -1.0); 

    // Grab the first PDF page 
    CGPDFPageRef page = CGPDFDocumentGetPage(pdf, pageNumber); 
    // We're about to modify the context CTM to draw the PDF page 
    // where we want it, so save the graphics state 
    // in case we want to do more drawing 
    CGContextSaveGState(context); 
    // CGPDFPageGetDrawingTransform provides an easy way 
    // to get the transform for a PDF page. It will scale down to fit, 
    // including any base rotations necessary to display the PDF page correctly. 
    CGAffineTransform pdfTransform = 
      CGPDFPageGetDrawingTransform(page, 
        kCGPDFCropBox, self.bounds, 0, true); 
    // And apply the transform. 
    CGContextConcatCTM(context, pdfTransform); 
    // Finally, we draw the page 
    // and restore the graphics state for further manipulations! 
    CGContextDrawPDFPage(context, page); 
    CGContextRestoreGState(context); 
} 

據我瞭解,它唯一的圖紙,所以所有的結構導航或外向鏈接,應手工處理。有功能which will set URLcreate element with URL

問題是:如何從某個PDF塊中獲取傳出鏈接URL?

謝謝!

類似的問題:
PDF hyperlinks on iPhone/iPad
How to access hyperlinks in PDF documents (iPhone)?

相同的
iPhone SDK Dev GGroup
macRumors Forum
iPhone Dev SDK Forum
Dev Shed Forum
iphonedevbook.com

+2

對於任何地方都沒有答案的問題+1。 *擦頭,不斷挖掘* – Kalle 2010-08-27 08:56:12

+3

+1,50點賞金 - 我很想知道答案,我們一直在尋找幾個星期,不管我們已經嘗試過什麼沒有結果 – 2010-09-27 23:45:19

+2

+100分爲工作樣品! – 2010-10-05 05:12:07

回答

17

這是一個不平凡的問題,這就是爲什麼你找不到簡單的答案。解決方案是:您必須解析PDF文檔。好消息是,蘋果提供的功能可以讓你做到這一點。壞消息是,他們是程序性的,而男性,這是一團糟。

在非常粗糙的僞代碼:

  • 使用CGPDFDocumentGetCatalog獲得樣本爲PDF
  • 看在目錄你正在尋找的頁面(是的,它是在「頁面」元素一個字典,而不是一個數組和一個嵌套的字典,所以這個簡單的操作不是那麼簡單)。
  • 現在使用CGPDFDictionaryGetArray獲取「Annot」對象
  • 接下來,您需要遍歷註釋並查找「Link」對象。

Adob​​e發佈了一個document,它規定了PDF規範。祝你好運!

+0

謝謝我意識到這不是一個微不足道的問題,因此賞金,但它是非常重要的,蘋果文檔是非常差,關於iPhone上的Quartz PDF,並沒有其他博客或教程覆蓋它 – 2010-09-29 09:03:36