parent
63d68cb4c6
commit
441ba06176
@ -0,0 +1,60 @@
|
||||
package com.ruoyi.web.controller.pdf.controller;
|
||||
|
||||
import com.ruoyi.web.controller.pdf.service.ChangePdfService;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@RestController
|
||||
@RequestMapping("/api/ChangePdf")
|
||||
public class ChangePdfController {
|
||||
private final ChangePdfService ChangePdfService;
|
||||
|
||||
public ChangePdfController(ChangePdfService changePdfService) {
|
||||
this.ChangePdfService = changePdfService;
|
||||
}
|
||||
|
||||
@PostMapping(value = "/ChangeFill", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public ResponseEntity<byte[]> fillPdfForm(
|
||||
@RequestParam(required = false) String name,
|
||||
@RequestParam(required = false) String sex,
|
||||
@RequestParam(required = false) String phone,
|
||||
@RequestParam(required = false) String smPost,
|
||||
@RequestParam(required = false) String smGrade,
|
||||
@RequestParam(required = false) MultipartFile photo) throws Exception {
|
||||
|
||||
// 构建表单数据
|
||||
Map<String, String> formData = new HashMap<>();
|
||||
if (name != null) formData.put("姓名", name);
|
||||
if (sex != null) formData.put("性别", sex);
|
||||
if (phone != null) formData.put("联系电话", phone);
|
||||
if (smPost != null) formData.put("涉密岗位", smPost);
|
||||
if (smPost != null) formData.put("原涉密等级", smGrade);
|
||||
|
||||
// 构建图片数据
|
||||
Map<String, MultipartFile> imageData = new HashMap<>();
|
||||
if (photo != null && !photo.isEmpty()) {
|
||||
imageData.put("照片", photo);
|
||||
}
|
||||
|
||||
// 生成PDF
|
||||
ByteArrayOutputStream outputStream = ChangePdfService.fillForm(formData, imageData);
|
||||
|
||||
// 返回PDF文件
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_PDF);
|
||||
headers.setContentDispositionFormData("attachment", "output.pdf");
|
||||
|
||||
return ResponseEntity.ok()
|
||||
.headers(headers)
|
||||
.body(outputStream.toByteArray());
|
||||
}
|
||||
}
|
Loading…
Reference in new issue