Skip to content

Instantly share code, notes, and snippets.

@itod
Created August 16, 2012 21:05
Show Gist options
  • Save itod/3373667 to your computer and use it in GitHub Desktop.
Save itod/3373667 to your computer and use it in GitHub Desktop.
PDF Rendering white background
- (NSData *)PDFDataForMultiPageDocument {
NSMutableData *data = [NSMutableData data];
CGDataConsumerRef consumer = CGDataConsumerCreateWithCFData((CFMutableDataRef)data);
if (NULL == consumer) {
NSLog(@"could not create consumer");
return nil;
}
CGRect r = CGRectMake(0.0, 0.0, 800.0, 600.0);;
CGContextRef ctx = CGPDFContextCreate(consumer, &r, NULL);
CFRelease(consumer);
NSGraphicsContext *gc = [NSGraphicsContext graphicsContextWithGraphicsPort:ctx flipped:NO];
CGContextBeginPage(ctx, &r);
CGContextSaveGState(ctx);
// CGContextClearRect(ctx, r);
const CGFloat clearColor[] = {1.0, 1.0, 0.0, 1.0};
CGContextSetFillColor(ctx, clearColor);
CGContextFillRect(ctx, CGRectMake(10.0, 10.0, 50.0, 50.0));
CGContextSetStrokeColor(ctx, clearColor);
CGContextStrokeEllipseInRect(ctx, r);
CGContextRestoreGState(ctx);
CGContextEndPage(ctx);
CGPDFContextClose(ctx);
CGContextRelease(ctx);
return data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment