Remove PDF security settings

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.

using (FileStream inFile = new FileStream("PackingLightBrochure.pdf", FileMode.Open, FileAccess.Read))
{
    // open the source document
    Document document = new Document( inFile );
         
    // remove security settings - as a consequence user privileges 
    // that were disabled are now enabled again
    document.Security = null;

    // write the modified document to disk
    using ( FileStream outFile = new FileStream("removesecuritysettings.pdf", FileMode.Create, FileAccess.Write ) )
    {
        document.Write( outFile );
    }
}

``` vb
Using inFile As New FileStream("PackingLightBrochure.pdf", FileMode.Open, FileAccess.Read)
    ' open the source document
    Dim document As New Document(inFile)

    ' remove security settings - as a consequence user privileges 
    ' that were disabled are now enabled again
    document.Security = Nothing

    ' write the modified document to disk
    Using outFile As New FileStream("removesecuritysettings.pdf", FileMode.Create, FileAccess.Write)
        document.Write(outFile)
    End Using
End Using