MojoDK
1
Hi
I’ve tired this sample code:
Convert Emails to PDF in C# and VB.NET
But if there is large inline images, they are not fitted to the A4 page - I only see part of the image.
Is it possible to fit all images that exceeds A4 to the page size?
Thanks.
Hi Morten,
Can you send us your input email file so that we can investigate it?
I want to investigate how exactly is the <img>
element styled in the HTML body.
Regards,
Mario
MojoDK
3
How can I send an email to you privatly in here?
You can send it as an attachment to an email or support ticket, see the Contact page.
The images in the email’s body have a width
specified in inches instead of a percentage:
<img border="0" width="1512" height="2016" style="width:15.75in;height:21.0in" ... />
That is why you’ll need to resize them yourself.
So, try using the following:
DocumentModel document = ...
// Load HTML content from MSG body...
var pageSetup = document.Sections[0].PageSetup;
var pageSize = new Size(
pageSetup.PageWidth - pageSetup.PageMargins.Left - pageSetup.PageMargins.Right,
pageSetup.PageHeight - pageSetup.PageMargins.Top - pageSetup.PageMargins.Bottom);
// Resize picture elements.
foreach (var picture in document.GetChildElements(true, ElementType.Picture).Cast<Picture>())
{
var pictureLayout = picture.Layout;
var pictureSize = pictureLayout.Size;
double ratioX = pageSize.Width / pictureSize.Width;
double ratioY = pageSize.Height / pictureSize.Height;
double ratio = Math.Min(ratioX, ratioY);
if (ratio < 1)
pictureLayout.Size = new Size(pictureSize.Width * ratio, pictureSize.Height * ratio);
}
document.Save("output.pdf");
Does this solve your issue?
Regards,
Mario
MojoDK
6
Perfect - that seams to work!