Convert PDF to DOCX in Java using Aspose.PDF - output is blank

@ramanna,

The trail version is only for testing purposes and limited to 30 days. In order to extend the time span, our sales team can guide you better on this. We have created a separate thread in Aspose.Purchase forum. One of our fellow workers will assist you soon there. Please refer to this thread: https://forum.aspose.com/t/can-we-have-the-temporary-license-till-we-get-the-licensed-product/171202

Noted. We are communicating in a separate thread on the temporary license.

We have a query on ASPOSE.WORDS. can I use the same thread to raise my query?

@ramanna,

Please create a new thread in Aspose.Words forum and share all details of the scenario. Aspose.Words API expert will assist you there.

With regard to your response above:

String path = “path/to/my/folder”;
List fontPaths = com.aspose.pdf.Document.getLocalFontPaths();
fontPaths.add(path);
com.aspose.pdf.Document.setLocalFontPaths(fontPaths);

Please advise what are basic font types required by ASPOSE.PDF APIs to convert the document from PDF to WORD?

We would like to highlight that without creating local font path, ASPOSE can still generate the WORD document. Where does the default path or font type reside in APOSE libraries?

Thanks & Regards,

We are having performance impact on our application while saving the WORD document by the below statement:

pdfdoc.save("/mnt/shared/Pega/Enfw/test1.docx", com.aspose.pdf.SaveFormat.DocX)

For one simple PDF to convert into WORD, ASPOSE is taking almost 2 mins. Please advise what could be the reason. Thanks.

Thanks & Regards,

Awaiting your reply

@ramanna,

By default, Aspose.PDF API reads all installed system fonts(from the default system font paths). You can put missing font files into a directory, and then specify the custom font directory in the font folder list as follows:

Java

String path = "path/to/my/folder";
List<String> fontPaths = com.aspose.pdf.Document.getLocalFontPaths();
fontPaths.add(path);
com.aspose.pdf.Document.setLocalFontPaths(fontPaths);

If the font is not available, then Aspose.PDF API uses default fonts and does not break the export process. You need to provide all fonts which are being used in the source PDF document.

Kindly send us your source PDF document and code. We will investigate your scenario and share our findings with you. Your response is awaited.

For the query 1:
What is the default font name that ASPOSE.PDF API uses?

For the query 2: Code is stated below and PDF document is attached
awLic.setLicense(“C:\New folder\Inspire\Pega\Aspose.Words-for-Java-master\Aspose.Total.Java.lic”);
Document pdf = new Document(“C:\New folder\Inspire\Pega\PDF_TO_TEST.pdf”);
PDF_TO_TEST.zip (145.2 KB)
pdf.save(“C:\New folder\Inspire\Pega\PDF_TO_TEST_PDFtoDOC.docx”, SaveFormat.DocX);

@ramanna,

We have tested your source PDF document with the latest version 18.2 of Aspose.PDF for Java API, and it is taking 7 seconds in our environment. Please download and try the latest version 18.2, and then let us know how that goes into your environment.

Well, it depends upon the available fonts on the system.

We are using 18.1 of ASPOSE.PDF for Java API, this should be feasible right? Are there any fixes done at your end to address performance issues in 18.2 version? If so, we will try with this. Please let us know.

Regarding query 1:
Suppose, there is only one font setup in the custom font directory path i.e New Times Roman. The PDF document if it uses the font Courier New and formatting, what will happen to WORD document generation? Will it throw exception error or it will proceed and changes all the PDF fonts to New Times Roman.
Please advise.

@ramanna,

We have tested your scenario with the version 18.1 of Aspose.PDF for Java API, and it is taking 9 seconds in our environment. Please try the following code, and then let us know how that goes into your environment.
Java

long startTime = System.currentTimeMillis();
String basePath = "C:\\Pdf\\test736\\";
Document pdfDocument = new Document(basePath + "PDF_TO_TEST.pdf");
pdfDocument.save(basePath + "Output100.docx", SaveFormat.DocX);
long endTime   = System.currentTimeMillis();
long totalTime = endTime - startTime;
System.out.println(totalTime);

Yes, it will not throw an error and use an available font. You can also embed fonts in the PDF document. Please refer to these help topics: Embedding Fonts in an Existing PDF File and Embedding Fonts while creating PDF

Hi, basically the code u asked us to execute will only give the runtime of the pdfDcoument.save statement. How does this help in troubleshooting the issue? it doesn’t address our problem.

Btw, does your API work the same with or without stream? Below is the code using the stream to read and write the files. We tot stream will improve the performance but still the same. Please advise.

InputStream stream = new FileInputStream(“C:\New folder\Inspire\Pega\PDF_TO_TEST.pdf”);
Document doc = new Document(stream);
stream.close();

ByteArrayOutputStream dstStream = new ByteArrayOutputStream();
doc.save(dstStream, SaveFormat.DocX);

java.io.File file = new java.io.File(“C:\New folder\Inspire\Pega\PDF_TO_TEST_PDFtoDOC1.docx”);
java.io.OutputStream outstream = new java.io.FileOutputStream(file); dstStream.writeTo(outstream);
outstream.close();

@ramanna,

The source code shared in this earlier post is calculating the total conversion time (PDF to DOCX). You might face the problem of slow conversion process due to the environment difference. Kindly send all details of your System environment, including JDK, IDE and Operating System (name and edition). It would be great if you can create a small project application which reproduces the problem of slow conversion into your environment, and then send us a ZIP of this project application.

We have tried your recent code example with version 18.1, and it is taking 8 seconds in our environment.
Java

long startTime = System.currentTimeMillis();
String basePath = "C:\\Pdf\\test736\\";
//Document pdfDocument = new Document(basePath + "PDF_TO_TEST.pdf");
//pdfDocument.save(basePath + "Output101.docx", SaveFormat.DocX);		
InputStream stream = new FileInputStream(basePath + "PDF_TO_TEST.pdf");	
Document doc = new Document(stream);
stream.close();
ByteArrayOutputStream dstStream = new ByteArrayOutputStream();
doc.save(dstStream, SaveFormat.DocX);
java.io.File file = new java.io.File(basePath + "OutputwithStream.docx");	
java.io.OutputStream outstream = new java.io.FileOutputStream(file);
dstStream.writeTo(outstream);	
outstream.close();		
long endTime   = System.currentTimeMillis();
long totalTime = endTime - startTime;
System.out.println(totalTime);

Result (milliseconds):
8379