Edit PDF Pages With ComPDFKit in Objective-C
It’s annoying to receive PDFs which are with much extra information or less information than they should have. A large PDF document could make sharing difficult. So, for electric file editors, it’s important to provide the function of editing PDFs like adding and deleting PDF pages.
We will introduce how to edit PDF pages with ComPDFKit in Objective-C here. The features we mentioned in the following are deleting, adding, moving, exchanging, replacing, and rotating.
The Operations Between PDF Files
Import PDF Pages
ComPDFKit supports importing PDF pages from other PDFs to add lots of information. Here are the methods in code. If you don’t specify the pages, the whole PDF will be imported.
NSURL *url = [NSURL fileURLWithPath:@""];
CPDFDocument *document = [[CPDFDocument alloc] initWithURL:url];
NSURL *improtUrl = [NSURL fileURLWithPath:@""];;
CPDFDocument *importDocument = [[CPDFDocument alloc]initWithURL:improtUrl];
NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
for (NSUInteger index = 0; index< importDocument.pageCount; index++) {
[indexSet addIndex:index];
}
[document importPages:indexSet fromDocument:importDocument atIndex:document.pageCount];
Replace PDF Pages
If you want to delete and insert the pages, Replace PDF pages in one step by CPDFDocument::removePageAtIndexSet:
and CPDFDocument::importPages:fromDocument:atIndex:
.
The Operations in the Current PDF file
Add PDF Pages
ComPDFKit supports inserting one page or multiple pages into PDFs. You can insert blank pages for adding little content to present. Here are the methods in code to add a blank page in front of page 3.
NSURL *url = [NSURL fileURLWithPath:@""];
CPDFDocument *document = [[CPDFDocument alloc] initWithURL:url];
[document insertPage:CGSizeMake(595.0, 842.0) atIndex:2];
Delete PDF Pages
An easy way to delete PDF pages is by interface removePageAtIndexSet: The pages you want to delete could be a single page, a range of PDF pages, or some randomly selected pages. The code below shows the methods of deleting page 5 and the page range from 8 to 10.
NSURL *url = [NSURL fileURLWithPath:@""];
CPDFDocument *document = [[CPDFDocument alloc] initWithURL:url];
NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
[indexSet addIndex:4];
NSRange range = NSMakeRange(7, 3);
[indexSet addIndexesInRange:range];
[document removePageAtIndexSet:indexSet];
Move PDF Pages
To have a better reading experience or arrange the content more properly, ComPDFKit supports moving a PDF page or a group of PDF pages. The features we often used when preparing presentations or reports. Follow the methods to move pages 1~2 and insert them after page 5.
NSURL *url = [NSURL fileURLWithPath:@""];
CPDFDocument *document = [[CPDFDocument alloc] initWithURL:url];
CPDFPage *page0 = [document pageAtIndex:0];
CPDFPage *page1 = [document pageAtIndex:1];
[document movePageAtIndex:[document indexForPage:page0] withPageAtIndex:4];
[document movePageAtIndex:[document indexForPage:page1] withPageAtIndex:[document indexForPage:page0]];
Exchange PDF Pages
With ComPDFKit, you could exchange the location of two PDF pages. Follow the method below to exchange the location of pages 3 and 7.
[document exchangePageAtIndex:2 withPageAtIndex:6];
Rotate PDF Page
Rotating pages could be done by the method in the CPDFPage class. Pages can be rotated at 0, 90, 180, or 270 degrees. Follow the method below to rotate page 5 in 180 degrees.
CPDFPage *page = [document pageAtIndex:4];
NSInteger rotate = page.rotation;
rotate += 180;
rotate = rotate % 360;
[page setRotation:rotate];
Conclusion
ComPDFKit provides complete PDF editing features like editing PDFs, security, etc.
相关文章
- java将Word转换成PDF
- PDF Expert for mac(pdf编辑工具) v2.5.21中文激活版
- python读取pdf文件
- PDF转Word完全指南:3大方法满足各种场景!
- Adobe发布针对Acrobat、Reader和Photoshop CC的重要更新PDF编辑器全版本下载
- Acrobat Pro9 Pdf编辑器-最牛逼的PDF编辑器
- 斯坦福经典书《统计学习导论》第二版(附PDF)
- 时隔七年的填坑之作:《机器学习数学》书稿PDF免费下载了
- PDF Expert for mac(pdf编辑工具) v3.0.37(910)中文激活版
- 轻松处理PDF文档,无缝连接云端——Adobe Acrobat Pro DC 2015+全版本安装包
- Linux系统编程:从基础到实践的PDF手册(linux系统编程pdf)
- MySQL OR和IN:比较和选择(mysqlor和in)
- Linux学习入门:从PDF到实际操作(linux学习教程pdf)
- OneDrive更新:网页端引入深色模式 iOS端支持PDF书签
- Microsoft Edge获全新功能 进一步增强PDF阅读体验
- 文件Linux下打开PDF文件的方法(linux如何打开pdf)
- MySQL查询优化:从IN中获取更高性能(mysql查询优化in)
- linux系统下轻松转换PDF文件(linux转pdf文件)
- 搜索MySQL中IN搜索的应用(mysql包含in)
- Mastering Advanced MySQL: The Ultimate Guide in PDF Format(mysql高级pdf)
- Adobe Reader(也被称为Acrobat Reader)是美国Adobe公司开发的一款优秀的PDF文件阅读软件。文档的撰写者可以向任何人分发自己制作(通过Adobe Acobat制作)的PDF文档而不用担心被恶意篡改。
- 「Linux防火墙PDF」教你如何有效保护你的计算机网络安全(linux防火墙pdf)
- MySQL中的Out和In操作一个简单的指南(mysql中out in)
- 解析MySQL中IN操作符的实现原理(mysql中in的原理)
- MySQL中IN操作的高效优化(mysql 中in的优化)
- 中利用IN语句检索Oracle数据库中的数据(in在oracle数据库)
- Oracle中IN运算符的强大用法(oracle中in的使用)
- 使用Oracle中的IN方法精准查找数据(oracle中in方法)
- 基于Redis的大规模分布式系统设计与实现(redis设计实现pdf)
- java使用pdfbox操作pdf文件示例
- asp.net实现将ppt文档转换成pdf的方法