如何在iphone应用程序中为pdf文件添加背景色

如何在iphone应用程序中为pdf文件添加背景色,iphone,xcode,pdf,background,uiimage,Iphone,Xcode,Pdf,Background,Uiimage,我正在用这种方法生成pdf文件,现在效果很好,但背景是白色的,我想给背景加一些颜色,所以有可能给背景加上颜色 - (void) generatePdfWithFilePath: (NSString *)thefilePath { UIGraphicsBeginPDFContextToFile(thefilePath, CGRectZero, nil); NSInteger currentPage = 0; BOOL done = NO; do { UIGr

我正在用这种方法生成pdf文件,现在效果很好,但背景是白色的,我想给背景加一些颜色,所以有可能给背景加上颜色

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

在DoWhile循环中使用此代码

CGContextRef currentContext = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(currentContext, [UIColor redColor].CGColor );
CGContextFillRect(currentContext, pdfpageFrame);
这将解决您的问题

我得到一个“Thread1:EXC\u BAD\u ACCESS(code=1,address=0x40)”错误