1. Sample HTML input file and PDF output file attached.
2. Code Snippet:
- 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 outputFile.getAbsolutePath();
}
3. Spire PDF version:
Manifest-Version: 1.0
Extension-Name: spire.pdf
Implementation-Title: spire.pdf for java
Implementation-Version: 4.8.7
Implementation-Vendor: E-iceblue Co., Ltd
Implementation-Vendor-Id: com.spire
4. Application Type: Spingboot JDK 1.8