Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Mon Apr 03, 2023 10:37 am

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

Dasgupta
 
Posts: 54
Joined: Fri Mar 11, 2022 9:14 am

Tue Apr 04, 2023 9:24 am

Hi,

Thanks for your feedback.
I tested your Html file by using the following code, it could converted successfully. I have packaged my program to a JAR file. Please unzip it, put the plugins file at the same folder, and then use "java -jar ..." to run it at your side. It is based on JDK 1.8. If your issue still exists after testing, please provide your system information (E.g. Win10, 64 bit) and region setting (E.g. China, Chinese) for further testing.
Code: Select all
        HtmlConverter.setPluginPath("plugins");
        // Convert the HTML file to PDF
        HtmlConverter.convert("working.html", "output.pdf", true, 100000, new Size(700, 900), new PdfMargins(0));

Best Regards,
Herman
E-iceblue support team
User avatar

Herman.Yan
 
Posts: 115
Joined: Wed Mar 08, 2023 2:00 am

Wed Apr 05, 2023 8:24 am

Hello,

I have extracted, added plugins to extracted folder and tested the code.
But, it's giving output.pdf file which is pdf version of working.html.
I have provided working.html (working as expected) and not_working.html (not generating pdf of HTML and having issues with this) in PoC.zip

Can you also check with not_working.html file.

Please find attachment for performed steps and details of OS and Regions setting.

Dasgupta
 
Posts: 54
Joined: Fri Mar 11, 2022 9:14 am

Wed Apr 05, 2023 8:45 am

Hello,

Thank you for your feedback.

We are on Chinese Tomb-Sweeping Day holiday today, there is currently no testing environment for you. After I return to the office tomorrow, I will use your testing environment to test the project and provide you with the results.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Thu Apr 06, 2023 3:17 am

Hello,

Thank you for your feedback.
Actually, my previous 'JAR file' has checked the 'not_working.html' file, since I modified the file name to 'working.html'. You can check the output PDF content. Meanwhile, you can change your other html file name to this name and use my JAR file to test them. If there is any other issues, just feel free to contact.

Best Regards,
Herman
E-iceblue support team
User avatar

Herman.Yan
 
Posts: 115
Joined: Wed Mar 08, 2023 2:00 am

Thu Apr 06, 2023 2:45 pm

Hello,

When I ran attached html with your test.jar as 'java -jar test.jar' i can get pdf file generated.

Where as when i try to generate in local with
Code: Select all
public static void main(String args[]) {
      try {
         com.spire.license.LicenseProvider.setLicenseKey(LICENSE_KEY);
         String htmlString = HtmlToString(HTML_PATH);
         String outputFile = TEMP_PATH + "genrated.pdf";
         String pluginPath = PLUGIN_PATH;
         // Set the plugin path
         HtmlConverter.setPluginPath(pluginPath);
         System.out.println("outputFile " + outputFile);
         HtmlConverter.convert(htmlString, outputFile, true, 100000, new Size(700, 900), new PdfMargins(0));
         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;
        File file = new File(path);
        FileReader fileReader = new FileReader(file);
        BufferedReader bufferedReader = new BufferedReader(fileReader);
        StringBuilder stringBuilder = new StringBuilder();
        String temp = "";
        while ((temp = bufferedReader.readLine()) != null) {
            stringBuilder.append(temp + "");
        }
        bufferedReader.close();
        String str = stringBuilder.toString();
        return str;
    }

it gives me below error
Code: Select all
class com.spire.pdf.packages.sprLyB: Illegal characters in path.
com.spire.pdf.packages.sprBdc.spr  (Path.java:293)
com.spire.pdf.packages.sprOla.spr  (Unknown Source)
com.spire.pdf.packages.sprFJa.spr  (Unknown Source)
com.spire.pdf.htmlconverter.qt.HtmlConverter.convert(Unknown Source)
com.spire.pdf.htmlconverter.qt.HtmlConverter.convert(Unknown Source)
com.liferay.rbi.rbiHtmlToPdfSpire.portlet.SpireMain.main(SpireMain.java:47)
   at com.spire.pdf.packages.sprBdc.spr  (Path.java:293)
   at com.spire.pdf.packages.sprOla.spr  (Unknown Source)
   at com.spire.pdf.packages.sprFJa.spr  (Unknown Source)
   at com.spire.pdf.htmlconverter.qt.HtmlConverter.convert(Unknown Source)
   at com.spire.pdf.htmlconverter.qt.HtmlConverter.convert(Unknown Source)
   at com.liferay.rbi.rbiHtmlToPdfSpire.portlet.SpireMain.main(SpireMain.java:47)


In local I'm using below jdk
Code: Select all
openjdk version "1.8.0_362"
OpenJDK Runtime Environment (Zulu 8.68.0.20-SA-win64) (build 1.8.0_362-b08)
OpenJDK 64-Bit Server VM (Zulu 8.68.0.20-SA-win64) (build 25.362-b08, mixed mode)

Dasgupta
 
Posts: 54
Joined: Fri Mar 11, 2022 9:14 am

Fri Apr 07, 2023 10:34 am

Hi,

Thanks for your message.
Your error could be avoided by adding "LoadHtmlType.Source_Code". But It also can not generate the PDF file. I have logged this issue into our tracking system with the ticket SPIREPDF-5913, our Dev team will do further investigation and fixing. Once there is any update, we will keep you informed. Sorry for the inconvenience caused.We suggest that you use my previous code to do the conversion.If there is any other issues, just feel free to contact.

Best Regards,
Herman
E-iceblue support team
User avatar

Herman.Yan
 
Posts: 115
Joined: Wed Mar 08, 2023 2:00 am

Wed Apr 12, 2023 8:00 am

Hello,

Do you have any updates on this issue? Please share.

Dasgupta
 
Posts: 54
Joined: Fri Mar 11, 2022 9:14 am

Wed Apr 12, 2023 10:21 am

Hi,

Thank you for following up.
Sorry that there is no update at present. Our development team is working hard to fix this issue. How about your testing result when you test my previous code in your project?

Best Regards,
Herman
E-iceblue support team
User avatar

Herman.Yan
 
Posts: 115
Joined: Wed Mar 08, 2023 2:00 am

Thu Apr 13, 2023 8:35 am

Hello,

Below is the result of testing with your code.

Dasgupta wrote:Hello,

When I ran attached html with your test.jar as 'java -jar test.jar' i can get pdf file generated.

Where as when i try to generate in local with
Code: Select all
public static void main(String args[]) {
      try {
         com.spire.license.LicenseProvider.setLicenseKey(LICENSE_KEY);
         String htmlString = HtmlToString(HTML_PATH);
         String outputFile = TEMP_PATH + "genrated.pdf";
         String pluginPath = PLUGIN_PATH;
         // Set the plugin path
         HtmlConverter.setPluginPath(pluginPath);
         System.out.println("outputFile " + outputFile);
         HtmlConverter.convert(htmlString, outputFile, true, 100000, new Size(700, 900), new PdfMargins(0));
         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;
        File file = new File(path);
        FileReader fileReader = new FileReader(file);
        BufferedReader bufferedReader = new BufferedReader(fileReader);
        StringBuilder stringBuilder = new StringBuilder();
        String temp = "";
        while ((temp = bufferedReader.readLine()) != null) {
            stringBuilder.append(temp + "");
        }
        bufferedReader.close();
        String str = stringBuilder.toString();
        return str;
    }

it gives me below error
Code: Select all
class com.spire.pdf.packages.sprLyB: Illegal characters in path.
com.spire.pdf.packages.sprBdc.spr  (Path.java:293)
com.spire.pdf.packages.sprOla.spr  (Unknown Source)
com.spire.pdf.packages.sprFJa.spr  (Unknown Source)
com.spire.pdf.htmlconverter.qt.HtmlConverter.convert(Unknown Source)
com.spire.pdf.htmlconverter.qt.HtmlConverter.convert(Unknown Source)
com.liferay.rbi.rbiHtmlToPdfSpire.portlet.SpireMain.main(SpireMain.java:47)
   at com.spire.pdf.packages.sprBdc.spr  (Path.java:293)
   at com.spire.pdf.packages.sprOla.spr  (Unknown Source)
   at com.spire.pdf.packages.sprFJa.spr  (Unknown Source)
   at com.spire.pdf.htmlconverter.qt.HtmlConverter.convert(Unknown Source)
   at com.spire.pdf.htmlconverter.qt.HtmlConverter.convert(Unknown Source)
   at com.liferay.rbi.rbiHtmlToPdfSpire.portlet.SpireMain.main(SpireMain.java:47)


In local I'm using below jdk
Code: Select all
openjdk version "1.8.0_362"
OpenJDK Runtime Environment (Zulu 8.68.0.20-SA-win64) (build 1.8.0_362-b08)
OpenJDK 64-Bit Server VM (Zulu 8.68.0.20-SA-win64) (build 25.362-b08, mixed mode)

Dasgupta
 
Posts: 54
Joined: Fri Mar 11, 2022 9:14 am

Fri Apr 14, 2023 3:54 am

Hi,

Thanks for your message.
I noticed that you did test my previous JAR file which I used the following code.
Code: Select all
    public static void main(String[] args) throws IOException {
        String pluginPath = "plugins";
        HtmlConverter.setPluginPath(pluginPath);
        HtmlConverter.convert("not_working.html", "output.pdf", true, 100000, new Size(700, 900), new PdfMargins(0));
    }

What I mean is that you directly use this code for your project. I look forward to your test results.

Best Regards,
Herman
E-iceblue support team
User avatar

Herman.Yan
 
Posts: 115
Joined: Wed Mar 08, 2023 2:00 am

Wed Apr 19, 2023 4:17 pm

Hello,

do we have any update on the above issue?
This issue mainly seems with HTML with large sizes.

I tried below code:
Code: Select all
         com.spire.license.LicenseProvider.setLicenseKey(LICENSE_KEY);
              String htmlString = HtmlToString(HTML_PATH);
         String outputFile = TEMP_PATH + "genrated.pdf";
         String pluginPath = PLUGIN_PATH;
         HtmlConverter.setPluginPath(pluginPath);
         HtmlConverter.convert(htmlString, outputFile, true, 100000, new Size(700, 900), new PdfMargins(0));


and I am getting below error:

Code: Select all
class com.spire.pdf.packages.sprLyB: Illegal characters in path.
com.spire.pdf.packages.sprBdc.spr  (Path.java:293)
com.spire.pdf.packages.sprOla.spr  (Unknown Source)
com.spire.pdf.packages.sprFJa.spr  (Unknown Source)
com.spire.pdf.htmlconverter.qt.HtmlConverter.convert(Unknown Source)
com.spire.pdf.htmlconverter.qt.HtmlConverter.convert(Unknown Source)
com.liferay.rbi.rbiHtmlToPdfSpire.portlet.SpireMain.main(SpireMain.java:51)
   at com.spire.pdf.packages.sprBdc.spr  (Path.java:293)
   at com.spire.pdf.packages.sprOla.spr  (Unknown Source)
   at com.spire.pdf.packages.sprFJa.spr  (Unknown Source)
   at com.spire.pdf.htmlconverter.qt.HtmlConverter.convert(Unknown Source)
   at com.spire.pdf.htmlconverter.qt.HtmlConverter.convert(Unknown Source)
   at com.liferay.rbi.rbiHtmlToPdfSpire.portlet.SpireMain.main(SpireMain.java:51)


Also when I tried with below code with small and large size HTML Small HTML processed successfully whereas large HTML is not processed with no error. (where as content of both pdf are same only repetitive content in large pdf)

Code: Select all
com.spire.license.LicenseProvider.setLicenseKey(LICENSE_KEY);
              String htmlString = HtmlToString(HTML_PATH);
         String outputFile = TEMP_PATH + "genrated.pdf";
         String pluginPath = PLUGIN_PATH;
         HtmlConverter.setPluginPath(pluginPath);
         HtmlConverter.convert(htmlString, outputFile, true, 100000, new Size(700, 900), new PdfMargins(0), LoadHtmlType.Source_Code);


Attaching sample html.

Dasgupta
 
Posts: 54
Joined: Fri Mar 11, 2022 9:14 am

Thu Apr 20, 2023 11:31 am

Hi,

Thanks for your feedback.
I have tested your HTML file and it is true as you mentioned that 'working. html' can be converted to PDF, while 'not_working'big. html' cannot be converted. I have already informed our developers of this phenomenon. Since the conversion process used the third-party plugins, our developers need more time to investigate. At the same time, I found that the first parameter of the HtmlConverter. convert() method is directly set to the position of 'not_working'big. html', as shown in the screenshot below.
1.png

We can generate a PDF file. You can firstly use this way instead.

Best Regards,
Herman
E-iceblue support team
User avatar

Herman.Yan
 
Posts: 115
Joined: Wed Mar 08, 2023 2:00 am

Sun Apr 23, 2023 2:13 pm

Hello,

I tried with the file path of not_working_big.html as 1st param for HtmlConverter. convert() method and it worked, But we are using this HTML to PDF library in API where we get HTML string which we pass for conversion. So, in this case, when the HTML string is large it doesn't convert it to PDF.

I tried saving the HTML string to a temp file first and then providing the file URL to the method but again it will consume space on the server.

Dasgupta
 
Posts: 54
Joined: Fri Mar 11, 2022 9:14 am

Mon Apr 24, 2023 7:23 am

Hello,

Thank you for your feedback.
We have understood that the method of setting "not_working_big.html" as 1st param for HtmlConverter.convert() isn't available for your situation. Regarding the issue of directly loading HTML string, our Dev team are working on it now. Once we receive their any feedback, we will inform you promptly. Thank you for your patience.

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1533
Joined: Wed Apr 25, 2018 3:20 am

Return to Spire.PDF

cron