是否可以在iPhone中以编程方式将多个pdf文件合并为一个pdf文件? [英] Is it possible to combine multiple pdf files into a single pdf file programmatically in iphone?
本文介绍了是否可以在iPhone中以编程方式将多个pdf文件合并为一个pdf文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在iPhone中以编程方式将多个pdf文件组合为一个pdf文件.我已经从程序的不同部分创建了单独的页面,现在需要将它们合并为一个文件
Is it possible to combine multiple pdf files into a single pdf file programmatically in iphone.I have created individual pages from different parts of my program and now need to merge them into a single file
推荐答案
是的,您可以这样做.请遵循以下代码
Yes you can do that. Please follow the below code
//Open a pdf context for the single file
UIGraphicsBeginPDFContextToFile(oldFile, paperSize, nil);
//Run a loop to the number of pages you want
for (pageNumber = 1; pageNumber <= count; pageNumber++)
{
//Open a pdf page context
UIGraphicsBeginPDFPageWithInfo(paperSize, nil);
//Get graphics context to draw the page
CGContextRef currentContext = UIGraphicsGetCurrentContext();
//Flip and scale context to draw the pdf correctly
CGContextTranslateCTM(currentContext, 0, paperSize.size.height);
CGContextScaleCTM(currentContext, 1.0, -1.0);
//Get document access of the pdf from which you want a page
CGPDFDocumentRef newDocument = CGPDFDocumentCreateWithURL ((CFURLRef) newUrl);
//Get the page you want
CGPDFPageRef newPage = CGPDFDocumentGetPage (newDocument, pageNumber);
//Drawing the page
CGContextDrawPDFPage (currentContext, newPage);
//Clean up
newPage = nil;
CGPDFDocumentRelease(newDocument);
newDocument = nil;
newUrl = nil;
}
UIGraphicsEndPDFContext();
因此,在绘制页面之前,您必须编写从适当的pdf中获取适当页面的必要条件.您已经从多个来源创建了pdf文件!
So you have to write necessary condition of taking appropriate pages from appropriate pdf before draw the page. You have created a pdf from multiple sources!
这篇关于是否可以在iPhone中以编程方式将多个pdf文件合并为一个pdf文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文