iphone - 将 HTML 转换为 PDF 时出现额外的空白页
<p><p>我已经像这样从 <code>UIWebView</code> 创建了 <code>PDF</code> :</p>
<pre><code>UIPrintPageRenderer *render = [ init];
;
CGRect printableRect;
CGRect paperRect;
printableRect = CGRectMake(10, 5, kPaperSizeA4.width-20, kPaperSizeA4.height-10);
paperRect = CGRectMake(0, 0, kPaperSizeA4.width, kPaperSizeA4.height);
forKey:@"paperRect"];
forKey:@"printableRect"];
NSData *pdfData = ;
if (pdfData) {
BOOL isSuccess = ;
if (isSuccess)
{
NSLog(@"Created and Saved");
}
}
</code></pre>
<p>现在问题是在 <code>created PDF</code> 中添加 <code>blank page</code>。</p>
<p>我引用了 <a href="https://stackoverflow.com/questions/2379521/extra-blank-page-when-converting-html-to-pdf-using-abcpdf" rel="noreferrer noopener nofollow">Extra blank page when converting HTML to PDF using abcPDF</a> .但是在 <code>iOS</code> 中我们怎样才能摆脱它???</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>相应变化:</p>
<p>首先<code>A4尺寸</code>是这样的:</p>
<pre><code>#define kPaperSizeA4 CGSizeMake(595,842)
</code></pre>
<p>改成:</p>
<pre><code>#define kPaperSizeA4 CGSizeMake(595.2,841.8)
</code></pre>
<p><code>PDF</code> 中 <code>content</code> 的 <code>increased</code> <code>page margin</code> :</p>
<pre><code>printableRect = CGRectMake(10, 18, kPaperSizeA4.width-20, kPaperSizeA4.height-36);
</code></pre>
<p>更多信息请引用 <a href="https://github.com/iclems/iOS-htmltopdf/pull/10" rel="noreferrer noopener nofollow">Avoid extra blank page (with A4, in some unexpected cases</a> </p></p>
<p style="font-size: 20px;">关于iphone - 将 HTML 转换为 PDF 时出现额外的空白页,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/18426817/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/18426817/
</a>
</p>
页:
[1]