Decrypt this document using the specified password.
public bool Decrypt(
string password
)
public:
bool Decrypt(
String^ password
)
public boolean decrypt(String password)
def Decrypt(self,password):
password
String containing the password phrase to decrypt this document.
In most cases, the LEADDocument is ready to use after it has been obtained. However, some documents such as PDF can be encrypted and required a password before it can be parsed and used. Most of the properties and methods of LEADDocument will throw an error if the document has not been decrypted. IsEncrypted can be used to check if the document is encrypted and if so, Decrypt must be called with a password obtained from the user to unlock the document. When that happens, the value of IsDecrypted becomes true and the document is ready to be used. Note that IsEncrypted will stay true to indicate the original state of the document.
For more information, refer to Loading Encrypted Files Using the Document Library.
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Document.Writer;
using Leadtools.Document;
using Leadtools.Caching;
using Leadtools.Annotations.Engine;
using Leadtools.Ocr;
using Leadtools.Barcode;
using Leadtools.Document.Converter;
public void DocumentIsEncryptedExample()
{
// This is the password for this encrypted document
string password = "lead";
var options = new LoadDocumentOptions();
using (var document = DocumentFactory.LoadFromFile(Path.Combine(LEAD_VARS.ImagesDir, "Protected.pdf"), options))
{
if (document.IsEncrypted && !document.IsDecrypted)
{
Console.WriteLine("Encrypted Document, decrypting it...");
// Decrypt it now
document.Decrypt("lead");
}
// Should not be encrypted anymore
System.Diagnostics.Debug.Assert(!document.IsEncrypted);
}
// Or, set the password directly in the load options
options.Password = password;
using (var document = DocumentFactory.LoadFromFile(Path.Combine(LEAD_VARS.ImagesDir, "Protected.pdf"), options))
{
// Should not be encrypted
System.Diagnostics.Debug.Assert(!document.IsEncrypted);
}
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images";
}
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.regex.Pattern;
import org.junit.*;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
import static org.junit.Assert.*;
import leadtools.*;
import leadtools.annotations.engine.*;
import leadtools.barcode.*;
import leadtools.caching.*;
import leadtools.codecs.*;
import leadtools.document.*;
import leadtools.document.DocumentMimeTypes.UserGetDocumentStatusHandler;
import leadtools.document.converter.*;
import leadtools.document.writer.*;
import leadtools.ocr.*;
public void documentIsEncryptedExample() {
final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images";
// This is the password for this encrypted document
String password = "password";
LoadDocumentOptions options = new LoadDocumentOptions();
LEADDocument document = DocumentFactory.loadFromFile(combine(LEAD_VARS_IMAGES_DIR, "leadtools_encrypted.pdf"),
options);
if (document.isEncrypted() && !document.isDecrypted()) {
System.out.println("Encrypted Document, decrypting it...");
// Decrypt it now
document.decrypt(password);
}
// Should not be encrypted anymore
assertTrue(document.isDecrypted());
// Or, set the password directly in the load options
options.setPassword(password);
document = DocumentFactory.loadFromFile(combine(LEAD_VARS_IMAGES_DIR, "leadtools_encrypted.pdf"), options);
// Should not be encrypted
assertTrue(document.isDecrypted());
}
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document