PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Tue May 14, 2024 10:28 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Fri May 13, 2016 5:55 pm 
Offline

Joined: Fri May 13, 2016 5:44 pm
Posts: 6
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.Modify

Forgetting 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


Top
 Profile  
Reply with quote  
PostPosted: Fri May 13, 2016 8:16 pm 
Online
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 920
Location: CCAA
Are you using the WPF build? Trying the GDI build could be a problem.
Why don't you use the WPF build 1.50 beta 3? Or at least give it a try?

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
PostPosted: Sun May 15, 2016 12:40 am 
Offline

Joined: Fri May 13, 2016 5:44 pm
Posts: 6
I am using the GDI build. I have not tried the WPF build on 1.5 beta 3, but I will give it a try and reply to this post as to the outcome.

Also, why would the GDI build be a problem for this instance? Thanks.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 82 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group