ios - 为什么我的字符串在写入 PDF 时会被截断
<p><p>我将多个字符串<code>连接</code>成一个 super 字符串,然后将其绘制到<b><code>PDF</code></b>。然而,由于某种神秘的原因,该字符串在 <code>line 48</code> 处提前终止。我已经确认字符串本身在所有适当的时间都包含所有所需的信息,这表明问题出在其他地方。</p>
<p>会发生什么?</p>
<p><b>这是我的代码:</b></p>
<pre><code>@interface Review ()
{
CGSize pagesize;
UIDocumentInteractionController *documentInteractionController;
}
...
UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, 612, 3000), nil);
...
// prepare string ... we're in a loop
// each addition is typically a single line and either a word or number
// as you can see the first string is itself. it's possible i'm doing this in a hacky way, but i am preparing pdfText in multiple stages identical as below in the loop and decided to use on string instead of many.
// i can post the entire loop if requested, but i don't see any additional useful information it provides as it's simply a series of the code line below
pdfText = , _fd.t2_departure, _fd.t2_outFuel, _fd.t2_startHobbs, _fd.t2_whoIsFlying];
if(i == 0)
{
// for reasons undetermined, i have to offset by a large negative value to format the text properly. if set to 0, the text is near the middle of the page??? i'm thinking this is a clue.
// if pdfText is set to a single line, the negative bias is unneeded. wtf?
rect = CGRectMake(offset, -103, pagesize.width, pagesize.height);
}else{
rect = CGRectMake(offset, 12, pagesize.width, pagesize.height);
}
;
</code></pre>
<p>这是一张图片,它说明了垂直偏移的特别注意问题(右栏中的日期信息应与左栏中的日期标签对齐)。应该还有大约 9 个数据条目,这些条目被过早地切断了。格式正确时很明显,但无论如何都很清楚。:</p>
<p> <a href="http://i.imgur.com/zNVXxIH.jpg" rel="noreferrer noopener nofollow">http://i.imgur.com/zNVXxIH.jpg</a> </p>
<p>这是调用上述代码的代码主体(在生成内部)</p>
<pre><code>pagesize = CGSizeMake(612, 792);
NSString *fileName = @"AirShare.pdf";
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docDirectory = ;
NSString *PDFpathWithFileName = ;
;
NSURL *URL = ;
if (URL) {
self->documentInteractionController = ;
;
;
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我的页面太小了</p>
<pre><code>pagesize = CGSizeMake(612, 1200); // the 2nd argument was set to 792
</code></pre>
<p>为什么这不会切断整个页面,我不知道,但这确实解决了立即发布的问题。</p></p>
<p style="font-size: 20px;">关于ios - 为什么我的字符串在写入 PDF 时会被截断,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/16706485/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/16706485/
</a>
</p>
页:
[1]