Springboot 整合 itext 实现PDF文件合并,识别图片则转成PDF拼接
目录
- 前言
- 一、引用依赖
- 二、使用步骤
-
- 1.Controller
- 2.Service接口
- 3.实现类
- 三、请求接口及结果
前言
本文实现 Springboot 整合 itext 实现PDF文件合并,图片转PDF拼接。
一、引用依赖
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itext7-core</artifactId>
<version>8.0.5</version>
<type>pom</type>
</dependency>
二、使用步骤
1.Controller
代码如下(示例):
import com.ruoyi.tools.service.IPdfHandlerService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
@RestController
@RequiredArgsConstructor
@RequestMapping("/pdf")
public class PdfHandlerController {
private final IPdfHandlerService pdfHandlerService;
@PostMapping(value = "/generateFromFiles", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public void uploadFiles(@RequestPart("files") List<MultipartFile> files, HttpServletResponse response) throws Exception {
byte[] pdfBytes = pdfHandlerService.generatePdfFromFiles(files