【问题标题】:PDF paging from UIWebView来自 UIWebView 的 PDF 分页
【发布时间】:2013-03-17 08:17:47
【问题描述】:

我正在使用这个类从 UIWebView 生成 PDF 文件

-(void)createPDFfromUI:(UIView *)aView saveToDocumentsWithFileName:(NSString*)aFilename
{
    // Creates a mutable data object for updating with binary data, like a byte array
    NSMutableData *pdfData = [NSMutableData data];

    // Points the pdf converter to the mutable data object and to the UIView to be converted
    UIGraphicsBeginPDFContextToData(pdfData, aView.bounds, nil);
    UIGraphicsBeginPDFPage();

    CGContextRef pdfContext = UIGraphicsGetCurrentContext();


    // draws rect to the view and thus this is captured by UIGraphicsBeginPDFContextToData

    [aView.layer renderInContext:pdfContext];

    // remove PDF rendering context
    UIGraphicsEndPDFContext();

    // Retrieves the document directories from the iOS device
    NSArray* documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);

    NSString* documentDirectory = [documentDirectories objectAtIndex:0];
    NSString* documentDirectoryFilename = [documentDirectory stringByAppendingPathComponent:aFilename];

    // instructs the mutable data object to write its context to a file on disk
    [pdfData writeToFile:documentDirectoryFilename atomically:YES];
}

我唯一的问题是它只是在一页中生成 PDF 文件,我只是想知道是否可以将它分成多页。

【问题讨论】:

    标签: ios xcode pdf uiwebview paging


    【解决方案1】:

    是的,您可以在 PDF 中包含多页,但为此您必须每次使用手动标记页面的开头

     UIGraphicsBeginPDFPage
    

    我们的想法是根据您要生成的页面数量为 LOOP 执行此部分。

    Go Through this post

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-12
      相关资源
      最近更新 更多