During the PDF generation, the inline attached picture disappeared

I am using Aspose Words JDK17:24.3, now I should convert mhtml file into PDF.

Our code is following:

public static void email2pdf(final String mhtFile, final String targetPDFname) throws Exception
{
    final Document document = new Document(mhtFile);
    document.getSections().forEach(s -> {s.getPageSetup().setPaperSize(PaperSize.A4);});
    document.save(targetPDFname, SaveFormat.PDF);
}

Problem is, our test mhtml file contains an inline pic, however after convert this pic disappeared in the PDF.

In this zip, it is our MHTML test file and the corresponding PDF, as you can see, the company logo disappears in the PDF.

mhtml2pdfTest.zip (83,2 KB)

p.s. I have also tried the same code with Aspose Words 23.7 evaluation edition and this problem doesn’t exist. However, if I use Aspose Words 24.3 licensed edition, this problem will come.

@zwei Unfortunately, I cannot reproduce the problem on my side. Here is PDF document produced on my side using the latest 24.4 version of Aspose.Words for Java and the following simple code:

Document doc = new Document("C:\\Temp\\in.mhtml");
doc.save("C:\\Temp\\out.pdf");

out.pdf (90.8 KB)

Please make sure the image is accessible in the environment where the document is converted. Also, please try using the latest version and let us know if the problem still persists.

1 Like

Thanks for your reply, however it is a MHTML file, therefore the inline attached picture is part of the same MHTML file. So Aspose should have access to the inline attached pic.

I will update my Aspose to 24.4 and try again.

@zwei As I can see the image is not embedded into the MHTML document, so it is required to download the image for rendering.

1 Like

omg, thanks for such a clue!

1 Like

The reason of this problem should be our Firewall setting.

The Aspose evaluation edition was installed in a PC which has free internet access, yet the licensed edition was installed in a Server which has very strict firewall settings.

This should be the true reason.

@zwei Yes, this definitely might be the reason of the problem. You can try using IResourceLoadingCallback to implement a custom logic for loading external resource.

Thanks, I will consider to use it!

1 Like