Sample code for 30+ languages & platforms
Delphi ActiveX Requires Chilkat v11.7.0+

Remove the Password and Encryption from a PDF

See more PDF Protection Examples

Demonstrates the removeEncryption operation, which saves the PDF with no encryption at all: no password, no restrictions. It needs owner rights, so the PDF is loaded with its owner password. As with every Protection operation, the change is applied when the file is written.

Chilkat Delphi ActiveX Downloads

Delphi ActiveX
var
success: Integer;
pdf: TChilkatPdf;
json: TChilkatJsonObject;
jsonOut: TChilkatJsonObject;
reader: TChilkatPdf;
info: TChilkatJsonObject;

begin
success := 0;

//  This example requires the Chilkat API to have been previously unlocked.
//  See Global Unlock Sample for sample code.

//  The PDF used in this example is available at encrypted_user_password.pdf

pdf := TChilkatPdf.Create(Self);

//  Removing the encryption needs owner rights: load with the owner password.
pdf.OwnerPassword := 'owner-secret';
success := pdf.LoadFile('qa_data/pdf/encrypted_user_password.pdf');
if (success = 0) then
  begin
    Memo1.Lines.Add(pdf.LastErrorText);
    Exit;
  end;

json := TChilkatJsonObject.Create(Self);
jsonOut := TChilkatJsonObject.Create(Self);
success := pdf.Protection('getInfo',json.ControlInterface,jsonOut.ControlInterface);
if (success = 0) then
  begin
    Memo1.Lines.Add(pdf.LastErrorText);
    Exit;
  end;
Memo1.Lines.Add('encrypted, as loaded: ' + IntToStr(Ord(jsonOut.BoolOf('loaded.encrypted'))));
Memo1.Lines.Add('algorithm: ' + jsonOut.StringOf('loaded.algorithm'));

success := pdf.Protection('removeEncryption',json.ControlInterface,jsonOut.ControlInterface);
if (success = 0) then
  begin
    Memo1.Lines.Add(pdf.LastErrorText);
    Exit;
  end;
Memo1.Lines.Add('will be saved encrypted: ' + IntToStr(Ord(jsonOut.BoolOf('pending.encrypted'))));

success := pdf.WriteFile('qa_output/minutes_unprotected.pdf');
if (success = 0) then
  begin
    Memo1.Lines.Add(pdf.LastErrorText);
    Exit;
  end;

//  The result is an ordinary PDF that opens without a password.
reader := TChilkatPdf.Create(Self);
info := TChilkatJsonObject.Create(Self);
success := reader.PreLoadCheck('qa_output/minutes_unprotected.pdf',info.ControlInterface);
if (success = 0) then
  begin
    Memo1.Lines.Add(reader.LastErrorText);
    Exit;
  end;
Memo1.Lines.Add('encrypted: ' + IntToStr(Ord(info.BoolOf('encrypted'))));
success := reader.LoadFile('qa_output/minutes_unprotected.pdf');
if (success = 0) then
  begin
    Memo1.Lines.Add(reader.LastErrorText);
    Exit;
  end;
Memo1.Lines.Add('pages: ' + IntToStr(reader.NumPages));

//  Sample output:

//  encrypted, as loaded: True
//  algorithm: rc4-128
//  will be saved encrypted: False
//  encrypted: False
//  pages: 1