DocumentReaderPage Class
Summary
Contains information about a page in the document.
Syntax
[DataContractAttribute(Name="DocumentReaderPage")]
public class DocumentReaderPage
Public Class DocumentReaderPage
public ref class DocumentReaderPage
Example
Public Sub DocumentReaderPageExample()
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 using default options
Dim reader As DocumentReader = DocumentReader.Create(documentFileName, Nothing)
' Show the document properties
Dim sb As New StringBuilder()
sb.AppendFormat("Reader used: {0}\n", reader.ReaderType)
sb.AppendFormat("Document has {0} pages\n", reader.Pages.Count)
' Get the properties (meta data)
Dim props As IDictionary(Of String, String) = reader.GetProperties()
For Each prop As KeyValuePair(Of String, String) In props
sb.AppendFormat("{0}: {1}\n", prop.Key, prop.Value)
Next
MessageBox.Show(sb.ToString())
' Now show the pages sizes
sb = New StringBuilder()
For Each page As DocumentReaderPage In reader.Pages
sb.AppendFormat("Page: {0} size: {1}\n", page.PageNumber, page.Size)
Next
MessageBox.Show(sb.ToString())
' Now loop and show the text for each page till use cancels
' If this is a Raster document such as TIFF or JPEG, we must use an OCR engine
Dim ocrEngine As IOcrEngine = Nothing
If reader.ReaderType = DocumentReaderType.Raster Then
ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, False)
ocrEngine.Startup(Nothing, Nothing, Nothing, LEAD_VARS.OcrAdvantageRuntimeDir)
End If
reader.ObjectManager.BeginParse(ocrEngine)
For Each page As DocumentReaderPage In reader.Pages
' Parse this page
Dim pageText As DocumentPageText = reader.ObjectManager.ParsePageText(page)
Dim text As String = pageText.BuildText()
If MessageBox.Show(text, String.Format("Page {0} text, continue to next page?", _
page.PageNumber), MessageBoxButtons.YesNo) = _
System.Windows.Forms.DialogResult.No Then
Exit For
End If
Next
reader.ObjectManager.EndParse()
If Not IsNothing(ocrEngine) Then
ocrEngine.Dispose()
End If
reader.Dispose()
End Sub
public void DocumentReaderPageExample()
{
string documentFileName;
using(OpenFileDialog dlg = new OpenFileDialog())
{
if(dlg.ShowDialog() != DialogResult.OK)
{
return;
}
documentFileName = dlg.FileName;
}
// Load the document using default options
DocumentReader reader = DocumentReader.Create(documentFileName, null);
// Show the document properties
StringBuilder sb = new StringBuilder();
sb.AppendFormat("Reader used: {0}\n", reader.ReaderType);
sb.AppendFormat("Document has {0} pages\n", reader.Pages.Count);
// Get the properties (meta data)
IDictionary<string, string> props = reader.GetProperties();
foreach(KeyValuePair<string, string> prop in props)
{
sb.AppendFormat("{0}: {1}\n", prop.Key, prop.Value);
}
MessageBox.Show(sb.ToString());
// Now show the pages sizes
sb = new StringBuilder();
foreach(DocumentReaderPage page in reader.Pages)
{
sb.AppendFormat("Page: {0} size: {1}\n", page.PageNumber, page.Size);
}
MessageBox.Show(sb.ToString());
// Now loop and show the text for each page till use cancels
// If this is a Raster document such as TIFF or JPEG, we must use an OCR engine
IOcrEngine ocrEngine = null;
if(reader.ReaderType == DocumentReaderType.Raster)
{
ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, false);
ocrEngine.Startup(null, null, null, LEAD_VARS.OcrAdvantageRuntimeDir);
}
reader.ObjectManager.BeginParse(ocrEngine);
foreach(DocumentReaderPage page in reader.Pages)
{
// Parse this page
DocumentPageText pageText = reader.ObjectManager.ParsePageText(page);
string text = pageText.BuildText();
if(MessageBox.Show(text, string.Format("Page {0} text, continue to next page?", page.PageNumber), MessageBoxButtons.YesNo) == DialogResult.No)
{
break;
}
}
reader.ObjectManager.EndParse();
if(ocrEngine != null)
{
ocrEngine.Dispose();
}
reader.Dispose();
}
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