Error when converting pdf file to word file

Hi,
We are encountering the following error in one of our reports only on the servers when converting a PDF to a Word document. The conversion works fine locally.

We are using:

  • Java version: 17.0.9
  • Aspose libraries: latest version
  • Operating system: Linux

Could you please help us investigate this issue?

org.mozilla.javascript.WrappedException: Wrapped class com.aspose.pdf.internal.ms.System.lh: Invalid parameter used.
com.aspose.pdf.internal.l66j.l0k.lj(Unknown Source)
com.aspose.pdf.internal.l66j.l0k.lj(Unknown Source)
com.aspose.pdf.internal.l66p.l2p.lj(Unknown Source)
com.aspose.pdf.internal.l66p.l2p.lf(Unknown Source)
com.aspose.pdf.internal.l66p.l2p.lI(Unknown Source)
com.aspose.pdf.internal.l66p.l2p.lt(Unknown Source)
com.aspose.pdf.internal.l66p.l2p.lI(Unknown Source)
com.aspose.pdf.internal.l26l.lj.visitPathEnd(Unknown Source)
com.aspose.pdf.internal.foundation.rendering.l2if.accept(Unknown Source)
com.aspose.pdf.internal.foundation.rendering.l0if.accept(Unknown Source)
com.aspose.pdf.internal.foundation.rendering.lv.accept(Unknown Source)
com.aspose.pdf.internal.foundation.rendering.l0if.accept(Unknown Source)
com.aspose.pdf.internal.foundation.rendering.lv.accept(Unknown Source)
com.aspose.pdf.internal.l26l.lj.lI(Unknown Source)
com.aspose.pdf.internal.l96f.le.lI(Unknown Source)
com.aspose.pdf.internal.l18p.ld.lI(Unknown Source)
com.aspose.pdf.internal.l18p.lv.lI(Unknown Source)
com.aspose.pdf.internal.l18p.lb.lf(Unknown Source)
com.aspose.pdf.internal.l18t.lj.lI(Unknown Source)
com.aspose.pdf.internal.l3if.lf.lI(Unknown Source)
com.aspose.pdf.l1p.lI(Unknown Source)
com.aspose.pdf.l1p.lI(Unknown Source)
com.aspose.pdf.ADocument.ld(Unknown Source)
com.aspose.pdf.ADocument.lt(Unknown Source)
com.aspose.pdf.ADocument.lI(Unknown Source)
com.aspose.pdf.Document.lI(Unknown Source)
com.aspose.pdf.ADocument.lI(Unknown Source)
com.aspose.pdf.ADocument.save(Unknown Source)
com.aspose.pdf.Document.save(Unknown Source)
jdk.internal.reflect.GeneratedMethodAccessor1157.invoke(Unknown Source)
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.base/java.lang.reflect.Method.invoke(Method.java:568)
org.mozilla.javascript.MemberBox.invoke(MemberBox.java:220)
org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:284)

@minaeimi

Would you please make sure that all fonts are present on the server just like they are in the local environment where no error is occurring? In case issue still persists, please share your sample PDF document with some more details of server and code sample. We will log an investigation ticket and share the ID with you.

it works for other reports even with the same font. We use font Helvetica
image.png (15.8 KB)
But yes this font doesnot exist on the servers

@minaeimi

Would you please try after installing the particular font on server and check again. If issue still persists, please share some details as per our request in previous message so that we can further proceed accordingly.

Hi @asad.ali I am not sure if it is the same issue or not, if we convert a pdf file to the word document, while the pdf contains a signature, in word document signature moves to another place. Again it works fine locally but not on the servers.

this is the code we are using:

function onActionExportToWord(event) {
	var locale = new java.util.Locale('en', 'US');
	java.util.Locale.setDefault(locale);

	/** @type {Packages.com.aspose.pdf.Document} */
	var doc = new Packages.com.aspose.pdf.Document(uploadedFile);

	var license = new Packages.com.aspose.pdf.License();
	// Call setLicense method to set license
	license.setLicense("Aspose.Pdf.Java.lic");

	var FILE_DOWLOAD_PATH = plugins.file.getDefaultUploadLocation() + scopes.svyIO.getFileSeperator();

	var wordFile = FILE_DOWLOAD_PATH + uploadedFile.getName().replace('.pdf', '.docx');

	plugins.webnotificationsToastr.info('This may take several minutes to convert, please wait!');

	var options = new Packages.com.aspose.pdf.DocSaveOptions();

	// Set output format xlsx and 1 worksheet
	options.setFormat(Packages.com.aspose.pdf.DocSaveOptions.DocFormat.DocX);

	doc.save(wordFile, options);

	var fbytes = plugins.file.readFile(wordFile);
	plugins.file.writeFile(uploadedFile.getName().replace('.pdf', '.docx'), fbytes, 'application/vnd.openxmlformats-officedocument.wordprocessingml.document');

}

here you can see the pdf file:
test_report.pdf (144.2 KB)

and the word document which is result of above conversion:
test_report.docx (101.0 KB)

I should add we installed Helvetica font on the server but it didn’t help.

@minaeimi

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PDFJAVA-45157

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@asad.ali does this ticket for both above issues?

@minaeimi

No, this ticket only addresses the issue about signature’s position in the output. For the issue mentioned in the first post, have you still faced it after installing the fonts? And can you please share sample file for it as well?

@asad.ali

yes, the issue is persist.

@minaeimi

Can you please provide a sample PDF to reproduce the same issue?

@asad.ali sure attached you can find the document. Can you please advise why both reports work locally but not on the servers considering we uploaded required fonts on the servers?

test2.pdf (5.9 KB)

@minaeimi

Apparently, the issue looks related to the missing font that API is not able to find or locate the font in system. Have you tried adding font directories as below?

FontSource fs = new FolderFontSource("{Path tocustomfonts}");
FontRepository.getSources().add(fs);

Hi @asad.ali is following code correct? I mean the classes we are using?

// Use the absolute Linux path to your fonts directory
	var fontFolder = '/usr/share/fonts/';

	var FolderFontSource = Packages.com.aspose.words.FolderFontSource;
    var FontRepository = Packages.com.aspose.words.FontSettings.getDefaultInstance();

    // Replace this with your actual path (absolute path required)

    // Create font source and add to the repository
    var fontSource = new FolderFontSource(fontFolder, true); // true = include subfolders
    var sources = FontRepository.getFontsSources();
    
    sources.concat(fontSource)
    FontRepository.setFontsSources(sources);

image.png (64.5 KB)

@minaeimi

Since you need to set the fonts for Aspose.PDF, you will have to use com.aspose.pdf namespace like below:

com.aspose.pdf.FontSource fs = new com.aspose.pdf.FolderFontSource(dataDir  + "customfonts\\");
com.aspose.pdf.FontRepository.getSources().add(fs);

@asad.ali thanks but we are still getting the same issue for both issues. I still cannot understand why it works locally not on the servers.

@minaeimi

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PDFJAVA-45160

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.