2.
- Code: Select all
public static String convertHtmlToPdf(String htmlString) throws IOException {
Path tempFile = Files.createTempFile("output", ".html");
try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(tempFile.toFile().getPath()),
StandardCharsets.UTF_8)) {
writer.append(htmlString);
writer.newLine();
} catch (IOException e) {
throw e;
}
logger.info("temp file created: " + tempFile.toFile().getPath());
File outputFile = File
.createTempFile("output_pdf_" + new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date()), ".pdf");
// Set license key
com.spire.license.LicenseProvider.setLicenseKey(LICENSE_KEY);
// Set plugin path
HtmlConverter.setPluginPath(PLUGIN_PATH);
// Convert HTML string to PDF
HtmlConverter.convert(tempFile.toFile().getPath().toString(), new FileOutputStream(outputFile), true,
1000000000, new Size(700, 900), new PdfMargins(40, 40, 40, 40));
logger.info("outputResource.getFile().length() " + outputFile.length());
return addPageNumberToPDF(outputFile.getAbsolutePath());
}
Manifest-Version: 1.0
Extension-Name: spire.office
Implementation-Title: spire.office for java
Implementation-Version: 8.10.2
Implementation-Vendor: E-iceblue Co., Ltd.
Implementation-Vendor-Id: com.spire
Implementation-URL: https://www.e-iceblue.com
4. Application Type: Spingboot JDK 1.8