public
Created

PDF Rendering white background

  • Download Gist
pdfmultipage.m
Objective-C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
- (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;
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.