Message body with Inline image dos not fit on PDF

If we convert a message body to PDF and the body contains a large image, the PDF is created with the full size image. Is ther a way to automaticly sale this image so that it wil fit on the PDF page? But only if the image would be otherwise croped.

I included an exampe msg, the generated mhtml and the generated PDF

FW testmail robot.zip (312.0 KB)

For demonstartion this is the PDF we would like to be produced:

FW testmail robot (resized).zip (813.7 KB)

This is the code of our application:

Aspose.Email.License license = new Aspose.Email.License();
license.SetLicense(@“Aspose.Total.lic”);

MemoryStream stream = new MemoryStream();

MhtSaveOptions opt = Aspose.Email.SaveOptions.DefaultMhtml;
opt.SaveAttachments = false;
theMessage.Save(stream, opt);

string htmlFileName = Path.Combine(outputPath, Path.ChangeExtension(Path.GetFileName(inputFileName), ".mhtml"));
theMessage.Save(htmlFileName, opt);

stream.Seek(0, SeekOrigin.Begin);

Aspose.Words.LoadOptions loadOptions = new Aspose.Words.LoadOptions();
loadOptions.LoadFormat = Aspose.Words.LoadFormat.Mhtml;

AsposeWordWithTimeout doc = new AsposeWordWithTimeout(inputFileName, stream, loadOptions);

doc.UpdateTableLayout();

Aspose.Words.Saving.PdfSaveOptions options = new Aspose.Words.Saving.PdfSaveOptions();
options.Compliance = PdfCompliance.Pdf15;

string outputFileName = Path.Combine(outputPath, Path.ChangeExtension(Path.GetFileName(inputFileName), ".pdf"));
doc.Save(fileName, saveOptions);

@andreas4e47b,

You can resize wider images in MHTML to fit it inside the page bounds of PDF by using the following simple code:

Document doc = new Document("E:\\temp\\FW  testmail robot\\FW  testmail robot.mhtml");

PageSetup ps = doc.FirstSection.PageSetup;
double effectiveWidth = ps.PageWidth - (ps.LeftMargin + ps.RightMargin);

NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true);
foreach (Shape shape in shapes)
    shape.Width = (shape.Width > effectiveWidth) ? effectiveWidth : shape.Width;

doc.Save("E:\\temp\\FW  testmail robot\\19.9.pdf"); 

Hope, this helps.

Thank you, that was exactly what I was looking for.

@andreas4e47b,

Thanks for your feedback. In case you have further inquiries or need any help in future, please let us know.