- Code: Select all
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.doc</artifactId>
<version>12.11.0</version>
</dependency>
<repository>
<id>com.e-iceblue</id>
<name>e-iceblue</name>
<url>https://repo.e-iceblue.com/nexus/content/groups/public/</url>
</repository>
When using a Java program to convert a DOCX file to PDF, the resulting PDF file size is 0 bytes. When trying to open it with WPS, the error message appears: "The file type is not supported or the file is corrupted, filename: xxxx.pdf." Meanwhile, the Java program hangs in the conversion function, unable to complete for an extended period, with CPU usage continuously increasing as if it is stuck in an infinite loop. The protection type is also set to No_Protection.
However, the conversion works successfully when using the Live Demo.
- Code: Select all
@SpringBootApplication
public class ConvertWordToPdfApplication {
public static void main(String[] args) {
// Create a Document object
Document doc = new Document();
// Load a Word document
doc.loadFromFile("C:\\Users\\12627\\Desktop\\doc\\7a66b2d4.docx");
ProtectionType type = doc.getProtectionType();
System.out.println("ProtectionType: " + type);
// Save the document to PDF
doc.saveToFile("C:\\Users\\12627\\Desktop\\doc\\ToPDF.pdf", FileFormat.PDF);
// Dispose resources
doc.dispose();
System.out.println("OK");
}
}
The result of the pringln:
- Code: Select all
ProtectionType: No_Protection
But it gets stuck in the saveToFile function. I previously used the getPageCount function, and the program also froze for several minutes.And there are no exceptions or error messages in the program.