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.