开发者

How do I generate PDFs from images in Objective-C? (on Mac OS)

I'm trying to build the code that will generate a single PDF from a bunch of images in Objective-C. Most of examples I've seen so far don't really allow me to build the PDF, but only generating Cocoa views and turning them into PDFs.

What I'm looking for is some toolkit (like Java's iText) that would all开发者_开发技巧ow me to generate a PDF from a bunch of images (with each image being a page in the PDF document).

Any hints?


It's simpler with PDFKit.

PDFDocument *pdf = [[PDFDocument alloc] init];
for (NSString *fileName in fileNames)
{
    NSImage *image = [[NSImage alloc] initWithContentsOfFile:fileName]; 
    PDFPage *page = [[PDFPage alloc] initWithImage:image];
    [pdf insertPage:page atIndex: [pdf pageCount]];
    [image release];
    [page release];
}

[pdf writeToFile: @"output.pdf"];


See Creating a PDF File section in Quartz 2D programming guide.

There's a sample code to create a pdf document. All you'll need to do there is implement your custom myDrawContent function, where you can draw your images to pdf context same way as to any other CGContextRef.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜