Hello all,
I have developed a SharePoint 2010 Foundation web part that reads in PDF files from our network. Users have the option to view or print a given PDF (all user's do not have access to these folders on the network, but I programmed the proper security channels within the web part so they may view the PDFs). The view aspect works just fine, using native .NET classes through the HttpContext.
NOTE: viewing and printing is handled in an Http Handler .ashx file on the production server.
NOTE: I am using the latest full non-BETA build of PdfSharp (1.32) in my application
However, I am trying to send a JavaScript command to the PDF when the user tries to print it to bypass the print dialog. Here is my C# code:
Code:
using System;
using System.IO;
using PdfSharp.Pdf;
using PdfSharp.Internal;
using PdfSharp.Advanced;
using PdfSharp.Pdf.Security;
...
byte[] bytes = File.ReadAllBytes(filePath);
using (MemoryStream ms = new MemoryStream(bytes))
{
PdfDocument inputDoc = PdfReader.Open(ms, PdfDocumentOpenMode.Import);
PdfDocument outputDoc = new PdfDocument();
for (int i = 0; i < inputDoc.PageCount; i++)
{
outputDoc.AddPage(inputDoc.Pages[i]);
}
outputDoc.Save(ms, false);
}
context.Response.Clear();
context.Response.ContentType = "application/pdf";
context.Response.BinaryWrite(ms.ToArray());
context.Response.Flush();
context.Response.End();
NOTE: this fails when using either
PdfDocumentOpenMode.Import or
PdfDocumentOpenMode.ModifyForgetting the JavaScript portion at this time, I cannot get any file to open successfully using
PdfReader. In using
MemoryStream in the
PdfReader.Open method, or straight up string file location, I get errors. The SharePoint web part has all the necessary permissions, as well as the source directory and PDF files where this is trying to retrieve.
The errors I get for the MemoryStream approach is this:
PdfSharp.Pdf.Advanced.PdfCatalog...ctor(PdfSharp.PdfDictionary) as System.Reflection.MethodBase.PerformSecurityCheck(Object obj, RuntimeMethodHandle method, IntPtr parent, UIInt32 invocationFlags) as System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr....The errors I get for the string file location approach is this:
Request for the permission type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c56193e089' failed. at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) at System.Security.CodeAccess.Permission.Demand()...Again, I don't think it is a permissions things, because the files can be viewed just fine with native .NET coding. Only when I try to use PdfSharp does it fail.
Any help will greatly be appreciated.
Thank you