当前位置:网站首页>Extract any page number in PDF file with itextpdf
Extract any page number in PDF file with itextpdf
2022-07-23 22:34:00 【51CTO】
Now there is such a need :
There are dozens of pages PDF file , Now you need to split the specified page number , And then you generate a new one PDF file .
This is the time , You can use open source itextpdf Library to implement ,itextpdf The official github The address is : https://github.com/itext/itextpdf.
The following is a demonstration through specific code .
1、 Introduce dependencies
at present itextpdf The latest version is 5.5.13.3, Can be in https://search.maven.org/ Search the website .
2、 Code implementation
2.1 Specify page number extraction
extract() The method has three arguments , Subcontracting is the source PDF File path 、 The goal is PDF File path and specified page number , The designated page number is List Set to pass , For example, you need to extract the number 1 page , You can call... As follows
If you need to extract multiple pages at the same time , such as 1、3、5 page , So you can call
Of course , If one PDF There are more than 100 pages , Now we need to extract 10-60 page , If you still pass parameters as above , It will be very troublesome , At this point, you can overload a method , Realize the delivery of the start page number and end page number to extract .
2.2 Start and end page number extraction
heavy load extract Method , The specific code is as follows :
For consecutive pages , This method is simpler , For example, to extract 10-60 page , So you can call
3、 Test verification
Now there is a total 2 page PDF file , Use the above methods to extract and split the second 1 page , The code is as follows :
After operation , Each generated test_out_1.pdf and test_out_2.pdf Two new files , New files are the first page of the source file .
4、 Other methods
If you only deal with a single PDF Word of the file , Then you can use WPS The printing function of , perhaps Chrome The printing function of the browser can be realized , Very convenient .
4.1 WPS Print split

4.2 Chrome Print split

边栏推荐
- Investment suggestions for overseas senior players (2) 2021-05-03
- 人生总需要一点激情
- D2admin framework is basically used
- Array -- 27. remove elements
- [acwing] weekly competition
- 小说里的编程 【连载之十九】元宇宙里月亮弯弯
- Use of [golang learning notes] package
- JDBC programming of MySQL
- Programmation JDBC pour MySQL
- Comment forcer complètement le meurtre de processus indépendants de l'arrière - plan?
猜你喜欢

el-select下拉框多选远程搜索反显

Record the process of the first excavation and intersection

STM32单片机使用ADC功能驱动手指检测心跳模块

D1-H 开发板——哪吒 开发入门

Yolo7 mask recognition practice

Crazy bull market, where to go in the second half? 2021-04-30

Microsoft SQL Server database language and function usage (XIII)

【Unity3D日常BUG】Unity3D解决“找不到类型或命名空间名称“XXX”(您是否缺少using指令或程序集引用?)”等问题

Ali onedate's layered thought

Tools in the tools package of Damon database (operate Damon database)
随机推荐
MySQL索引事务
Investment suggestions for overseas senior players (2) 2021-05-03
小说里的编程 【连载之十六】元宇宙里月亮弯弯
Can Verilog of synthetizable be integrated
Use of cjson Library
STM32单片机使用ADC功能驱动手指检测心跳模块
Basic syntax of MySQL DDL and DML and DQL
海外资深玩家的投资建议(2) 2021-05-03
小说里的编程 【连载之二十】元宇宙里月亮弯弯
DeFi项目的盈利逻辑 2021-04-26
Microsoft SQL Server数据库语言及功能使用(十三)
El upload realizes the preview of uploaded files
视频号加强打击低俗内容:对违背公序良俗的内容必须赶尽杀绝
How to reasonably estimate the size of thread pool
Utilisation des fonctions fléchées es6
MySQL的 DDL和DML和DQL的基本语法
The simple use of ADB command combined with monkey is super detailed
Programming in the novel [serial 20] the moon bends in the yuan universe
The ultimate experiment of OSPF -- learn the example of OSPF century template
JS - event proxy and application scenarios