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

Free Support Forum - aspose.com

Document.Save(stream- Aspose.Words.SaveFormat.Pdf) failing


I’m experiencing an issue using the Document.Save method. My goal is to retrieve documents through a service created using IIS. If the document is a .doc type, it should be saved as a pdfStream first. To achieve this I’m using the code seen below.

Stream sourceData = File.ReadAllBytes(filePath);
MemoryStream pdfStream = new MemoryStream(); 
wordDocument = new Aspose.Words.Document(sourceData);
wordDocument.Save(pdfStream, Aspose.Words.SaveFormat.Pdf);
pdfStream.Position = 0;
return( pdfStream );

Strangely, this works when I set up the service locally on my computer and debug through it but doesn’t when I’m attempting to retrieve the same document on the UAT machine. The code falls over at wordDocument.Save(pdfStream, Aspose.Words.SaveFormat.Pdf); but doesn’t provide an exception message or inner exception. I think this might be related to the apppools permissions/behaviour on the uat machine and was wondering if anyone could advise.

I’m using Aspose.Words version 8 & cannot upgrade as it would cause issues with our framework. I don’t believe the issue is version related either since it works locally.

Hi Jack,

Thanks for your inquiry. I am afraid it is difficult to suggest you anything without replicating the issue at our end. However, please note you need to consider web server Trust Level settings for Aspose.Words for .NET, when running on a shared server environment.

Furthermore, please note we maintain a single code base. All fixes and improvements are made in latest version of Aspose.Words for .NET. You are using a quite old version of Aspose.Words for .NET. It is recommended to use latest version of Aspose.Words for .NET along with web server Trust Level. You may also request a temporary license to evaluate your issue with latest version of Aspose.Words for .NET. Hopefully it will resolve the issue.

Best regards,

Thanks for replying, I understand that it’s difficult to replicate this scenario especially considering how old the version I am using is.

I’m running a .NETv4.0 application pool, am I right in saying that trust level only applies to .NETv2.0 applications?

Are there any folders on the drive that the SaveAsPdf process uses that may require additional permissions from the apppool/user account the service is running under?



Hi Jack,

Thanks for your feedback. Trust level restriction applies to other .NET Frameworks as well.

Aspose .NET component sometimes need to access registry settings and files located in places other than the virtual directory e.g. for reading fonts etc. However, in your case for DOCX to PDF conversion, you may solve this issue by specifying your own folders, filled with the appropriate fonts as suggested in the following article.

Best Regards,

Hi Tital

Sorry the late reply, I had to work on another project for a while. I looked into trust levels and using this documentation. I gave Aspose.Words & Aspose.Pdf.Kit full trust. This got me a step further and there is no longer an error being thrown over service.

Unfortunately the pdf does not seem to be converted correctly, the stream only has a length of 10. When I use Stream.ToArray(), the byte array only has a size of 10. When I debug locally, the byte array is 34333 in length and works when I save it as a pdf. Not sure if this will give any further indication of the issue, please let me know if this clarifies anything.



Hi Jack,

Thanks for your feedback. It is good to know that original issue has been fixed. In reference to new issue, please try to save output on disk for testing instead of stream. Furthermore, have you tested the scenario with latest version of Aspose.Words?

However if the issue persists then please share some sample project to replicate the issue at our end. We can guide you properly after replicating the issue at our end.

We are sorry for the inconvenience.

Best Regards,