Reputation: 285
I have to generate a huge PDF file that contains data from 200 strings and 4 tables. Is there any way to visually create 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
Upvotes: 1
Views: 3028
Reputation: 10865
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 );
Upvotes: 2