当前位置:网站首页>Use itextpdf to intercept the page to page of PDF document and divide it into pieces
Use itextpdf to intercept the page to page of PDF document and divide it into pieces
2022-04-23 16:31:00 【Yangge landing】
itextpdf Implement interception pdf From page to page of the document
cause :pdf Document too large ,100M above , The front end cannot be displayed at all . Solution , Back end pdf Document slicing operation , For example, ten pages are sent to the front end .
1. Use itextpdf
Import dependence
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.13</version>
</dependency>
2. Business logic
@GetMapping("/download")
public void pdf(@RequestParam(value = "page", required = false) String page, HttpServletResponse response) throws IOException, DocumentException {
// File path
path = "C:\\Users\\pdf file .pdf"";
// Read pdf file
PdfReader reader = new PdfReader(path);
// Total number of pages
int numberOfPages = reader.getNumberOfPages();
// Intercept the start page
int start = Integer.parseInt(page.substring(0, 1));
// Intercept pdf Partial page , Format "2-5" The first 2 To the first page 5 page Page number out of range (10 page , You choose "15-20") Can only read the last page
// Parameter is String type , Allow the front end to transmit value , Control which page to read
// reader.selectPages("2-5");
reader.selectPages(page);
// I don't understand the source code very much , But you need to store the file stream in memory , So use the HttpServletResponse
PdfStamper stamp = new PdfStamper(reader, response.getOutputStream());
// Start page If it is greater than pdf Total number of pages , Do not return file stream ,stamp.close() The result returned to 1
if(start <= numberOfPages){
stamp.close();
}
reader.close();
}
3. result
More than a thousand pages of documents , I choose to intercept 1-5 page , Then it will only show 1,2,3,4,5 These pages
版权声明
本文为[Yangge landing]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231402542936.html
边栏推荐
- Findstr is not an internal or external command workaround
- There is a problem with the light switch from 1 to 100
- The solution of not displaying a whole line when the total value needs to be set to 0 in sail software
- 05 Lua control structure
- 5分钟NLP:Text-To-Text Transfer Transformer (T5)统一的文本到文本任务模型
- Esxi encapsulated network card driver
- Sail soft segmentation solution: take only one character (required field) of a string
- Cartoon: what are IAAs, PAAS, SaaS?
- Day (5) of picking up matlab
- [pyGame games] how did angry birds, a mobile game that became popular all over the world 10 years ago, dominate the list? Classic return
猜你喜欢
JMeter setting environment variable supports direct startup by entering JMeter in any terminal directory
Hyperbdr cloud disaster recovery v3 Version 2.1 release supports more cloud platforms and adds monitoring and alarm functions
Meaning and usage of volatile
The font of the soft cell changes color
100 deep learning cases | day 41 - convolutional neural network (CNN): urbansound 8K audio classification (speech recognition)
各大框架都在使用的Unsafe类,到底有多神奇?
建站常用软件PhpStudy V8.1图文安装教程(Windows版)超详细
Hypermotion cloud migration completes Alibaba cloud proprietary cloud product ecological integration certification
Gartner 发布新兴技术研究:深入洞悉元宇宙
Set cell filling and ranking method according to the size of the value in the soft report
随机推荐
On the value, breaking and harvest of NFT project
VMware Workstation cannot connect to the virtual machine. The system cannot find the specified file
Questions about disaster recovery? Click here
MySQL的btree索引和hash索引区别
OAK-D树莓派点云项目【附详细代码】
Summary according to classification in sail software
安装及管理程序
Construction of esp32 compilation environment
NVIDIA显卡驱动报错
[key points of final review of modern electronic assembly]
JMeter setting environment variable supports direct startup by entering JMeter in any terminal directory
GRBL学习(二)
Cloudy data flow? Disaster recovery on cloud? Last value content sharing years ago
logback的配置文件加载顺序
RAID磁盘阵列与RAID5的创建
How to quickly batch create text documents?
Passing header request header information between services through feign
[pyGame games] how did angry birds, a mobile game that became popular all over the world 10 years ago, dominate the list? Classic return
About JMeter startup flash back
Creation of RAID disk array and RAID5