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

Free Support Forum - aspose.com

Words.Document.Save(MemoryStream - SaveFormat.Pdf) throws System.Security.SecurityException

Hello,

we use Aspose.Words (Cells and Slides) in SharePoint for watermarking in pdf. Our solutions runs in Application-Context (IIS bin folder) an Aspose-Compontents are in GAC.

With CAS-Policies we configured the rights as far as we can see. Just FileIOPermission will shown.

...
<IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
Read="C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\;L:\MOSS\FileLog;$AppDir$"
Write="L:\MOSS\FileLog;$AppDir$"
Append="L:\MOSS\FileLog;$AppDir$"
PathDiscovery="L:\MOSS\FileLog;C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\;$AppDir$" />
...

So it runs, an the documents from SharePoint Site (Library) can be load into a Words.Document. After that the Document should be stored as PDF into a MemoryStream, that we kann add a stamp (watermark) to it with the Aspose.Pdf.Kit.

The exeption occurs when we use the folliwing lines of code:

_doc = new Document(fileStream); --> that works

_logger.Info("Finished loading file!");

_logger.Trace("Save Word document into memory stream as Pdf format.");

_doc.Save(_pdfStream, SaveFormat.Pdf); --> that fails

When do I raise the permission to FullTrust, no Error occurs, so what happens inside Aspose.Words (and others), that an FileIOPermission is necessary even if I use a MemoryStream??

Here is the ErrorLog:

2/19/2010 7:32:15 AM Verbose WATERMARK - WordBuilder Save Word document into memory stream as Pdf format. 5648 c:\windows\system32\inetsrv\w3wp.exe 5976
2/19/2010 7:32:15 AM Error WATERMARK - WordBuilder Loading Word file failed. Message: The type initializer for '䡄.䤍' threw an exception.
System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
at System.Security.CodeAccessPermission.Demand()
at System.Environment.get_SystemDirectory()
at 䡄.䤍.䥆()
at 䡄.䤍..cctor()
The action that failed was:
Demand
The type of the first permission that failed was:
System.Security.Permissions.FileIOPermission
The Zone of the assembly that failed was:
MyComputer - Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
Trace: at 䡄.䤍.ੴ(String 㜃, FontStyle ৢ, Boolean 䤣)
at 䞑.䠳..ctor(䟟 context, String familyName, FontStyle requestedStyle)
at 䞑.䢙..ctor(䟟 context, String familyName, FontStyle requestedStyle)
at 䞑.䢈.ੴ(String 㜃, FontStyle ৢ, Boolean 䡁)
at 䞑.䫄.䫌(㈮ 䪰)
at 䞑.䪪.䖆(㈮ 䪰)
at ㈊.㈖.Accept(㈙ visitor)
at ㈊.㉄.Accept(㈙ visitor)
at ㈊.㈖.Accept(㈙ visitor)
at ㈊.㉄.Accept(㈙ visitor)
at ㈊.㈖.Accept(㈙ visitor)
at ㈊.㉄.Accept(㈙ visitor)
at ㈊.㈖.Accept(㈙ visitor)
at ㈊.㉄.Accept(㈙ visitor)
at ㈊.㈖.Accept(㈙ visitor)
at ㈊.㉄.Accept(㈙ visitor)
at ㈊.㈖.Accept(㈙ visitor)
at ㈊.㈚.Accept(㈙ visitor)
at Aspose.Words.Document.SaveToPdf(Int32 pageIndex, Int32 pageCount, Stream stream, PdfOptions pdfOptions)
at Aspose.Words.Document.ԅ(Stream Ӿ, String Ӽ, SaveFormat Ԇ)
at MunichRe.cMOSS.Connect.Watermark.RenderEngine.AsposeBuilder.WordBuilder.Load(Stream fileStream) 5648 c:\windows\system32\inetsrv\w3wp.exe 5976

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. The problem can occur because Aspose.Words does not have permissions to read fonts, which are installed on your PC (C:\Windows\Fonts folder by default). So please make sure that your application has right to read from this folder. Fonts are necessary during converting to PDF.

Also there is new Aspose product called Aspose.Words for SharePoint. I think you can find it useful. Please see the following link for more information:

http://www.aspose.com/documentation/sharepoint-components/aspose.words-for-sharepoint/introducing-aspose-words-for-sharepoint.html

Best regards.

Hi

Does that mean that Aspose.Words for .NET cannot be used to save PDF from Word doc on GoDaddy Shared hosting ??

Hi Sangeet,


Thanks for your inquiry.

No. Aspose.Words is just a class library and there should not be any problems when using it inside a web application that is deployed on any web hosting server. Aspose.Words requires TrueType fonts when rendering Word documents to fixed-page formats (PDF, XPS or SWF) and you can also explicitly specify fonts location as mentioned in the following link:
http://www.aspose.com/docs/display/wordsnet/How+to++Specify+True+Type+Fonts+Location

I hope, this helps.

Best regards,