PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sun Jul 07, 2024 7:31 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Thu Jul 12, 2012 10:28 pm 
Offline

Joined: Thu Jul 12, 2012 10:16 pm
Posts: 4
I'm simply trying to set SecuritySettings on a PDF (in the form of a byte array) that is returned by the ReportViewer object in Visual Studio 2010. I have verified that the PDF returned by the ReportViewer is a valid two page PDF document. The problem is when I open it with the PdfReader, set the settings and save it, the result is a two page PDF document where both pages are completely blank.

With the exception of the MemoryStreams, this is pretty much a verbatim copy of the "Protect Document" example. Any suggestions?

Code:
         byte[] bytes = viewer.LocalReport.Render(
               "PDF",
               null,
               out mimeType,
               out encoding,
               out extension,
               out streamIds,
               out warnings
               );

         MemoryStream ms = new MemoryStream( bytes );

         PdfDocument pdfDoc = PdfReader.Open( ms );
         var settings = pdfDoc.SecuritySettings;

         settings.PermitAssembleDocument = false;
         settings.PermitExtractContent = false;
         settings.PermitModifyDocument = false;
         settings.PermitAccessibilityExtractContent = false;

         MemoryStream oms = new MemoryStream( );
         pdfDoc.Save( oms );
         bytes = oms.ToArray( );

         page.Response.Buffer = true;
         page.Response.Clear( );
         page.Response.ContentType = mimeType;
         page.Response.AddHeader(
            "content-disposition",
            "inline"
            //"attachment; filename=" + clientFileName + "." + extension
            );
         page.Response.BinaryWrite( bytes );
         page.Response.Flush( );


Thanks.
Ken.


Top
 Profile  
Reply with quote  
PostPosted: Fri Jul 13, 2012 1:24 pm 
Offline
PDFsharp Expert
User avatar

Joined: Wed Dec 09, 2009 8:59 am
Posts: 343
Can you tell the ReportViewer to create "HumanReadablePDF"?
See also:
viewtopic.php?p=1613#p1613
viewtopic.php?f=2&t=832

_________________
Öhmesh Volta ("() => true")
PDFsharp Team Holiday Substitute


Top
 Profile  
Reply with quote  
PostPosted: Fri Jul 13, 2012 5:02 pm 
Offline

Joined: Thu Jul 12, 2012 10:16 pm
Posts: 4
() => true wrote:
Can you tell the ReportViewer to create "HumanReadablePDF"?
See also:
viewtopic.php?p=1613#p1613
viewtopic.php?f=2&t=832


Excellent! That's an easy fix. My bad for not searching the forum for SSRS. I assumed the issue was PDFSharp :oops:

So, although this is now producing a readable PDF, it does not effect my ability to copy text. I assume that this is the correct setting to prevent copy:

settings.PermitExtractContent = false;
settings.PermitAccessibilityExtractContent = false;

Any thoughts?
Ken.


Top
 Profile  
Reply with quote  
PostPosted: Mon Jul 16, 2012 5:52 pm 
Offline

Joined: Thu Jul 12, 2012 10:16 pm
Posts: 4
Hi, I'm bumping this, because I really need resolution on it. My deadline quickly approaches.
Thanks.


Top
 Profile  
Reply with quote  
PostPosted: Tue Jul 17, 2012 8:20 pm 
Offline
PDFsharp Expert
User avatar

Joined: Wed Dec 09, 2009 8:59 am
Posts: 343
cosmokenney wrote:
So, although this is now producing a readable PDF, it does not effect my ability to copy text. I assume that this is the correct setting to prevent copy:

settings.PermitExtractContent = false;
settings.PermitAccessibilityExtractContent = false;

Any thoughts?
Looks good. IIRC you have to set an Owner password to make this work.
Do not set a User password if you want to enable users to open the file without entering a password.

_________________
Öhmesh Volta ("() => true")
PDFsharp Team Holiday Substitute


Top
 Profile  
Reply with quote  
PostPosted: Sat Jul 21, 2012 4:53 pm 
Offline

Joined: Thu Jul 12, 2012 10:16 pm
Posts: 4
() => true wrote:
cosmokenney wrote:
So, although this is now producing a readable PDF, it does not effect my ability to copy text. I assume that this is the correct setting to prevent copy:

settings.PermitExtractContent = false;
settings.PermitAccessibilityExtractContent = false;

Any thoughts?
Looks good. IIRC you have to set an Owner password to make this work.
Do not set a User password if you want to enable users to open the file without entering a password.


Yes, Owner Password did the trick. Thanks.


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 35 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