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.

Thu Aug 22, 2024 6:46 am

We are implementing the HTML to PDF feature using Java.

The PDF is generated correctly on the Windows server.

However, when running the same source on Linux, the PDF is not being generated.

echo "<p>test text</p>" | xvfb-run ./Html2Pdf "placeholder" "xxxxx.pdf" 800 600 0 0 0 0 1

successfully creates a PDF file, so it seems that the plugin installation is not the issue.

The Tomcat server on Linux is running with normal user permissions, and all folder permissions are correct.

What additional areas should be checked?

hdj_11255
 
Posts: 5
Joined: Thu Aug 22, 2024 12:50 am

Thu Aug 22, 2024 8:46 am

Hi,

Thank you for your message.
Could you please confirm if you downloaded the QT plugin from the specific page mentioned below? Additionally, kindly provide your HTML file so that we can conduct further investigation and testing. Your cooperation is highly valued and appreciated. Thank you for your assistance.

https://www.e-iceblue.com/Tutorials/Jav ... o-PDF.html

Sincerely,
Doris
E-iceblue support team
User avatar

Doris.Liu
 
Posts: 353
Joined: Mon Nov 07, 2022 8:10 am

Thu Aug 22, 2024 10:36 pm

The download URL for the Linux version is:

/downloads/plugins/qt-5.14.2-plugins-linux-x64.tar.gz

and

HtmlConverter.convert(<p>test</p>, "/temp/test.pdf", true, 100000, new Size(650, 900), new PdfMargins(0), LoadHtmlType.Source_Code);

HTML string in the Java source code as shown above, it does not work.

I have attached the HTML file as it includes other files such as images.

Thank you.

hdj_11255
 
Posts: 5
Joined: Thu Aug 22, 2024 12:50 am

Fri Aug 23, 2024 6:45 am

I have attached the simplified test Java source code below. I attempted to run it using xvfb-run java -jar, but no error messages were displayed, and the pdf file was not created.



/**
* pdftest.pdf.java
*/
package pdftest;

import com.spire.pdf.graphics.PdfMargins;
import com.spire.pdf.htmlconverter.LoadHtmlType;
import com.spire.pdf.htmlconverter.qt.HtmlConverter;
import com.spire.pdf.htmlconverter.qt.Size;

public class HTMLToPDFConverter {

public static void main(String[] args) {
try {
String outputFileName = "/home/test/test.pdf";
String realPath = "/opt/tomcat/test/project/webapps/ROOT/pdf_plugins";
HtmlConverter.setPluginPath(realPath);
HtmlConverter.convert("<p>test</p>", outputFileName, true, 100000, new Size(650, 900), new PdfMargins(0), LoadHtmlType.Source_Code);

} catch (Exception e) {
e.printStackTrace();
}
}
}

hdj_11255
 
Posts: 5
Joined: Thu Aug 22, 2024 12:50 am

Fri Aug 23, 2024 7:28 am

Hello,

I have tested your file on Linux, but I haven't been able to reproduce the issue you're experiencing. I was able to generate the PDF file successfully on my side.
I suggest you modify the "xxxxx.pdf" in the following command to the output path you have configured in your program and see if it generates the PDF file.

Code: Select all
echo "<p>test text</p>" | xvfb-run ./Html2Pdf "placeholder" "xxxxx.pdf" 800 600 0 0 0 0 1


If the PDF is generated successfully, please test your program with a simple HTML file to see if it can generate the PDF file. If the problem persists, kindly let us know your specific system details (e.g., Ubuntu 20.4), and we would greatly appreciate it.

Sincerely,
Doris
E-iceblue support team
User avatar

Doris.Liu
 
Posts: 353
Joined: Mon Nov 07, 2022 8:10 am

Sun Aug 25, 2024 11:09 pm

Thank you for your assistance.

I have developed an HTML to PDF feature in Java, packaged it as a JAR file, and confirmed that it works correctly when executed with the xvfb command. However, I need this functionality to be executed not as a standalone Java application but as part of another program's workflow.

For example: test.java source >>>> DB search -> (result) -> HTML to PDF -> file attachment

To achieve this, I tried running Tomcat with the xvfb command (xvfb-run ./startup.sh), but HTML to PDF is not working. Are there any aspects I should check or verify?

Thank you as always.

hdj_11255
 
Posts: 5
Joined: Thu Aug 22, 2024 12:50 am

Mon Aug 26, 2024 10:02 am

Hi,

Thank you for your feedback and sorry to reply late for weekend.
Perhaps you can try the following approach, which involves directly invoking the jar package within your code, thereby enabling the use of the xvfb command. If my understanding is incorrect, please provide a more detailed scenario description.

Code: Select all
            ProcessBuilder pb = new ProcessBuilder(
                    "java", "-jar" ,
                    "-DhtmlString=" + htmlString,
                    "-DpluginPath=" + pluginPath,
                    "D:\\testing\\java\\Test_40924.jar");
            Process process = pb.start();


Sincerely,
Doris
E-iceblue support team
User avatar

Doris.Liu
 
Posts: 353
Joined: Mon Nov 07, 2022 8:10 am

Return to Spire.PDF

cron