create pdf in objective-c
I have to generate a huge PDF file that contains data from 200 strings and 4 tables. Is there any way to visually create开发者_Go百科 the PDF, and then fill the data from my strings in the right place? If not, what would be the best way to do this? For now I tried drawInRect: method.
Thanks for any suggestion Radu
You may take a look to
NSPDFImageRep
CGPDFContext
Here's some sample code
NSMutableData* pdfData = [NSMutableData data];
CGDataConsumerRef consumer = CGDataConsumerCreateWithCFData((CFMutableDataRef) pdfData);
CGRect mediaBox = CGRectMake( 0, 0, width, height);
CGContextRef pdfContext = CGPDFContextCreate( consumer, &mediaBox, NULL);
CGDataConsumerRelease( consumer );
NSGraphicsContext* newGC = [NSGraphicsContext graphicsContextWithGraphicsPort:pdfContext flipped:YES];
[NSGraphicsContext saveGraphicsState];
[NSGraphicsContext setCurrentContext:newGC];
Then you can draw your pdf pages calling
CGPDFContextBeginPage( pdfContext, NULL );
/* draw here */
CGPDFContextEndPage( pdfContext );
精彩评论