我已经像这样从 UIWebView
创建了 PDF
:
UIPrintPageRenderer *render = [[UIPrintPageRenderer alloc] init];
[render addPrintFormatter:_webView.viewPrintFormatter startingAtPageAtIndex:0];
CGRect printableRect;
CGRect paperRect;
printableRect = CGRectMake(10, 5, kPaperSizeA4.width-20, kPaperSizeA4.height-10);
paperRect = CGRectMake(0, 0, kPaperSizeA4.width, kPaperSizeA4.height);
[render setValue:[NSValue valueWithCGRect:paperRect] forKey"paperRect"];
[render setValue:[NSValue valueWithCGRect:printableRect] forKey"printableRect"];
NSData *pdfData = [render printToPDF];
if (pdfData) {
BOOL isSuccess = [pdfData writeToFile:aStrDocDirPath atomically:YES];
if (isSuccess)
{
NSLog(@"Created and Saved");
}
}
现在问题是在 created PDF
中添加 blank page
。
我引用了 Extra blank page when converting HTML to PDF using abcPDF .但是在 iOS
中我们怎样才能摆脱它???
相应变化:
首先A4尺寸
是这样的:
#define kPaperSizeA4 CGSizeMake(595,842)
改成:
#define kPaperSizeA4 CGSizeMake(595.2,841.8)
PDF
中 content
的 increased
page margin
:
printableRect = CGRectMake(10, 18, kPaperSizeA4.width-20, kPaperSizeA4.height-36);
更多信息请引用 Avoid extra blank page (with A4, in some unexpected cases
关于iphone - 将 HTML 转换为 PDF 时出现额外的空白页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18426817/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |