iphone - 是否可以在 iphone 中以编程方式将多个 pdf 文件组合成一个 pdf 文件?

标签 iphone ios pdf

是否可以在 iphone 中以编程方式将多个 pdf 文件合并到一个 pdf 文件中。我已经从程序的不同部分创建了单独的页面,现在需要将它们合并到一个文件中

最佳答案

是的,你可以做到。请按照以下代码

//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!

关于iphone - 是否可以在 iphone 中以编程方式将多个 pdf 文件组合成一个 pdf 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9646203/

相关文章:

iphone - NSMutableArray 不获取 XML 值

ios - 如何在 RestKit 中映射动态响应?

iphone - 推送通知数据检索

php - 如何使用 PHP 制作 pdf 文件

php - FPDF - WriteHTML 函数中的 PHP?

iphone - xcode 地理位置 : Getting coordinates before view is loaded

iphone - 如何复制模态交叉溶解动画?

iphone - 向 UIImageView 添加触摸不起作用

ios - 如何为 iOS 应用程序正确使用 setNeedsDisplayInRect?

php - 如何使用 PHP 从 PDF 中检索数字签名信息?