ios - 从 UIWebView 进行 PDF 分页

标签 ios xcode pdf uiwebview paging

我正在使用此类从 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 文件,我只是想知道是否可以将其分成多页。

最佳答案

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

 UIGraphicsBeginPDFPage

这个想法是根据您想要生成的页面数量在 for LOOP 中执行此部分。

Go Through this post

关于ios - 从 UIWebView 进行 PDF 分页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15458839/

相关文章:

php - 多页 FPDI

objective-c - Xcode - UIActivityIndi​​cator 消失得太快

ios - 如何使用 grep 和 regex 提取特定标签内的信息

java - 如何使用 Google Cloud EndPoints(java) 在 Android/IOS 应用程序中使用基本身份验证

ios - 尝试在 iPad 上显示后置摄像头时应用程序卡住

ios - 根据另一个 UISegmentedControl 的情况禁用 UISegmentedControl

objective-c - 在 XCode 的自定义/用户代码片段中添加时间和日期

c# - 在 ITextSharp 免费许可证下动态创建 .pdf

xcode - 使用 Swift 设置文本字段中的数字格式

ios - 将 Realm 添加到 watchkit 项目时出现 Mach-O header 错误