Java Class not Found after import : com.spire.doc.Document

Hi All,

I imported Spire.Doc Java library for my requirement of Convert Docx stream to PDf stream by using this library. all the clsses are imported and able to access but Below class also deployed but not able to locate it in Pega.

Class: com.spire.doc.Document

Error: Failed to retrieve Java class location

If i use this class references in my function, I am not getting compilation errors but the code is not executing.

Example code:

try{
byte DocBytes2 = Base64.getDecoder().decode(DocStream);
ByteArrayInputStream instream = new ByteArrayInputStream(DocBytes2);
ByteArrayOutputStream pdfstream = new ByteArrayOutputStream();

Document document = new Document();
document.loadFromStream(instream, FileFormat.Docx);
document.saveToStream(pdfstream, FileFormat.PDF);

return pdfstream;
}
catch (Exception e) {

String Error = e.toString();

return Error;
}

@SANTOSHKUAMR V It seems like you are facing an issue with locating the com.spire.doc.Document class in Pega after importing the Spire.Doc Java library. This issue might be similar to the one discussed in the context where users faced issues with imported jars not being recognized in Pega. One suggested approach is to create a Library declare the packages and classes to import and then create a Function to do what you need. Once the Function is compiled you should be able to use it. This method has been found to work for similar issues.

:warning: This is a GenAI-powered tool. All generated answers require validation against the provided references.

Unable to use imported Jar in java step in an activity

@MarijeSchillern , As suggested I tried that option. Function and library complied successfully, But runtime that line of code in the function is not executing. No errors in the logs as well. Completely strange behavior.

We also tried another Java package, but there also facing issue - conversion was sucessful but FONT getting changed.

Looks like Pega don’t have solution to convert the DOCx document to PDF document. We may have to go for another approach which is out of Pega.

@SANTOSHKUAMR V Pega does not currently provide an out of the box (OOTB) solution to convert DOCx documents to PDF. However there are discussions about this feature being evaluated for future releases. Users have shared experiences with using Java code to implement conversions but these approaches may have limitations. For example one user mentioned using a base64 stream to convert Word documents to PDF in Pega 8.4.3. Additionally while Pega Robotics can save Word documents as PDFs it does not have a specific component for direct PDF creation from text or HTML content.

:warning: This is a GenAI-powered tool. All generated answers require validation against the provided references.

Convert Docx (Word document) to PDF in 8.1 and above

Ask the Expert - Pega and PDFs with Rahul Bojanapally and Sangeeta Kottilinga

@SangeetaKottilinga I am trying to attach an official Product Enhancement Request work ID to this question but have not found a single entity that encompasses the considered work.

Based on your answer in the above Ask the Expert session, please can you provide the active FDBK/ US?

There is no information why the following items were recently closed with no action:

FDBK-25889 ( Amyuni Word to PDF converter replacement)

FDBK-26944 (Enhancement request - docx to PDF conversion service)

US-363406 (Converting platform generated DOCX to PDF)

What is the ID of an open AS item?