We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

java.lang.InternalError: java.lang.reflect.InvocationTargetException

Hi there,
We are using Aspose PDF 22.6 to convert Images to PDF.
We are using the following code -
public static byte[] imagetopdf(ByteArrayInputStream input, String extension) throws Exception {
ByteArrayOutputStream result = new ByteArrayOutputStream();
try {
// Initialize document object
com.aspose.pdf.Document document = new com.aspose.pdf.Document();

            Page page = document.getPages().add();
            Image image = new Image();

            // Load sample JPEG image file
            image.setImageStream(input);
            page.getParagraphs().add(image);

            // Save output PDF document
            document.save(result);
            return result.toByteArray();
        } catch (Exception ex) {
            LOGGER.error("Exception occurred while converting Image to pdf :", ex);
            throw ex;
        } finally {
            result.close();
        }
    }

On windows (local setup) this works flawlessly, but on RHEL7 environment, every call fails with -
{

    "message": "org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.InternalError: java.lang.reflect.InvocationTargetException"

}

I have another ticket open here
I think the common factor here is the image. But, we also use Aspose Docs to convert docx to PDFs and documents with images get converted successfully.

Please help! :slight_smile:

UPDATE -
Upon @Peyton.Xu 's suggestion, we have added fontconfig to our environment. It solved the Excel to Pdf conversion issue.
But Image to PDF error just changed from the OP to -

com.aspose.pdf.internal.ms.System.l6n: Cannot find any fonts installed on the system.
 at com.aspose.pdf.internal.l26n.lv.lI(Unknown Source) ~[aspose-pdf-22.6.jar!/:na]
 at com.aspose.pdf.internal.l26n.lv.lI(Unknown Source) ~[aspose-pdf-22.6.jar!/:na]
 at com.aspose.pdf.internal.l26n.lv.lI(Unknown Source) ~[aspose-pdf-22.6.jar!/:na]
 at com.aspose.pdf.internal.l11t.l0if.<init>(Unknown Source) ~[aspose-pdf-22.6.jar!/:na]
 at com.aspose.pdf.internal.l11l.l0if.lI(Unknown Source) ~[aspose-pdf-22.6.jar!/:na]
 at com.aspose.pdf.internal.l11t.lI.l2n(Unknown Source) ~[aspose-pdf-22.6.jar!/:na]
 at com.aspose.pdf.internal.l11t.lI.l1u(Unknown Source) ~[aspose-pdf-22.6.jar!/:na]
 at com.aspose.pdf.internal.l4if.lu.lf(Unknown Source) ~[aspose-pdf-22.6.jar!/:na]
 at com.aspose.pdf.Page.calculateContentBBox(Unknown Source) ~[aspose-pdf-22.6.jar!/:na]
 at com.aspose.pdf.Page.lf(Unknown Source) ~[aspose-pdf-22.6.jar!/:na]
 at com.aspose.pdf.Page.lv(Unknown Source) ~[aspose-pdf-22.6.jar!/:na]
 at com.aspose.pdf.ADocument.processParagraphs(Unknown Source) ~[aspose-pdf-22.6.jar!/:na]
 at com.aspose.pdf.Document.processParagraphs(Unknown Source) ~[aspose-pdf-22.6.jar!/:na]
 at com.aspose.pdf.ADocument.lf(Unknown Source) ~[aspose-pdf-22.6.jar!/:na]
 at com.aspose.pdf.ADocument.save(Unknown Source) ~[aspose-pdf-22.6.jar!/:na]
 at com.aspose.pdf.Document.save(Unknown Source) ~[aspose-pdf-22.6.jar!/:na]
 at com.aspose.pdf.ADocument$4.lI(Unknown Source) ~[aspose-pdf-22.6.jar!/:na]
 at com.aspose.pdf.internal.l196u.lf.lI(Unknown Source) ~[aspose-pdf-22.6.jar!/:na]
 at com.aspose.pdf.internal.l196u.lj.lI(Unknown Source) ~[aspose-pdf-22.6.jar!/:na]
 at com.aspose.pdf.ADocument.save(Unknown Source) ~[aspose-pdf-22.6.jar!/:na]
 at com.aspose.pdf.Document.save(Unknown Source) ~[aspose-pdf-22.6.jar!/:na] 

Still figuring out how to resolve this since the other problem got resolved by the fonts configuration!

image.png (2.0 KB)

This is the fonts directory on the system. Do the contents look fine? What should I do to have aspose point to it?

@shaurya.chawla

Please try to install the package of msttcorefonts. Also, please note that these fonts should be placed in “/usr/share/fonts/truetype/msttcorefonts” directory as Aspose.PDF scans this folder on Linux like operating systems. In case operating system has other default folder/directory for fonts, you should use setLocalFontPaths method before performing any operation using Aspose.PDF.

@asad.ali Thanks for your reply Asad,
I’m just curious - Word to PDF and Excel to PDF work without having to set anything related to fonts. Why does Image to PDF have to set this?

@shaurya.chawla

Its default behavior of Aspose.PDF that it get font information from the system while processing the PDF documents. It is also mentioned in the documentation that fonts are necessary to be installed in order to get expected results while using the API.