I’m trying to turn a PDF page into a PNG image.
MemoryStream stream = new MemoryStream();
Document pdfDocument = new Document(sourceFileInfo.FullFilePath);<span style="color:#2b91af;">Resolution</span> resolution = <span style="color:blue;">new</span> <span style="color:#2b91af;">Resolution</span>(<span style="color:#2b91af;">ConfigSettings</span>.PreviewImageWidth, <span style="color:#2b91af;">ConfigSettings</span>.PreviewImagesHeight); <span style="color:#2b91af;">PngDevice</span> pngDevice = <span style="color:blue;">new</span> <span style="color:#2b91af;">PngDevice</span>(resolution); <span style="color:blue;">try</span> { pngDevice.Process(pdfDocument.Pages.Cast<<span style="color:#2b91af;">Page</span>>().First(), stream); } <span style="color:blue;">catch</span> (<span style="color:#2b91af;">Exception</span> ex) { System.Diagnostics.<span style="color:#2b91af;">Debug</span>.Write(ex.ToString()); }
I get a MethodAccessException on pngDevice.Process with details:
Attempt by security transparent method ’ . . (System.Drawing.Bitmap, System.Drawing.RectangleF)’ to access security critical method ‘System.Runtime.InteropServices.Marshal.Copy(IntPtr, Byte[], Int32, Int32)’ failed.
Assembly ‘Aspose.Pdf, Version=6.2.0.0, Culture=neutral, PublicKeyToken=47b2d0fcacdd3eb6’ is marked with the AllowPartiallyTrustedCallersAttribute, and uses the level 2 security transparency model. Level 2 transparency causes all methods in AllowPartiallyTrustedCallers assemblies to become security transparent by default, which may be the cause of this exception.
I’m running on ASP.NET 4.0 on IIS 7 on Windows 7.