I have search but unable to find anything suitable for converting text along with logo image to another image or PDF. It would be great if both image and Pdf options are there, Just like Banking website.
model.addAttribute("success_message", "Your Reference number is " + referenceNo + ".\nFund Transfer of Amount " + cl.Money(xxDTO.getAmount())
+ " has been made successfully against " + xxDTO.getAccount()
+ " on " + xxDTO.getTime()
+ " from " + xxDTO.getSendAccountNumber()
+ " for " + session.getAttribute("purposeText"));
This is my success message, When funds are transfered, The success messages show on a page inside a div. But I want to add two options there to download as Image or PDF.
How Can I achieve that in Java 11 (Springboot)
I will have to add one static logo at the top and then above text at bottom, and Text format can be changed etc. For testing purpose, I have created a simple HTML file and added a table inside it. It is a static File. I have addded a button and on button click, I am trying to download PDF, Below is code
@requestMapping("/pdf")
public ResponseEntity<?> getPDF(HttpServletRequest request, HttpServletResponse response) throws IOException {
/* Create HTML using Thymeleaf template Engine */
// testingpdf is html view
String orderHtml = templateEngine.process("testingpdf");
/* Setup Source and target I/O streams */
ByteArrayOutputStream target = new ByteArrayOutputStream();
/*Setup converter properties. */
ConverterProperties converterProperties = new ConverterProperties();
converterProperties.setBaseUri("http://localhost:8080");
/* Call convert method */
HtmlConverter.convertToPdf(orderHtml, target, converterProperties);
/* extract output as bytes */
byte[] bytes = target.toByteArray();
/* Send the response as downloadable PDF */
return ResponseEntity.ok()
.contentType(MediaType.APPLICATION_PDF)
.body(bytes);
}
POM FILE
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>kernel</artifactId>
<version>7.1.12</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>html2pdf</artifactId>
<version>3.0.1</version>
</dependency>
The above is already in my pom.xml but these import are not working.
import com.itextpdf.html2pdf.ConverterProperties;
import com.itextpdf.html2pdf.HtmlConverter;