2013-10-28 91 views
0

我想創建電子書閱讀器應用程序。初期我的目標是閱讀.pdf文件(閱讀器可以在此標記並可能做簽名);後者,它可以讀取其他文件格式also.I都通過這個走了:爲iOS創建電子書(pdf)閱讀器應用程序

https://developer.apple.com/library/ios/samplecode/DocInteraction/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010052-Intro-DontLinkElementID_2

但沒有提到哪裏,這將閱讀.PDF。做這個的最好方式是什麼?

請建議。

回答

0

請點擊此代碼

-(void)drawText 
{ 
    NSString* fileName = @"Invoice.PDF"; 

    NSArray *arrayPaths = 
    NSSearchPathForDirectoriesInDomains(
             NSDocumentDirectory, 
             NSUserDomainMask, 
             YES); 
    NSString *path = [arrayPaths objectAtIndex:0]; 
    NSString* pdfFileName = [path stringByAppendingPathComponent:fileName]; 

    NSString* textToDraw = @"Hello World"; 
    CFStringRef stringRef = (__bridge CFStringRef)textToDraw; 

    // Prepare the text using a Core Text Framesetter. 
    CFAttributedStringRef currentText = CFAttributedStringCreate(NULL, stringRef, NULL); 
    CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString(currentText); 

    CGRect frameRect = CGRectMake(0, 0, 300, 50); 
    CGMutablePathRef framePath = CGPathCreateMutable(); 
    CGPathAddRect(framePath, NULL, frameRect); 

    // Get the frame that will do the rendering. 
    CFRange currentRange = CFRangeMake(0, 0); 
    CTFrameRef frameRef = CTFramesetterCreateFrame(framesetter, currentRange, framePath, NULL); 
    CGPathRelease(framePath); 

    // Create the PDF context using the default page size of 612 x 792. 
    UIGraphicsBeginPDFContextToFile(pdfFileName, CGRectZero, nil); 

    // Mark the beginning of a new page. 
    UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, 612, 792), nil); 

    // Get the graphics context. 
    CGContextRef currentContext = UIGraphicsGetCurrentContext(); 

    // Put the text matrix into a known state. This ensures 
    // that no old scaling factors are left in place. 
    CGContextSetTextMatrix(currentContext, CGAffineTransformIdentity); 

    // Core Text draws from the bottom-left corner up, so flip 
    // the current transform prior to drawing. 
    CGContextTranslateCTM(currentContext, 0, 100); 
    CGContextScaleCTM(currentContext, 1.0, -1.0); 

    // Draw the frame. 
    CTFrameDraw(frameRef, currentContext); 

    CFRelease(frameRef); 
    CFRelease(stringRef); 
    CFRelease(framesetter); 

    // Close the PDF context and write the contents out. 
    UIGraphicsEndPDFContext(); 

} 

否則示例代碼此鏈接http://www.raywenderlich.com/6581/how-to-create-a-pdf-with-quartz-2d-in-ios-5-tutorial-part-1

+0

感謝這個tutorial.I可參照此以後(當我要做出一些PDF平局)但是,現在我想閱讀任何PDF文檔(我不想生成PDF,但只是想閱讀)。我試圖開發一個iOS電子書應用程序,這將允許閱讀不同的PDF。使用蘋果API將是最好的,但第三方免費庫也可以爲我工作。我的目標是用於iPAD應用程序。謝謝。 – bapi

+0

剛剛得到這個:「PSPDFKit」;這是免費的嗎? http://pspdfkit.com/ – bapi