来自:http://www.cnblogs.com/tx8899/p/4082749.html

#pragma mark - Merge PDF

- (void)mergePDF

{

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString *filePath1 = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"阅办卡.pdf"];

NSString *filePath2 = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"文件.pdf"];

NSArray *PDFURLS = [NSArray arrayWithObjects:filePath1,filePath2, nil];

[self joinPDF:PDFURLS];

}

- (NSString *)joinPDF:(NSArray *)listOfPaths {

// File paths

NSString *fileName = [NSString stringWithFormat:@"公文%d.pdf",arc4random_uniform(100)];

NSString *pdfPathOutput = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0] stringByAppendingPathComponent:fileName];

CFURLRef pdfURLOutput = (  CFURLRef)CFBridgingRetain([NSURL fileURLWithPath:pdfPathOutput]);

NSInteger numberOfPages = 0;

// Create the output context

CGContextRef writeContext = CGPDFContextCreateWithURL(pdfURLOutput, NULL, NULL);

for (NSString *source in listOfPaths) {

CFURLRef pdfURL = (  CFURLRef)CFBridgingRetain([[NSURL alloc] initFileURLWithPath:source]);

//file ref

CGPDFDocumentRef pdfRef = CGPDFDocumentCreateWithURL((CFURLRef) pdfURL);

numberOfPages = CGPDFDocumentGetNumberOfPages(pdfRef);

// Loop variables

CGPDFPageRef page;

CGRect mediaBox;

// Read the first PDF and generate the output pages

//        NSLog(@"GENERATING PAGES FROM PDF 1 (%@)...", source);

for (int i=1; i<=numberOfPages; i++) {

page = CGPDFDocumentGetPage(pdfRef, i);

mediaBox = CGPDFPageGetBoxRect(page, kCGPDFMediaBox);

CGContextBeginPage(writeContext, &mediaBox);

CGContextDrawPDFPage(writeContext, page);

CGContextEndPage(writeContext);

}

CGPDFDocumentRelease(pdfRef);

CFRelease(pdfURL);

}

CFRelease(pdfURLOutput);

// Finalize the output file

CGPDFContextClose(writeContext);

CGContextRelease(writeContext);

return pdfPathOutput;

}

IOS - PDF合并 - 转的更多相关文章

  1. IOS - PDF合并

    #pragma mark - Merge PDF - (void)mergePDF { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSD ...

  2. PDF合并

    要求:将多个table导出到一个PDF里,然后打印. 问题分析:要求将四个table放一个PDF打印,四个table的列各不相同,第一个是表头,其他三个是列表,列比表头多很多,如果直接生成一个exce ...

  3. C#实现多个PDF合并及去除文字水印功能

    实现pdf合并就是使用Spire.Pdf.dll类库的方法,但是注意需要同时引用Spire.Pdf.dll和Spire.License.dll两个类库,且两个类库的版本要一致 String[] fil ...

  4. PHP使用FPDF pdf添加水印中文乱码问题 pdf合并版本问题

    ---恢复内容开始--- require_once('../fpdf/fpdf.php');require_once('../fpdi/fpdi.php'); 使用此插件 pdf 合并 并添加水印 期 ...

  5. iOS音频合并

    iOS音频合并 最近遇到一个需求,客户录音试听一下可以,就继续向下录制,当客户录制完成后,需要把前面录制的试听音频和后面的音频进行合并.最初想到的方法,使用NSData对两个音频文件进行合并,但是合并 ...

  6. pdftk - handy tool for manipulating PDF 免费的pdf合并工具

    Linux pdf合并的工具 安装工具 $ sudo apt-get install pdftk 使用 $ pdftk *.pdf cat output all-in-one.pdf &&am ...

  7. 极客工具,PDF合并工具

    前言 这两天一番花两天的时间,重新用python和python图形化开发工具tkinter,完善了下PDF合并小工具,终于可以发布了. 工具目前基本功能已经完善,后期如果有反馈可以修复部分bug或完善 ...

  8. PDF文档转换为图片、图片转成PDF 及PDF合并

    简介 功能:PDF文档按每页转换成一张图片,一张图片转换成一张PDF 并将多张PDF合成一个多页的PDF文档. 经历:在各个网站上搜索始终出现各种问题,尤其是遇到引用的版本问题尤其头疼,不是不能适用当 ...

  9. Aspose.Pdf合并图片到PDF文件

    将图片和PDF文件合成为新的PDF文件,可以先将图片转换为PDF文件, 然后合成PDF即可, 将图片转换成PDF文件有如下方法: Aspose.Pdf.Document Aspose.Pdf.Gene ...

随机推荐

  1. Prime Distance(二次筛素数)

    Description The branch of mathematics called number theory is about properties of numbers. One of th ...

  2. C# 性能优化 之 秒表 Stopwatch。 Dapper一个和petapoco差不多的轻量级ORM框架

    Sweet小马 小马同学的编程日记. C# 性能优化 之 秒表 Stopwatch. 生词解释:Diagnostics[,daɪəg'nɑstɪks] n.诊断学 using System.Diagn ...

  3. MongoDB 自己定义函数

    定义 db.system.js.insert({ _id : "TestConcat", value : function TestConcat(s1, s2){ return s ...

  4. 刚刚做了个文件上传功能,拿来分享一下!(MVC架构及传统架构通用)

    文件上传无论在软件还是在网站上都十分常见,我今天再把它拿出来,讲一下,主要讲一下它的设计思想和实现技术,为了它的通用性,我把它做在了WEB.Service项目里,即它是针对服务器的,它的结构是关联UI ...

  5. HDU 5544 Ba Gua Zhen dfs+高斯消元

    Ba Gua Zhen Problem Description During the Three-Kingdom period, there was a general named Xun Lu wh ...

  6. accp

    ACCP(Aptech Certified Computer Professional)是印度最早从事IT职业教育的Aptech计算机教育公司推出的培养软件程序设计人员的课程体系,由北大青鸟集团于20 ...

  7. camera shading比例

    -- ---- vendor/mediatek/proprietary/custom/mt6735/hal/D2/camera_3a/isp_tuning_custom.cpp static MINT ...

  8. leetcode 783. Minimum Distance Between BST Nodes 以及同样的题目 530. Minimum Absolute Difference in BST

    Given a Binary Search Tree (BST) with the root node root, return the minimum difference between the ...

  9. 【转】Java 并发编程:线程间的协作(wait/notify/sleep/yield/join)

    一.线程的状态 Java中线程中状态可分为五种:New(新建状态),Runnable(就绪状态),Running(运行状态),Blocked(阻塞状态),Dead(死亡状态). New:新建状态,当线 ...

  10. bzoj 3781 小B的询问 —— 莫队

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3781 就是莫队,左端点分块排序,块内按右端点排序,然后直接做即可. 代码如下: #inclu ...