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

Free Support Forum - aspose.com

Problem Saving to a PDF file

Update on the below message:

The goal here is to use Aspose.Email to load an Outlook msg file and convert it to .PDF format. I can load the msg file into an Aspose.Email object and write this to a MemoryStream (in MailMessageSaveType.MHtmlFromat)... where I run into the problem detailed below. I can convert a Word "Hello World" file to PDF so it appears that maybe embedded links in the msg file are causing the problem. Any suggestions????

******************************************************************

Original message:

I'm running C# in .Net 4 and the latest version of Aspose Words. When I excute the following two lines of code, I get a "UriFormatException":

---------------------------------------------------------------

//load a Word document into Aspose.Words

Aspose.Words.Document WordDoc = new Aspose.Words.Document(@"D:\Attach\dump.doc");

//create a PDF version by saving ....

WordDoc.Save(@"D:\Attach\dump.pdf"); //throws the exception on this statement

--------------------------------------------------------------

The exception message says: "Invalid URI: The hostname could not be parsed."

Hmmm. Interesting. On my machine I get a "dump.pdf" file with size = 0 but the Save routine doesn't know where to put the file??????

Ok. Let's try this....

MemoryStream dump = new MemoryStream();

Aspose.Words.Document WordDoc = new Aspose.Words.Document(@"D:\Attach\dump.doc");

WordDoc.Save(dump, Aspose.Words.SaveFormat.Pdf);

-----------------------------------------------------------------------

I get the SAME exception. Aspose.Words basically throws this exception no matter what if I ask it to save the file .PDF format.

So, what did I do wrong? Install it wrong? License wrong? Didn't say "Simon Says?" Anybody see what I obviously missed????

Hi Steven,


Thanks for your inquiry. Could you please attach your input Word document/Outlook msg file here for testing? I will investigate the issue on my side and provide you more information.

Greetings. I sent the offending file back and haven’t heard anything. Was anything discovered?

Steve Myatt

I sent this file out before but in case it never made it, here it is again. Please let me know if you find anything.

Thanks a bunch.
Steve Myatt

Hi Steve,


Thanks for you inquiry. I have tested the scenario with latest version of Aspose.Words for .NET 13.1.0 and Aspose.Email for .NET 2.6.0 and have not found any issue while converting from Msg file to PDF. Please use the latest version of Aspose.Words and Aspose.Email and let us know how it goes on your side. I have used the following code snippet at my end. I have attached the output Mhtml and Pdf file with this post for your reference.

MailMessage mail = MailMessage.Load(MyDir

  • “testinput.msg”, MessageFormat.Msg);<o:p></o:p>

MemoryStream stream = new MemoryStream();

mail.Save(stream, MailMessageSaveType.MHtmlFromat);

stream.Position = 0;

Document doc = new Document(stream);

doc.Save(MyDir + "out.pdf");


StevetheStater:
Aspose.Words.Document WordDoc = new Aspose.Words.Document(@"D:\Attach\dump.doc");
//create a PDF version by saving ....
WordDoc.Save(@"D:\Attach\dump.pdf"); //throws the exception on this statement
In your first post, you mentioned the conversion of Doc to PDF as well. Please share your Doc file here for testing. I will investigate the issue on my side and provide you more information.


Thanks for the reply. I re-installed Words 13.1.0 and Email 2.6.0 and ran your snippet with the same result. I changed things up a bit and tried to write the PDF file to another memory stream and I got the same exact error. I'm attaching a screen shot so you can see what's going on....

If this is working fine on your end, there must be a configuration or install problem on this side. Using the uninstall utility, I checked the version numbers of the installed Aspose products and they're showing 13.1.0 for Words and 2.6.0 for Email.

Thanks for your help!

Steve Myatt

Hi Steve,


Thanks for your inquiry. Please note that Aspose.Words dll Net 2.0 assembly is used for 2.0, 3.0, 3.5 and 4.0 .net frameworks. So kindly use net 2.0 assembly of Aspose.Words with 4.0 .net framework. Hopefully it will serve your purpose.

I have tested your scenario at Windows 7 (64 bit), Visual Studio 2010 (.NET framework 4.0) and 2.0 assembly of Aspose.Words and have not found any issue. It would be great if you please test your scenario by creating separate Visual Studio application with the same code shared before. Please save the mhtml file at disk and share that mhtml file with us for investigation purposes.

If you still face problem, please share your working environment like Operating System, Architecture (32 / 64 bit). I will test this scenario at same platform and share my finding with you.