Dim caption As String = "Example: SetPassword"
Dim gdpicturePDF As New GdPicturePDF()
If gdpicturePDF.LoadFromFile("test.pdf", False) = GdPictureStatus.OK Then
'We are going to create an encrypted PDF document here.
If gdpicturePDF.SaveToFile("encrypted.pdf", PdfEncryption.PdfEncryption128BitRC4, "user", "owner", False, False,
False, False, False, False, False, False) = GdPictureStatus.OK Then
If gdpicturePDF.CloseDocument() <> GdPictureStatus.OK Then
Return
End If
If gdpicturePDF.LoadFromFile("encrypted.pdf", False) <> GdPictureStatus.OK Then
Return
End If
'The new encrypted PDF document has been successfully loaded.
Dim isEncrypted As Boolean = gdpicturePDF.IsEncrypted()
Dim status As GdPictureStatus = gdpicturePDF.GetStat()
If status = GdPictureStatus.OK Then
If isEncrypted Then
'Providing an user password.
status = gdpicturePDF.SetPassword("user")
MessageBox.Show("The PDF document was encrypted and now it is decrypted with the status: " + status.ToString(), caption)
'You can work with the PDF document according to the specified access rights (see above).
'Closing and reloading the document to make it encrypted again.
If gdpicturePDF.CloseDocument() <> GdPictureStatus.OK Then
Return
End If
If gdpicturePDF.LoadFromFile("encrypted.pdf", False) <> GdPictureStatus.OK Then
Return
End If
'Providing an owner password.
status = gdpicturePDF.SetPassword("owner")
'You have full access to the document content now.
MessageBox.Show("The PDF document was encrypted and now it is decrypted with the status: " + status.ToString(), caption)
Else
MessageBox.Show("The PDF document is unencrypted.", caption)
End If
End If
Else
MessageBox.Show("The encrypted file has failed to save.", caption)
End If
Else
MessageBox.Show("The file can't be loaded.", caption)
End If
gdpicturePDF.Dispose()
string caption = "Example: SetPassword";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
if (gdpicturePDF.LoadFromFile("test.pdf", false) == GdPictureStatus.OK)
{
//We are going to create an encrypted PDF document here.
if (gdpicturePDF.SaveToFile("encrypted.pdf", PdfEncryption.PdfEncryption128BitRC4, "user", "owner", false, false, false, false, false, false, false, false) == GdPictureStatus.OK)
{
if (gdpicturePDF.CloseDocument() != GdPictureStatus.OK) return;
if (gdpicturePDF.LoadFromFile("encrypted.pdf", false) != GdPictureStatus.OK) return;
//The new encrypted PDF document has been successfully loaded.
bool isEncrypted = gdpicturePDF.IsEncrypted();
GdPictureStatus status = gdpicturePDF.GetStat();
if (status == GdPictureStatus.OK)
{
if (isEncrypted)
{
//Providing an user password.
status = gdpicturePDF.SetPassword("user");
MessageBox.Show("The PDF document was encrypted and now it is decrypted with the status: " + status.ToString(), caption);
//You can work with the PDF document according to the specified access rights (see above).
//Closing and reloading the document to make it encrypted again.
if (gdpicturePDF.CloseDocument() != GdPictureStatus.OK) return;
if (gdpicturePDF.LoadFromFile("encrypted.pdf", false) != GdPictureStatus.OK) return;
//Providing an owner password.
status = gdpicturePDF.SetPassword("owner");
MessageBox.Show("The PDF document was encrypted and now it is decrypted with the status: " + status.ToString(), caption);
//You have full access to the document content now.
}
else
{
MessageBox.Show("The PDF document is unencrypted.", caption);
}
}
}
else
{
MessageBox.Show("The encrypted file has failed to save.", caption);
}
}
else
{
MessageBox.Show("The file can't be loaded.", caption);
}
gdpicturePDF.Dispose();