We are using your product Aspose.Total
Our main use case is converting Outlook emails (.msg files) to PDF, using the following API interface:
https://docs.aspose.com/email/net/saving-an-email-as-pdf/
We are currently using Licence Version 3 of the product.
Unfortunately, we are encountering an issue:
The scaling of the output PDF does not match the expected result. Whereas if a picture in the E-Mail file is too big it only shows a small part of the picture in the pdf-file.
Is this a known issue?
@Corner4Anna
It sounds like you’re experiencing an issue with the scaling of images when converting Outlook emails (.msg files) to PDF using Aspose.Total. The problem may arise if the images in the email are too large, leading to improper rendering in the output PDF, where only a portion of the image is visible.
Cause: This issue is likely due to the default settings for image handling during the conversion process.
Solution: Here are several steps you can take to troubleshoot and resolve the issue:
-
Check Image Compression Settings: Ensure that the image compression settings are configured correctly. Adjust the ImageCompression
options in your PDF save settings to see if that improves the output.
-
Adjust Image Quality: If the images are being downsampled or compressed excessively, consider increasing the quality settings. Set the ImageQuality
property in the ImageCompressionOptions
to a higher value.
-
Use PdfSaveOptions: When saving the email as a PDF, utilize the PdfSaveOptions
class to specify how images should be handled. For instance, set the CompressImages
property to false
to retain the original quality of the images.
Here’s a minimal code example to illustrate how you might set these options:
using Aspose.Email;
using Aspose.Email.Saving;
using Aspose.Pdf;
using Aspose.Pdf.Optimization;
// Load the email
var email = MailMessage.Load("path/to/email.msg");
// Save as PDF with options
var pdfOptions = new PdfSaveOptions
{
ImageCompressionOptions = new ImageCompressionOptions
{
CompressImages = false,
ImageQuality = 100 // Set to a higher value for better quality
}
};
email.Save("output.pdf", SaveOptions.Pdf, pdfOptions);
- Update Aspose Libraries: Ensure that you are using the latest version of Aspose.Total, as updates may include bug fixes and improvements related to image handling.
Next Steps: If the issue persists after trying these steps, I recommend reaching out to Aspose support with specific details about the images and the settings you are using.
Please let me know if this resolves your issue!
@Corner4Anna,
Could you please zip and attach the email message file(s) that you are converting to PDF using Aspose.Email? Additionally, please include the resulting PDF file for our reference. We will review your issue soon.
Furthermore, I am transferring your thread to the appropriate category, where a member of the Aspose.Email team will evaluate it and provide assistance accordingly.
Aspose.zip (2,9 MB)
In the zip you will find the target state as well as the current state and the message file. Sorry for the dealyed answer - I has to wait for the response of our customers who use your tool.
We tried following the instructions of @Professionalize.Discourse, sadly that did not work for us…:
Code.zip (203,7 KB)
As you can see in the pictures the code doesn’t seem to work…
The namespace used does not exist either.
When we run the PDF conversion with my code using the latest library, the problem still occurs. Tested with Aspose 25.3.14.0
Could you please explain this or send a working example?
Hello @Corner4Anna,
We’ve looked into the problem and found that it’s not caused by Aspose.Email.
Since the image is rendered to PDF after the email is saved as MHTML, we suspect the issue is related to ‘Aspose.Words’.
We are forwarding the issue to ‘Aspose.Words’ team for further analysis.
@Corner4Anna The problem occurs because the image is too wide and does not fit the default page size. You can adjust shape size to avoid image cropping. For example see the following code:
Aspose.Email.MailMessage msg = Aspose.Email.MailMessage.Load("C:\\Temp\\in.eml");
msg.Save("C:\\Temp\\tmp.mhtml", Aspose.Email.SaveOptions.DefaultMhtml);
Document doc = new Document("C:\\Temp\\tmp.mhtml");
PageSetup ps = doc.FirstSection.PageSetup;
double pageWidth = ps.PageWidth - ps.LeftMargin - ps.RightMargin;
double pageHeight = ps.PageHeight - ps.TopMargin - ps.BottomMargin;
foreach (Shape s in doc.GetChildNodes(NodeType.Shape, true))
{
if (s.IsTopLevel)
{
if (s.Width > pageWidth)
{
s.AspectRatioLocked = true;
s.Width = pageWidth;
}
}
}
doc.Save("C:\\Temp\\out.pdf");
out.pdf (1.2 MB)