保存之前在iOS中预览PDF文档

时间:2013-04-15 02:50:56

标签: ios pdf nsdocumentcontroller

我正在制作一个可生成PDF的应用。我可以很好地生成PDF,但它是一键式操作,可以构建和保存PDF。我想要做的是将其更改为显示PDF的预览,然后提供编辑内容的选项,或将其保存到Documents文件夹。我该怎么做呢?以下是我所保存的内容。

- (IBAction)generatePdfButtonPressed:(id)sender
{
    pageSize = CGSizeMake(792, 612);
    NSString *fileName = @"Demo.pdf";
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *pdfFileName = [documentsDirectory stringByAppendingPathComponent:fileName];

    [self generatePdfWithFilePath:pdfFileName];
}
- (void) generatePdfWithFilePath: (NSString *)thefilePath
{
    UIGraphicsBeginPDFContextToFile(thefilePath, CGRectZero, nil);


    BOOL done = NO;
    do
    {

        UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, pageSize.width, pageSize.height), nil);


         [self drawImage];

        [self drawText];
        [self drawText2];
        [self drawText3];
        [self drawText4];


        done = YES;
    }
    while (!done);

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

1 个答案:

答案 0 :(得分:0)

使用UIWebview创建视图。然后,您只需将已保存的PDF文档加载到webview

即可