Remove PDF security settings

Security
7/17/2015

Remove the security setting of a PDF

This code sample shows how you can remove the security setting of a PDF quite easily; just set the security attribute to null.

C# code sample

1 using ( FileStream inFile = new FileStream( @"..\..\..\inputDocuments\PackingLightBrochure.pdf", FileMode.Open, FileAccess.Read ) ) 2 { 3 // open the source document 4 Document document = new Document( inFile ); 5 6 // remove security settings - as a consequence user privileges 7 // that were disabled are now enabled again 8 document.Security = null; 9 10 // write the modified document to disk 11 using ( FileStream outFile = new FileStream( @"..\..\removesecuritysettings.pdf", FileMode.Create, FileAccess.Write ) ) 12 { 13 document.Write( outFile ); 14 } 15 }

VB.NET code sample

1 Using inFile As New FileStream("..\..\..\inputDocuments\PackingLightBrochure.pdf", FileMode.Open, FileAccess.Read) 2 ' open the source document 3 Dim document As New Document(inFile) 4 5 ' remove security settings - as a consequence user privileges 6 ' that were disabled are now enabled again 7 document.Security = Nothing 8 9 ' write the modified document to disk 10 Using outFile As New FileStream("..\..\removesecuritysettings.pdf", FileMode.Create, FileAccess.Write) 11 document.Write(outFile) 12 End Using 13 End Using