During Email to PDF export, part of the inline Picture get cut off

I am using Aspose Total 24.4.1

Our code for Email2PDF is

   public static void email2pdf(final String emailFilename, final String targetPDFname, final Properties properties) throws Exception
   {
       final MailMessage message = MailMessage.load(emailFilename);
       final String temp = "TempHtmlOutput.mhtml";
       // exclude non-inline Attachment PDF export
       MhtSaveOptions mhtSaveOptions = new MhtSaveOptions();
       mhtSaveOptions.setMhtFormatOptions(mhtSaveOptions.getMhtFormatOptions() & ~MhtFormatOptions.WriteOutlineAttachments);
       message.save(temp, mhtSaveOptions);

       final Document document = new Document(temp);

       document.getSections().forEach(s -> {s.getPageSetup().setPaperSize(PaperSize.A4);});

       final boolean isPdfA = Boolean.parseBoolean(
               properties.getProperty(DocumentConverterConstants.PARAM_PDFA_VIA_OFFICE, DocumentConverterConstants.PARAM_PDFA_VIA_OFFICE_VALUE_TRUE))
                              && properties.getProperty(DocumentConverterConstants.PARAM_PDFA) != null &&
                              !properties.getProperty(DocumentConverterConstants.PARAM_PDFA).isEmpty();
       if (isPdfA)
       {
           final PdfSaveOptions opts = new PdfSaveOptions();
           opts.setCompliance(PdfCompliance.PDF_A_1_A); 
           document.save(targetPDFname, opts);
       }
       else
       {
           document.save(targetPDFname, SaveFormat.PDF);
       }

       final File file = new File(temp);
       file.delete();
   }

Here is our test Email file and PDF output:
test.zip (1,4 MB)

As you can see, part of the inline picture disappears on the PDF export.

How can I get the whole picture on the PDF export?

Hello @zwei,

The issue is with the PDF conversion process.
MHTML displays correctly, without image clipping.
We will escalate the issue to the Aspose.Words support team.

1 Like

@zwei You can use following code to resize shape with the image before saving to pdf:

for (Shape shape : (Iterable<Shape>) document.getChildNodes(NodeType.SHAPE, true)) {
    Section parentSection = (Section)shape.getAncestor(NodeType.SECTION);
    PageSetup ps = parentSection.getPageSetup();
    double pageWidth = ps.getPageWidth() - ps.getLeftMargin() - ps.getRightMargin();
    double pageHeight = ps.getPageHeight() - ps.getTopMargin() - ps.getBottomMargin();

    shape.setAspectRatioLocked(true);

    if (shape.getWidth() > pageWidth)
        shape.setWidth(pageWidth);
    if (shape.getHeight() > pageHeight)
        shape.setHeight(pageHeight);
}

thanks, I will try it

1 Like