We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Problems with Saving MSG to PDF

I have an email I am trying to convert to PDF. The process loads the file into an Aspose.Network.Mail.MailMessage, saves that message to a Stream then loads that stream with a format of MHtmlFromat into an Aspose.Words.Document.

When the stream is loaded it throws the following exception. I have also attached the file in question.
Not sure if this is a Words issue or a Network issue.

{Aspose.Words.FileCorruptedException: The document appears to be corrupted and cannot be loaded. —> System.ArgumentException: Parameter is not valid.
at System.Drawing.Bitmap…ctor(Stream stream)
at xf9a9481c3f63a419.x3cd5d648729cd9b6…ctor(Byte[] imageBytes)
at Aspose.Words.Drawing.ImageData.SetImage(Byte[] imageBytes)
at Aspose.Words.DocumentBuilder.InsertImage(Byte[] imageBytes, RelativeHorizontalPosition horzPos, Double left, RelativeVerticalPosition vertPos, Double top, Double width, Double height, WrapType wrapType)
at Aspose.Words.DocumentBuilder.InsertImage(Stream stream, RelativeHorizontalPosition horzPos, Double left, RelativeVerticalPosition vertPos, Double top, Double width, Double height, WrapType wrapType)
at Aspose.Words.DocumentBuilder.InsertImage(Stream stream, Double width, Double height)
at Aspose.Words.DocumentBuilder.InsertImage(Stream stream)
at x4e7201a131ebc6f0.xf018334243635fc2.xf8a40478b82d35ca()
at x4e7201a131ebc6f0.xf018334243635fc2.xafe4c84dad991034()
at x4e7201a131ebc6f0.xf018334243635fc2.x22a6d26ddb3dacb9()
at x4e7201a131ebc6f0.xf018334243635fc2.xd5f4297b62020f85()
at x4e7201a131ebc6f0.xf018334243635fc2.xafe4c84dad991034()
at x4e7201a131ebc6f0.xf018334243635fc2.x22a6d26ddb3dacb9()
at x4e7201a131ebc6f0.xf018334243635fc2.xd5f4297b62020f85()
at x4e7201a131ebc6f0.xf018334243635fc2.xafe4c84dad991034()
at x4e7201a131ebc6f0.xf018334243635fc2.x06b0e25aa6ad68a9(Stream xcf18e5243f8d5fd3, Document x6beba47238e0ade6)
at Aspose.Words.Document.x5d4db34d48fb3129(Stream xcf18e5243f8d5fd3, LoadOptions x27aceb70372bde46)
— End of inner exception stack trace —
at Aspose.Words.Document.x5d4db34d48fb3129(Stream xcf18e5243f8d5fd3, LoadOptions x27aceb70372bde46)
at Aspose.Words.Document.x5d95f5f98c940295(Stream xcf18e5243f8d5fd3, LoadOptions x27aceb70372bde46)
at Aspose.Words.Document…ctor(Stream stream, LoadOptions loadOptions)
at Aspose.Words.Document…ctor(Stream stream)

Hello,
Thank you for your request.
Could you please provide us your generated Mhtml file.

Unfortunately I was unable to reproduce your problem on my side.
I used the components:
Aspose.Network for. NET 6.4.0
Aspose.Words for. Net 9.8.0.0
Here’s the code:

var license = new License();
license.SetLicense("Aspose.Words.lic");
MemoryStream ms = new MemoryStream();
MailMessage msg = MailMessage.Load("X:\\ACL.msg", MessageFormat.Msg);
MemoryStream msgStream = new MemoryStream();
msg.Save(msgStream, MailMessageSaveType.MHtmlFromat);
msgStream.Position = 0;
Document msgDocument = new Document(msgStream);
msgDocument.Save("X:\\out.pdf", SaveFormat.Pdf);

I’ve attached a pdf file is generated.

Using those versions of the DLLs I am still having the same problem. Not sure if it matters, but I am running Win7 64 bit in test. I believe the customer is using 32 bit 2003 server. Attached is the mshtml output. My implementation is identical to what you have described above. The only thing I wasn’t doing was initializing the stream position to zero, but even after doing that it does not work.

Just for test, I took your code and pasted directly into a new project. Same failure.

Hi
Thank you for reporting this problem to us. I managed to reproduce the problem on my side. Your request has been linked to the appropriate issue. You will be notified as soon as it is resolved.
Best regards,

Hi Brian,

I am a representative of Aspose.Email (Aspose.Network) product family. We are investigating a behavior of Aspose.Email for .NET component in connection with MSG to PDF conversion. We have noticed, when your provided sample message is saved as MHTML, the Content Type of the email attachment (a Pdf file) is set to “image/pdf” in the generated MHTML. Whereas it should be “application/pdf” according to IANA standards. Due to this behavior, Aspose.Words cannot process the MHTML further for conversion to PDF.

For investigation and correction purposes, we have logged a ticket (NETWORKNET-33207) in Aspose.Email tracking space. We will keep you posted with updates on this.

Regards,

The issues you have found earlier (filed as NETWORKNET-33207) have been fixed in this update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.

The issues you have found earlier (filed as WORDSNET-4703) have been fixed in this .NET update and this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.