簡體   English   中英

寫入PDF時為什么我的字符串被切斷

[英]Why does my string get cut off when writing to a PDF

我將多個字符串concatenating到一個超級字符串中,然后將其繪制為PDF 但是,由於某些神秘的原因,該字符串在line 48過早中斷了。 我已經確認,字符串本身在所有適當的時間包含所有所需的信息,這表明問題出在其他地方。

可能會發生什么?

這是我的代碼:

@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 = [NSString stringWithFormat:@"\n%@\n%@\n%@\n%@\n%@\n%@\n", pdfText, _fd.t2_tripNumber[i], _fd.t2_departure[i], _fd.t2_outFuel[i], _fd.t2_startHobbs[i], _fd.t2_whoIsFlying[i]];


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);
 }  

 [pdfText drawInRect:rect withFont:font lineBreakMode:NSLineBreakByWordWrapping alignment:NSTextAlignmentLeft];

這是一幅圖像,該圖像說明了垂直偏移特別注意的問題(右列的日期信息應與左列的日期標簽對齊)。 大約還應該有9個數據條目,這些條目過早地被切斷了。 格式正確時很明顯,但是無論如何它都很清楚。

http://i.imgur.com/zNVXxIH.jpg

這是調用上面代碼的代碼體(在內部生成)

pagesize = CGSizeMake(612, 792);
NSString *fileName = @"AirShare.pdf";
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docDirectory = [path objectAtIndex:0];
NSString *PDFpathWithFileName = [docDirectory stringByAppendingPathComponent:fileName];

[self generate:PDFpathWithFileName];

NSURL *URL = [NSURL fileURLWithPath:PDFpathWithFileName];
if (URL) {
    self->documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:URL];
    [self->documentInteractionController setDelegate:self];
    [self->documentInteractionController presentPreviewAnimated:YES];
} 

我的頁面大小太小

pagesize = CGSizeMake(612, 1200); // the 2nd argument was set to 792

我不知道為什么這不能中斷整個頁面,但這確實解決了立即發布的問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM