我有一个很大的麻烦。我想合并多个PDF文件在iphone应用程序的一个PDF文件。但是我不能。你可以帮我吗 ?非常感谢如何将多个PDF文件合并为一个PDF
2
A
回答
3
如果我正确地理解了这个问题,您正试图将一堆独立的PDF文件添加到一个PDF文件中。
我用下面的代码将1个pdf文件添加到另一个pdf文件的末尾来创建一个pdf文件。
//NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *cacheDir = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
// File paths
NSString *pdfPath1 = [[NSBundle mainBundle] pathForResource:@"pdf1" ofType:@"pdf"];
NSString *pdfPath2 = [cacheDir stringByAppendingPathComponent:@"temp.pdf"];
NSString *pdfPathOutput = [cacheDir stringByAppendingPathComponent:@"out.pdf"];
// File URLs - bridge casting for ARC
CFURLRef pdfURL1 = (__bridge_retained CFURLRef)[[NSURL alloc] initFileURLWithPath:(NSString *)pdfPath1];//(CFURLRef) NSURL
CFURLRef pdfURL2 = (__bridge_retained CFURLRef)[[NSURL alloc] initFileURLWithPath:(NSString *)pdfPath2];//(CFURLRef)
CFURLRef pdfURLOutput =(__bridge_retained CFURLRef) [[NSURL alloc] initFileURLWithPath:(NSString *)pdfPathOutput];//(CFURLRef)
// File references
CGPDFDocumentRef pdfRef1 = CGPDFDocumentCreateWithURL((CFURLRef) pdfURL1);
CGPDFDocumentRef pdfRef2 = CGPDFDocumentCreateWithURL((CFURLRef) pdfURL2);
// Number of pages
NSInteger numberOfPages1 = CGPDFDocumentGetNumberOfPages(pdfRef1);
NSInteger numberOfPages2 = CGPDFDocumentGetNumberOfPages(pdfRef2);
// Create the output context
CGContextRef writeContext = CGPDFContextCreateWithURL(pdfURLOutput, NULL, NULL);
// Loop variables
CGPDFPageRef page;
CGRect mediaBox;
// Read the first PDF and generate the output pages
NSLog(@"GENERATING PAGES FROM PDF 1 (%i)...", numberOfPages1);
for (int i=1; i<=numberOfPages1; i++) {
page = CGPDFDocumentGetPage(pdfRef1, i);
mediaBox = CGPDFPageGetBoxRect(page, kCGPDFMediaBox);
CGContextBeginPage(writeContext, &mediaBox);
CGContextDrawPDFPage(writeContext, page);
CGContextEndPage(writeContext);
}
// Read the second PDF and generate the output pages
NSLog(@"GENERATING PAGES FROM PDF 2 (%i)...", numberOfPages2);
for (int i=1; i<=numberOfPages2; i++) {
page = CGPDFDocumentGetPage(pdfRef2, i);
mediaBox = CGPDFPageGetBoxRect(page, kCGPDFMediaBox);
CGContextBeginPage(writeContext, &mediaBox);
CGContextDrawPDFPage(writeContext, page);
CGContextEndPage(writeContext);
}
NSLog(@"DONE!");
// Finalize the output file
CGPDFContextClose(writeContext);
// Release from memory
CFRelease(pdfURL1);
CFRelease(pdfURL2);
CFRelease(pdfURLOutput);
CGPDFDocumentRelease(pdfRef1);
CGPDFDocumentRelease(pdfRef2);
CGContextRelease(writeContext);
+0
你可以检查这个SO链接http://stackoverflow.com/questions/16646039/how-to-save-created-pdf-in-document-folder-and-merge-in-ios我正在运行相同的问题 –
+0
我完成了你的上面的代码:) 1up的答案... –
-1
$mergedPath = '/tmp/bulkinvoice_merge_'.$vendor_id.'_'.$randomno.'.pdf';
$filepath = 'http://xyz/'.$vendor_id.'/'.$shipmentId.'_invoice_shipment_label.pdf';
$current = file_get_contents($filepath);
$tempPath = '/tmp/bulkinvoice_'.$vendor_id.'_'.$shipmentId.'.pdf';
chmod($tempPath, 777);
file_put_contents($tempPath,$current);
$pdf = Zend_Pdf::load($tempPath);
foreach($pdf->pages as $page){
$pdfExtract = $ex->clonePage($page);
$pdf2show->pages[] = $pdfExtract;
}
//$pdf2show->pages[] = $ex->clonePage($pdf->pages[0]);
echo "\n [->]Added in merged PDF : ".$shipmentId;
$pdf2show->save($mergedPath);
unlink($tempPath);
相关问题
- 1. 将多个PDF合并为一个PDF
- 2. 将多个PDF文件合并为一个PDF文件
- 3. 将多个pdf合并为一个PDFMerger
- 4. 如何在PHP中将多个PDF文件合并到一个单页PDF中
- 5. 如何使用PDF :: API2将几个pdf合并为一个Perl?
- 6. PDFCreator将多个pdf文件合并为一个
- 7. 将多个文件夹中的多个文件类型合并为一个pdf
- 8. 将2个postscript文件合并为pdf
- 9. 将pdf文件合并为{pdf ver 1.7}
- 10. 如何在swift 3.0中将一个pdf合并到另一个pdf文件中。
- 11. 如何使用ruby将多个图像合并为一个PDF?
- 12. 将多页PDF与ImageMagick合并为一个PDF
- 13. 合并多个PDF文件合并成一个用PHP Ghostscript的
- 14. 如何将2个base64二进制PDF文件合并为单个PDF?
- 15. 创建多个PDF合并为一个文件从excel
- 16. iTextSharp - 填写PDF多次并合并为一个pdf
- 17. 合并几个pdf文件
- 18. VB.Net将多个PDF合并为一个并导出
- 19. 用VBScript合并多个PDF文件
- 20. 如何将多个PDF文件(或PNG)合并成一个单一的页面
- 21. 在Linux上搜索PDF库(转换为图像并将多个文件合并为一个pdf)
- 22. 将两个文件pdf合并成一个文件覆盖?
- 23. 是否可以在iPhone中以编程方式将多个PDF文件合并为一个PDF文件?
- 24. 将PDF插入PDF(不合并文件)
- 25. 如何将多个单页PDF文件合并到Android中的一个PDF文档中
- 26. 如何在PHP中以单个PDF合并多个PDF
- 27. 如何使用java将多个多页面tiff文件合并为一个pdf文件?
- 28. 将png图像合并为一个pdf文件
- 29. 合并多个PDF的Zend
- 30. Unix:将PDF文件和图像合并为PDF文件?
您想使用现有的应用多个PDF文件合并成一个PDF文件,或者你想创建一个新的应用程序吗? –
使用['pdftk'](http://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/),'cat'命令。 – Orbling
@Orbling:在iOS上,嗯。 :/ – BastiBen