开发者

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 );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜