Leadtools.Forms.DocumentReaders Namespace : DocumentReaderLoadOptions Class |
public class DocumentReaderLoadOptions
'Declaration Public Class DocumentReaderLoadOptions
'Usage Dim instance As DocumentReaderLoadOptions
public ref class DocumentReaderLoadOptions
The DocumentReaderLoadOptions class is used as the type for the options optional parameter passed to DocumentReader.Create.
DocumentReaderLoadOptions contain the following:
RasterCodecsInstance: Optional instance of a Leadtools.Codecs.RasterCodecs object to be used when rendering or creating thumbnails for the pages. You can pass your own initialized instance of Leadtools.Codecs.RasterCodecs to be used. The same object will then be used internally by the document reader. Otherwise, pass null (Nothing in Visual Basic) and the document reader will create and use its own version of Leadtools.Codecs.RasterCodecs when needed. Refer to DocumentReader.RasterCodecsInstance for more information on how this parameter is used by the document reader during its lifetime.
Resolution: The resolution value in dots per inch to use when loading a document that does not have a native resolution such as PDF, XPS or DOC.
Password: The password to use if the document is encrypted.
GetPasswordCallback: The password to use if the document is encrypted and no password was supplied in Password.
Imports Leadtools Imports Leadtools.Codecs Imports Leadtools.Forms Imports Leadtools.Forms.DocumentReaders Imports Leadtools.WinForms Imports Leadtools.Forms.Ocr Imports Leadtools.Drawing Public Sub DocumentReaderLoadOptionsExample() Dim loadOptions As New DocumentReaderLoadOptions() ' Load at 200 DPI loadOptions.Resolution = 200 ' Use a new RasterCodecs loadOptions.RasterCodecsInstance = Nothing ' Set the callback to use if the document is encrypted loadOptions.GetPasswordCallback = New DocumentReaderGetPasswordCallback(AddressOf MyGetPasswordCallback) Dim documentFileName As String Using dlg As New OpenFileDialog() If dlg.ShowDialog() <> System.Windows.Forms.DialogResult.OK Then Return End If documentFileName = dlg.FileName End Using ' Load the document Dim reader As DocumentReader = DocumentReader.Create(documentFileName, loadOptions) ' If the value of reader is Nothing, then the document was encrypted and the user hit cancel ' for the dialog If IsNothing(reader) Then MessageBox.Show("Canceled") Else ' Document is loaded, show its properties Dim sb As New StringBuilder() sb.AppendFormat("Reader used: {0}\n", reader.ReaderType) sb.AppendFormat("MIME type: {0}\n", reader.MimeType) sb.AppendFormat("Document has {0} pages", reader.Pages.Count) MessageBox.Show(sb.ToString()) reader.Dispose() End If End Sub Private Function MyGetPasswordCallback(ByVal fileName As String) As String MessageBox.Show(String.Format("{0}\nIs encrypted. Enter a password", fileName)) ' Will simulate a password, in your application you could show a dialog box ' here asking the user for a pssword Return "lead" ' Or you can return Nothing, to cancel reading the document without an exception ' being thrown. DocumentReader.Create will return Nothing as well End Function
using Leadtools; using Leadtools.Codecs; using Leadtools.Forms; using Leadtools.Forms.DocumentReaders; using Leadtools.WinForms; using Leadtools.Forms.Ocr; using Leadtools.Drawing; public void DocumentReaderLoadOptionsExample() { DocumentReaderLoadOptions loadOptions = new DocumentReaderLoadOptions(); // Load at 200 DPI loadOptions.Resolution = 200; // Use a new RasterCodecs loadOptions.RasterCodecsInstance = null; // Set the callback to use if the document is encrypted loadOptions.GetPasswordCallback = new DocumentReaderGetPasswordCallback(MyGetPasswordCallback); string documentFileName; using(OpenFileDialog dlg = new OpenFileDialog()) { if(dlg.ShowDialog() != DialogResult.OK) { return; } documentFileName = dlg.FileName; } // Load the document DocumentReader reader = DocumentReader.Create(documentFileName, loadOptions); // If the value of reader is null, then the document was encrypted and the user hit cancel // for the dialog if(reader == null) { MessageBox.Show("Canceled"); } else { // Document is loaded, show its properties StringBuilder sb = new StringBuilder(); sb.AppendFormat("Reader used: {0}\n", reader.ReaderType); sb.AppendFormat("MIME type: {0}\n", reader.MimeType); sb.AppendFormat("Document has {0} pages", reader.Pages.Count); MessageBox.Show(sb.ToString()); reader.Dispose(); } } private string MyGetPasswordCallback(string fileName) { MessageBox.Show(string.Format("{0}\nIs encrypted. Enter a password", fileName)); // Will simulate a password, in your application you could show a dialog box // here asking the user for a pssword return "lead"; // Or you can return null, to cancel reading the document without an exception // being thrown. DocumentReader.Create will return null as well }