public IList<PDFObject> Objects { get; }
An IList of PDFObject items that contain the objects found on the page. The default value is null.
LEADTOOLS toolkits support parsing the following objects: text items (characters), images and rectangles. For more information, refer to PDFObject.
By default, the Annotations, Objects, FormFields, Signatures and Hyperlinks lists are not populated when a new PDFDocument is created and the values of these properties are null. You must call the PDFDocument.ParsePages method to parse the items are you interested in (depending on the PDFParsePagesOptions passed as the options parameter to the method). This is done for performance reasons and to give the user the ability to parse only the objects and pages of interest.
The Objects list will be populated if PDFParsePagesOptions.Objects is passed as part of the options parameter to PDFDocument.ParsePages. After this method returns, all the pages parsed will have their Objects properties populated either with a list of the objects found in the page or an empty list (with IList
When parsing is finished, the Objects and Hyperlinks properties will contain a list of the PDFObject and PDFHyperlink items found on the page (if PDFParsePagesOptions.Objects and PDFParsePagesOptions.Hyperlinks was selected). Each of these items contain a PDFTextProperties object that contain the text properties of the item such its font information and color. One of these properties is PDFTextProperties.FontIndex which is the 0-based integer index to the font of the item in the Fonts list.
If PDFParsePagesOptions.Fonts is not passed to PDFDocument.ParsePages, but PDFParsePagesOptions.Objects and PDFParsePagesOptions.Hyperlinks was selected, then the fonts are not parsed and the PDFTextProperties.FontIndex value of any returned object will be 0.
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Pdf;
using Leadtools.WinForms;
public void PDFDocumentPageExample()
{
string pdfFileName = Path.Combine(LEAD_VARS.ImagesDir, @"Leadtools.pdf");
string txtFileName = Path.Combine(LEAD_VARS.ImagesDir, @"LEAD_pdf.txt");
// Open the document
using (PDFDocument document = new PDFDocument(pdfFileName))
{
// Parse everything and for all pages
PDFParsePagesOptions options = PDFParsePagesOptions.All;
document.ParsePages(options, 1, -1);
// Save the results to the text file for examining
using (StreamWriter writer = File.CreateText(txtFileName))
{
foreach (PDFDocumentPage page in document.Pages)
{
writer.WriteLine("Page {0}", page.PageNumber);
IList<PDFObject> objects = page.Objects;
writer.WriteLine("Objects: {0}", objects.Count);
foreach (PDFObject obj in objects)
{
writer.WriteLine(" ObjectType: {0}", obj.ObjectType.ToString());
writer.WriteLine(" Bounds: {0}, {1}, {2}, {3}", obj.Bounds.Left, obj.Bounds.Top, obj.Bounds.Right, obj.Bounds.Bottom);
WriteTextProperties(writer, obj.TextProperties);
writer.WriteLine(" Code: {0}", obj.Code);
writer.WriteLine("------");
}
writer.WriteLine("---------------------");
IList<PDFHyperlink> hyperlinks = page.Hyperlinks;
writer.WriteLine("Hyperlinks: {0}", hyperlinks.Count);
foreach (PDFHyperlink hyperlink in hyperlinks)
{
writer.WriteLine(" Hyperlink: {0}", hyperlink.Hyperlink);
writer.WriteLine(" Bounds: {0}, {1}, {2}, {3}", hyperlink.Bounds.Left, hyperlink.Bounds.Top, hyperlink.Bounds.Right, hyperlink.Bounds.Bottom);
WriteTextProperties(writer, hyperlink.TextProperties);
}
writer.WriteLine("---------------------");
}
}
}
}
private static void WriteTextProperties(StreamWriter writer, PDFTextProperties textProperties)
{
writer.WriteLine(" TextProperties.FontHeight: {0}", textProperties.FontHeight.ToString());
writer.WriteLine(" TextProperties.FontWidth: {0}", textProperties.FontWidth.ToString());
writer.WriteLine(" TextProperties.FontIndex: {0}", textProperties.FontIndex.ToString());
writer.WriteLine(" TextProperties.IsEndOfWord: {0}", textProperties.IsEndOfWord.ToString());
writer.WriteLine(" TextProperties.IsEndOfLine: {0}", textProperties.IsEndOfLine.ToString());
writer.WriteLine(" TextProperties.Color: {0}", textProperties.Color.ToString());
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images";
}