1

根据我的应用程序,我创建了 Pdf 文件,但我需要生成多页的 Pdf?这是我用于生成 pdf 的代码。

-(void)drawPDF

{
pagesize = CGSizeMake(612, 792);

NSString *fileName = @"Report.pdf";
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
pdfFileName = [documentsDirectory stringByAppendingPathComponent:fileName];
[self generatePdfWithFilePath:pdfFileName];
}

-(void) generatePdfWithFilePath: (NSString *)thefilePath
{

UIGraphicsBeginPDFContextToFile(thefilePath, CGRectZero, nil);

//开始一个新页面。

UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, pagesize.width, pagesize.height), nil);

//为我们的标题绘制文本。

CGContextRef    currentContext = UIGraphicsGetCurrentContext();

CGContextSetRGBFillColor(currentContext, 0.0, 0.0, 0.0, 1.0);

UIFont *font = [UIFont systemFontOfSize:14.0];

int xOrigin = 20;
int yOrigin = 300;

int rowHeight = 50;
int columnWidth = 140;

int numberOfRows = 7;
int numberOfColumns = 4;

[self drawTableAt:CGPointMake(xOrigin, yOrigin) withRowHeight:rowHeight andColumnWidth:columnWidth andRowCount:numberOfRows andColumnCount:numberOfColumns];

[self drawImageAt:CGPointMake(xOrigin, yOrigin) withRowHeight:rowHeight andColumnWidth:columnWidth];

[self drawTableDataAt:CGPointMake(xOrigin, yOrigin) withRowHeight:rowHeight andColumnWidth:columnWidth andRowCount:numberOfRows andColumnCount:numberOfColumns withArray:allinfo];

// [self drawTextAt:CGPointMake(xOrigin, yOrigin) withRowHeight:rowHeight andColumnWidth:columnWidth];

CGSize stringSize = [contents_for_pdf sizeWithFont:font constrainedToSize:CGSizeMake(pagesize.width - 2*kBorderInset-2*kMarginInset, pagesize.height - 2*kBorderInset - 2*kMarginInset) lineBreakMode:NSLineBreakByWordWrapping];

CGRect renderingRect = CGRectMake(kBorderInset + kMarginInset, kBorderInset + kMarginInset + 50.0, pagesize.width - 2*kBorderInset - 2*kMarginInset, stringSize.height);

[contents_for_pdf drawInRect:renderingRect withFont:font lineBreakMode:NSLineBreakByWordWrapping alignment:NSTextAlignmentLeft];

UIGraphicsEndPDFContext();


}
4

1 回答 1

1

您可以在 ios 中查看此链接以生成 pdf

http://www.raywenderlich.com/6818/how-to-create-a-pdf-with-quartz-2d-in-ios-5-tutorial

同样在您的代码中使用您的 [array count+1] 行数

于 2014-08-08T11:49:23.083 回答