我使用这种方式生成pdf文件现在它工作正常但背景为白色我想给背景一些颜色,所以可以给backgorund颜色。
- (void) generatePdfWithFilePath: (NSString *)thefilePath
{
UIGraphicsBeginPDFContextToFile(thefilePath, CGRectZero, nil);
NSInteger currentPage = 0;
BOOL done = NO;
do
{
UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, pageSize.width, pageSize.height), nil);
currentPage++;
[self drawPageNumber:currentPage];
//Draw a border for each page.
[self drawBorder];
//Draw text fo our header.
[self drawHeader];
//Draw a line below the header.
[self drawLine];
//Draw some text for the page.
[self drawText];
//Draw an image
[self drawImage];
done = YES;
}
while (!done);
UIGraphicsEndPDFContext();
}
答案 0 :(得分:6)
在do while循环中使用此代码
CGContextRef currentContext = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(currentContext, [UIColor redColor].CGColor );
CGContextFillRect(currentContext, pdfpageFrame);
这将解决您的问题