Hello,
I'm trying to convert HTML to PDF, But it's not generating PDF file. There is no error or exception observed.
1. Sample HTML files attachned
2. Code Snippet:
public static void main(String args[]) {
try {
com.spire.license.LicenseProvider.setLicenseKey(LICENSE_KEY);
// Invoke the custom method HtmlToString() to convert HTML file to string
String htmlString = HtmlToString(HTML_PATH);
// Specify the output file path
String outputFile = TEMP_PATH + "HtmlToPdfhindi4.pdf";
// Specify the plugin path
String pluginPath = PLUGIN_PATH;
// Set the plugin path
HtmlConverter.setPluginPath(pluginPath);
// Convert the HTML string to PDF
HtmlConverter.convert(htmlString, outputFile, true, 100000, new Size(700, 900), new PdfMargins(0),
LoadHtmlType.Source_Code);
System.out.println("outputResource.getFile().length() " + new File(outputFile).length());
} catch (Exception e) {
e.printStackTrace();
}
}
// Convert a HTML file to string
public static String HtmlToString(String filePath) throws IOException {
// String path = filePath;
Path path = Paths.get(filePath);
File file = new File(filePath);
FileReader fileReader = new FileReader(file);
BufferedReader bufferedReader = Files.newBufferedReader(path, StandardCharsets.UTF_8);
StringBuilder stringBuilder = new StringBuilder();
String temp = "";
while ((temp = bufferedReader.readLine()) != null) {
stringBuilder.append(temp + "\n");
}
bufferedReader.close();
String str = stringBuilder.toString();
System.out.println("String " + str);
return str;
}
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