LEADTOOLS Forms (Leadtools.Forms.DocumentReaders assembly)
LEAD Technologies, Inc

DocumentReaderLoadOptions Class

Example 





Members 
Provides options to use when reading a document.
Object Model
DocumentReaderLoadOptions Class
Syntax
public class DocumentReaderLoadOptions 
'Declaration
 
Public Class DocumentReaderLoadOptions 
'Usage
 
Dim instance As DocumentReaderLoadOptions
public sealed class DocumentReaderLoadOptions 
function Leadtools.Forms.DocumentReaders.DocumentReaderLoadOptions()
public ref class DocumentReaderLoadOptions 
Remarks

The DocumentReaderLoadOptions class is used as the type for the options optional parameter passed to DocumentReader.Create.

DocumentReaderLoadOptions contain the following:

Example
 
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
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
}
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

DocumentReaderLoadOptions Members
Leadtools.Forms.DocumentReaders Namespace

 

 


Products | Support | Contact Us | Copyright Notices

© 2006-2012 All Rights Reserved. LEAD Technologies, Inc.

Leadtools.Forms.DocumentWriters requires a Document or Medical toolkit license and unlock key. For more information, refer to: Imaging Pro/Document/Medical Features