我面临的问题,在pdf生成时,我转换为pdf的html页的时间按钮也显示,但要求是按钮不应显示,但按钮应在同一页上,点击后pdf应生成。我正在使用itext生成pdf。我用的是百里香和Spring Boot。
我用这个代码生成pdf。
@RequestMapping("download-pdf/{refno}")
public ResponseEntity<?> getPDF(HttpServletRequest request, HttpServletResponse response,@PathVariable("refno") Long refno) throws IOException, IllegalAccessException, InvocationTargetException {
complaintDto = complaintRepo.findById(refno).orElse(null);
complaintPdfBean = pdfService.getComplaintInfo(complaintDto);
WebContext context = new WebContext(request, response, servletContext);
context.setVariable("complaintPdfBean", complaintPdfBean);
String grievanceHtml = templateEngine.process("complant-privew", context);
ByteArrayOutputStream target = new ByteArrayOutputStream();
ConverterProperties converterProperties = new ConverterProperties();
converterProperties.setBaseUri("http://localhost:8080");
HtmlConverter.convertToPdf(grievanceHtml, target, converterProperties);
byte[] bytes = target.toByteArray();
return ResponseEntity.ok().header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=grievance.pdf")
.contentType(MediaType.APPLICATION_PDF).body(bytes);
}
我在pom.xml文件中使用此maven依赖项:
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itext7-core</artifactId>
<version>7.1.0</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>html2pdf</artifactId>
<version>2.0.0</version>
</dependency>
<!-- pdf dependency -->
1条答案
按热度按时间11dmarpk1#
把你的纽扣包起来
<th:block>
和一个th:unless
声明:设置
isPdfExport
上下文变量到true
就在pdf生成之前。