Recommend this page to a friend! |
Classes of Christian Vigh | PHP PDF to Text | README.md | Download |
|
DownloadINTRODUCTIONThe PdfToText class has been designed to extract textual contents from a PDF file. It's pretty simple to use :
The same PdfToText object can be reused to process additional files :
Additionally, the PdfToText class provides support methods for getting the page number of any text in the underlying PDF file. Look at the class' blog for an overview on the underlying mechanics that are involved into extracting text contents from pdf files. Examples are also provided in the examples/ directory. Please have a look at the examples/README.md file for a brief explanation on their structure. IMPORTANT : the PdfToText class generates UTF8-encoded text. If your default character set is not UTF-8, you may need to add the following meta tag in the <head> part of your HTML page :
FEATURESText rendering in a PDF file is made using an obscure language which provides multiple ways to position the same text at the same location on a page. You could say for example :
Or :
(note that I'm using a pseudo-language here). Both pieces of code would probably display the same text at the same position, by using rather different ways. This is why the PdfToText class tracks the following information from the drawing-instruction stream to provide more accurate text rendering (even if the output is only pure text) :
These symptoms will not appear if the PDFOPT\_BASIC\_LAYOUT option is specified. ADVANCED FEATURESThe class is able to :
KNOWN ISSUESHere is a list about known issues for the PdfToText class ; I'm working on solving them, so I hope this whole paragraph will soon completely disappear !
A NOTE FOR WINDOWS USERSAn Apache server on Linux platforms allocates a default stack size of 8Mb for its threads. This value is set to 1Mb on Windows platforms. However, some regular expressions used by the PdfToText class may cause the PHP PCRE extension to require a little bit more than 1Mb of stack space when processing certain PDF files. Such a situation will cause your Windows Apache server to crash and your browser to display a message such as : Connection reset. This behavior affect several products such as EasyPHP, XAMPP or Wamp. To solve this issue, you will have to enable the mpm module in your httpd.conf file and define a new stack size, as in the following example, given for a Wamp server :
TESTINGI have tested this class against dozens of documents from various origins, and tested the output generated from each sample document by the PdfCreator, PrimoPdf and PDF Pro tools. I also compared the output of the PdfToText class with that of Acrobat Reader, when you choose the Save as...Text option. In many situations, the class performs better in positioning the final text than Acrobat Reader does. However, all of that will not guarantee that it will work in every situation ; so, if you find something weird or not functioning properly using the PdfToText class, feel free to contact me on this class' blog, and/or send me a sample PDF file at the following email address :
OTHER LINKSThis class can also be found here : http://www.phpclasses.org/package/9732-PHP-Extract-text-contents-from-PDF-files.html and here, where you will also find a FAQ section and be able to upload your PDF file samples for live testing : and also here : https://github.com/christian-vigh-phpclasses/PdfToText REFERENCEMETHODSConstructor
Instantiates a PdfToText object. If a filename has been specified, its text contents will be loaded and made available in the Text property (otherwise, you will have to call the Load() method for that). See the Options property for a description of the $options parameter. The $user\_password and $owner\_password parameters specify the user/owner password to be used for decrypting a password-protected file (note that this class is not a password cracker !). In the current version, decryption of password-protected files is not yet supported. Load ( $filename, $user\_password = false, $owner\_password = false )Loads the text contents of the specified filename. The $user\_password and $owner\_password parameters specify the user/owner password to be used for decrypting a password-protected file (note that this class is not a password cracker !). In the current version, decryption of password-protected files is not yet supported. The method returns the decoded text contents, which are also available through the Text property. LoadFromString ( $contents, $user\_password = false, $owner\_password = false )Loads the text contents of the specified PDF contents. The $user\_password and $owner\_password parameters specify the user/owner password to be used for decrypting a password-protected file (note that this class is not a password cracker !). In the current version, decryption of password-protected files is not yet supported. The method returns the decoded text contents, which are also available through the Text property. AddAdobeExtraMappings ( $mappings )Adobe supports 4 predefined fonts : standard, Mac, WinAnsi and PDF). All the characters in these fonts are identified by a character time, a little bit like HTML entities ; for example, 'one' will be the character '1', 'acircumflex' will be 'â', etc. There are thousands of character names defined by Adobe (see https://mupdf.com/docs/browse/source/pdf/pdf-glyphlist.h.html). Some of them are not in this list ; this is the case for example of the 'ax' character names, where 'x' is a decimal number. When such a character is specified in a /Differences array, then there is somewhere a CharProc[] array giving an object id for each of those characters. The referenced object(s) in turn contain drawing instructions to draw the glyph. At no point you could guess what is the corresponding Unicode character for this glyph, since the information is not contained in the PDF file. The AddAdobeExtraMappings() method allows you to specify such correspondences. Specify an array as the $mappings parameter, whose keys are the Adobe character name (for example, "a127") and values the corresponding Unicode values. The $mappings parameter is an associative array whose keys are Adobe character names. The array values can take several forms :
Note
In this current implementation, the method applies the mappings to ALL Adobe default fonts. That is, you cannot have one mapping for one Adobe font referenced in the PDF file, then a second mapping for a second Adobe font, etc. GetCaptures
Retrieves the areas of text captured by the PdfToText class. This assumes that you specified first the PDFOPT\_CAPTURE flag to the class constructor, then called either the SetCaptures() or SetCapturesFromString() method. When the $full parameter is set to false (the default), the returned object is a hierarchy of stdClass objects which maps capture names to their values. When set to true, the returned object is of type PdfToTextCaptures, which holds much more information. It should be useful only when doing internal debugging of the PdfToText class. Note : Accessing a property value when the $full parameter is false can be performed like this (here, we are accessing the value of the Title capture in the first page) :
When this parameter is true, you have to specify the Text property to retrieve its contents :
If you plan to switch between both return types during your development phase, you can use a unified approach that works in both cases :
See the Capturing Text* section for more information on capturing text from PDF files. GetFormCount
Returns the actual number of top-level forms defined in the PDF file. GetFormData
Retrieves the form data for the specified top-level form index. Data is returned as an object inheriting from class PdfToTextFormData, which provides ony helper functions to its derived classes. Data retrieval can be based on a template XML file, or, when the $template\_xml parameter is null, a default template will be created using the field names defined in the PDF file. See the Form templates later in this file to get more information on how templates are used and how form data objects are built. GetPageFromOffset ( $offset )Given a byte offset in the Text property, returns its page number in the pdf document. Page numbers start from 1. HasFormData
Returns true if the PDF file contains form data. MarkTextLike ( $regex, $mark_start, $mark_end )Sometimes it may be convenient, when you want to extract only a portion of text, to say : "I want to extract text between this title and this title". The MarkTextLike() method provides some support for such a task. Imagine you have documents that have the same structure, all starting with an "Introduction" title :
By calling the MarkTextLike() method such as in the example below :
then you will get as output :
Adding such markers in the output will allow you to easily extract the text between the chapters "Introduction" and "Some other title", using a regular expression. The font name used for the first string matched by the specified regular expression will be searched later to add markers around all the text portions using this font. The parameters are the following :
SetCaptures
Loads the capture definitions from the specified XML file. Note that you must instantiate the PdfToText class with the PDFOPT\_CAPTURE flag for this function to work. See the Capturing Text* section for more information on capturing text from PDF files. SetCapturesFromString
Same as the SetCaptures() method, but loads the capture definitions from a string instead of a file. Note that you must instantiate the PdfToText class with the PDFOPT\_CAPTURE flag for this function to work. See the Capturing Text* section for more information on capturing text from PDF files. text\_strpos, text\_stripos
These methods behave as the strpos/stripos PHP functions, except that :
Parameters are the following :
The method returns an array of two values containing the page number and text offset if the searched string has been found, or false otherwise. document\_strpos, document\_stripos
Searches for ALL occurrences of a given string in the pdf document. The value of the $group_by_page parameter determines how the results are returned :
For example, if a pdf document contains the string "here" at character offset 100 and 200 in page 1, and position 157 in page 3, the returned value will be :
The parameters are the following :
The method returns an array of page numbers/character offsets or false if the specified string does not appear in the document. text\_match, document\_match
text\_match() calls the preg\_match() PHP function on the pdf text contents, to locate the first occurrence of text that matches the specified regular expression. document\_match() calls the preg\_match\_all() function to locate all occurrences that match the specified regular expression. Note that both methods add the PREG\_OFFSET\_CAPTURE flag when calling preg\_match/preg\_match\_all so you should be aware that all captured results are an array containing the following entries :
Parameters are the following :
As for their PHP counterparts, these methods return the number of matched occurrences, or false if the specified regular expression is invalid. PROPERTIESThis section describes the properties that are available in a PdfTText object. Note that they should be considered as read-only. AuthorAuthor name, as inscribed in the PDF file. AutoSavedImageFilesWhen the PDFOPT\_AUTOSAVE\_IMAGES flag has been specified, this array of strings will contain the filenames where the auto-saved images have been put. BlockSeparatorA string to be used for separating chunks of text. The main goal is for processing data displayed in tabular form, to ensure that column contents will not be catenated. However, this does not work in all cases. The default value is the empty string. When the PDFOPT\_BASIC\_LAYOUT option is specified, this property is used to separate parts of text that are visually on a different x-axis on the same line. In this case, the default separator will be a white space. CIDTablesDirectoryPath to the directory containing CID mapping tables. CreationDateA string containing the document creation date, in UTC format. The value can be used as a parameter to the strtotime() PHP function. CreatorApplicationApplication used to create the original document. DocumentStartOffsetA PDF document normally starts with a string of the form :
where "a" and "b" (and the "c", "d", ... following) represent the version number of the PDF file. Some PDF documents may come with garbage at the beginning ; this is "illegal" of course, but Acrobat Reader is able to cope with that. So can do the PdfToText class... This property holds the byte offset in the input file where the starting "%PDF" string has been found. EncryptionAlgorithmAlgorithm used for password-protected files. The Adobe documentation states : A code specifying the algorithm to be used in encrypting and decrypting the document :
EncryptionAlgorithmRevisionThe revision number of the Standard security handler that is required to interpret this dictionary. The revision number is :
EncryptionFlagsA set of PDFPERM\_* constants describing which operations are authorized on a password-protected PDF file. EncryptionKeyLengthDefined only when EncryptionAlgorithm is 2 or 3. Length of key, in bits, used for encryption and decryption. The size is a multiple of 8, with a minimum value of 40 and maximum value of 128. EncryptionModeOne of the PDFCRYPT\_\* constants. This value is set to *PDFCRYPT\_NONE if the PDF file is not password-protected. EncryptMetadataA flag coming from a password-protected file that says is the document metadata is also encrypted. EOLThe string to be used for line breaks. The default is PHP\_EOL. ExtraTextWidthThis property is expressed in percents ; it gives the extra percentage to add to the values computed by the PdfTexterFont::GetStringWidth() method. This value is basically used when computing text positions and string lengths with the *PDFOPT\_BASIC\_LAYOUT option : the computed string length is shorter than its actual length (because of extra spacing determined by character kerning in the font data, among other details). To determine whether two consecutive blocks of text on the same should be separated by a space, the class will empirically add this extra percentage to the computed string length. The default value is -5 (percent). FilenameName of the file whose text contents have been extracted. This value will be an empty string if the LoadFromString() method has been called instead of Load(). ID, ID2A pair of unique ids generated for the document. The value of ID is used for decrypting password-protected documents. The second id is not clearly described in the Pdf specifications. ImageAutoSaveFileTemplateA template string to be used for generating filenames when the PDFOPT\_AUTOSAVE\_IMAGES flag has been specified. It can contain the following print-like formats :
The default value for this property is :
Using the template above, if your input filename is "/tmp/test.pdf" and contains 3 images, then you will get the following output images :
You can also specify a width with the "%d" format specifier ; the numbering will then be padded with leading zeroes. For example, the following template using the same example PDF file as above :
will generate the following filenames :
ImageAutoSaveFormatWhen the PDFOPT\_AUTOSAVE\_IMAGES flag has been specified, indicates the format to be used for saving the images found in the PDF file. It can be any of the constants defined by the gd library regarding image formats :
Note that the association between the constant and corresponding file suffix is automatically handled. ImagesAn array of objects inheriting from the PdfImage class. Currently, only the PdfJpegIMage class is implemented. The class currently supports the following properties :
The following methods are available :
Currently, images stored in proprietary Adobe format are not processed and will not appear in this array. Note that images will be extracted only if the PDFOPT\_DECODE\_IMAGE\_DATA is enabled. ImageCountNumber of images found in the supplied PDF file. This number will only take into account the images whose format is recognized by the PdfToText class. ImageDataAn array of associative arrays that contain the following entries :
Note that image data will be extracted only if the PDFOPT\_GET\_IMAGE\_DATA is enabled. IsEncryptedThis property is set to true if the Pdf file is encrypted through some kind of password protection scheme. KeywordsKeywords, as recorded in the author information part. MaxExecutionTimeSpecifies a maximum execution time in seconds for processing a single file. If this limit is reached, a PdfToTextTimeoutException exception will be thrown before PHP terminates the script. This allows the script to gracefully handle the error instead of PHP itself. Positive values are indicated in seconds. Negative values are subtracted from the max\_execution\_time PHP setting to compute the maximum execution time allowed. If the computed timeout value is out of range, the retained execution time will be max\_execution\_time minus one second. The value of this property is taken into account only if the PDFOPT\_ENFORCE\_EXECUTION\_TIME option has been specified. MaxExtractedImagesMaximum number of images to be extracted. The default is the value 0, meaning that all images will be selected for output if the PDFOPT\_GET\_IMAGE\_DATA or PDFOPT\_AUTOSAVE\_IMAGES option is set. MaxGlobalExecutionTimeThis static property is the same as MaxExecutionTime, except that it works globally. If you have to process x files, then it will ensure that the global execution time does not exceed the value of this property. The value of this property is taken into account only if the PDFOPT\_ENFORCE\_GLOBAL\_EXECUTION\_TIME option has been specified. MaxSelectedPagesMaximum number of pages to be selected. The default is the value 0, meaning that all pages will be selected for output. A value of 1 will extract the contents of the first page only, which can be useful if your PDF file is large and you're only interested by the contents of the first page. When this number is negative, selection starts from the end of the file : -1 means "extract the last page", -2 means "extract the last two pages", and so on. MemoryUsage, MemoryPeakUsageReport the memory (peak) used by the Load() method. MinSpaceWidthSometimes, characters (or blocks of characters) are separated by an offset which is counted in 1/1000's of text units. For certain ranges of values, when displayed on a graphical device, these consecutive characters appear to be separated by one space (or more). Of course, when generating ascii output, we would like to have some equivalent of such spacing. This is what the MinSpaceWidth property is meant for : insert an ascii space in the generated output whenever the offset found exceeds MinSpaceWidth text units. Note that if the PDFOPT\_REPEAT\_SEPARATOR flag is set for the Options property, the number of spaces inserted will always be based on a multiple of 1000, even if MinSpaceWidth is less than 1000. This means that if MinSpaceWidth is 200, and the Options property has the PDFOPT\_REPEAT\_SEPARATOR flag set, AND the offset between two chunks of characters is 1000 text units, only one space will be inserted, not 5 (which would be the result of 1000/200). ModificationDateA string containing the last document modification date, in UTC format. The value can be used as a parameter to the strtotime() PHP function. OptionsA combination of the following flags :
will be rendered as :
or, if you set the BlockSeparator property to "#", the output will be :
will be rendered as :
PagesAssociative array containing individual page contents. The array key is the page number, starting from 1. PageSeparatorString to be used when building the Text property to separate individual pages. The default value is a newline. ProducerApplicationApplication used to generate the PDF file contents. SeparatorA string to be used for separating blocks when a negative offset less than -1000 thousands of characters is specified between two sequences of characters specified as an array notation. This trick is often used when a pdf file contains tabular data. The default value is a space. SubjectSubject written in the author information part. StatisticsAn associative array that contains the following entries :
TextA string containing the whole text extracted from the underlying pdf file. Note that pages are separated with a form feed. TitleDocument title, as specified in the author information object. Utf8PlaceholderWhen a Unicode character cannot be correctly recognized, the Utf8Placeholder property will be used as a substitution. The string can contain format specifiers recognized by the sprintf() function. The parameter passed to sprintf() is the Unicode codepoint that could not be recognized (an integer value). The default value is the empty string, or the string '[Unknown character 0x%08X]' when debug mode is enabled. Note that if you change the PdfToText::$DEBUGvariableafterthe first instantiation of the class, then you will need to manually set the value of thePdfToText::Utf8PlaceHolder* static property. CONSTANTSPDFOPT\_\*The PDFOPT\_\constants are a set of flags which can be combined when either instantiating the class or setting theOptionsproperty before calling theLoad* method. It can be a combination of any of the following flags :
will be rendered as :
or, if you set the BlockSeparator property to "#", the output will be :
will be rendered as :
PagesAssociative array containing individual page contents. The array key is the page number, starting from 1. PageSeparatorString to be used when building the Text property to separate individual pages. The default value is a newline. VERSIONCurrent version of the PdfToText class, as a string containing a major, minor and release version numbers. For example : "1.2.19". ExceptionsThe PdfToText class can throw any of the following exceptions : PdfToTextExceptionThis is the base class for all exceptions thrown by the PdfToText class. PdfToTextDecodingExceptionThis exception is thrown if an error occurs when decoding a PDF object. Normally, most of these exceptions are thrown only if debug mode is activated. PdfToTextDecryptionExceptionOccurs when decryption failed on an encrypted file. PdfToTextTimeoutExceptionThis exception is thrown only if one of the following conditions occur :
PdfToTextFormTemplateExceptionThrown when an error is detected while parsing a template file for retrieving form data, or when retrieving form data. Form data extractionExtracting form data is fairly simple : use the GetFormData() method and it will return you an object containing all the field values contained in your PDF file, whether they have been filled or not. You have two ways to retrieve form data :
Both methods return a new object inheriting from the PdfToTextFormData class, which mainly contain helper functions that have no interest for the caller. The derived class returned by the GetFormData() method has a set of properties that give you access to the form fields contents. The examples given in the following sections are based on the file "sample.pdf", located in the examples directory "examples/formdata-extraction". It has been taken from a very common form used in the US, located here : https://www.irs.gov/pub/irs-pdf/fw9.pdf Getting form data without a templateGettig form data without a template is very simply ; just execute the following code :
Of course, we should have checked first that form data is present in the PDF file by calling :
The object returned in $form\_data has the following definition :
You can open file sample.pdf to verify that the data listed above is conformant to the one contained in the PDF file. However, you will see that the field names are not very explicit : $f1\_1, $f1\_2, etc. Moreover, information such as social security number is splitted in three parts : $f1\_11, $f1\_12 and $f1\_13. This is why you may want to spend some time designing a template XML file that maps PDF field names to human-readable ones... Getting form data with a templateUsing an XML template does not require many changes to your existing code ; you just need to supply the path of your XML template when calling the GetFormData() method :
Using the supplied example, your $form\_data object will look like this :
You can notice some important differences with the templateless version :
All of the above have been defined in the template file, and the parent class, PdfToTextFormData, is able to handle any modifications made to any of the properties involved in a grouped property. For example, if you modify the SSN\_1 property, then the SSN property will be rebuilt accordingly. Similarly, if you modify the SSN property, then the SSN\_1, SSN\_2 and SSN\_3 properties will be changed accordingly. This internal work is performed by the PdfToTextFormData, from which any class returned by the GetFormData() method inherits. Now, this is time to have a look at what is a template. This is described in the next section. A typical form templateHere is the typical form that has been designed to extract form data from our sample PDF file :
The root tag is specified by <forms>. Subtags are <form> definitions. Currently, the following are implemented :
Please note that the above information could be subject to changes in future releases. Defining fieldsForm fields can currently be of three types :
A (somewhat) tedious way to get the knowledge of which PDF form field contains which data is :
String fieldsString fields within a form are basically specified with the following XML field construct :
The attributes are the following :
Choice fieldsChoice fields are typically used for a group of checkboxes that behave like radiobuttons :
They basically contain the same information as string fields, except that the type attribute is set to choice. They can be paired to a set of constants defined either through the <case> or <default> tags :
Note that each defined constant, such as TAXCLASS\_INDIVIDUAL in the above example, will be defined as a class constant in the object returned by the GetFormData() method. Grouped fieldsGrouped fields allow you to create new properties, coming from the concatenation of existing fields. A typical definition looks like this :
In our template example, we have seen that the social security number (SSN) was splitted into three parts : SSN\_1, SSN\_2 and SSN\_3. The above example creates an SSN property, which is the result of the concatenation of the specified fields. The required attributes are the following :
Note that modifying the value of a property referenced by a grouped field will modify the corresponding grouped field value. Similarly, modifying the grouped field value will modify its associated properties. Capturing textSometimes, it's easier to tell the PdfToText class which area(s) of text you want to retrieve from which page(s), rather than having to struggle with regular expressions to isolate the information you want. This is especially true when you want to retrieve data from tabular reports. Captures are a solution for such needs ; they allow you to define shapes of the following types :
Areas to be captured are specified using a capture definition file or string, in XML format. A step-by-step overviewCapturing areas of your PDF document will require you a few preliminary steps that involve some extra work. This is why you will have to choose between using captures or using regular expressions on the extracted text :
The step-by-step overview below references the files located in the examples/text-captures directory. Determining what to captureA PDF file uses a coordinate system whose values are more or less expressed in "relative units". The point at coordinates (0,0) is located at the bottom-left corner of the page ; the point at coordinates (x,y), where "x" is the page width and "y" the page height, is located at the top-right corner of the page. That's nice, but how to find the coordinates (x, y, width and height) of the rectangle that contains the text you want to capture ? of course, if you have an Adobe product that allows you to modify PDF files, it may give you such information. But if you don't have such a tool, you're stuck. The PdfToText class has a flag, PDFOPT\_DEBUG\_SHOW\_COORDINATES, that includes in the text output the (x,y) coordinates, width and height of each block of text found in the PDF stream. This may be the only occasion you will have to use this option. The following example script explains how the file sample-report.txt in the examples/text-capture directory of this package was generated :
The first few lines of file sample-report.txt now contain things like this :
instead of the default output with no specific options (see file sample-report.pdf for its graphic counterpart) :
In the output generated with the PDFOPT\_DEBUG\_SHOW\_COORDINATES option, you will notice some additional information between square brackets :
It gives the page number, its width and its height in graphics coordinates.
Designing the capture definitions file (or string)The various information added to the output using the PDFOPT\_DEBUG\_SHOW\_COORDINATES option should give you enough data to design the capture definitions file. An example is given below, which will capture some contents of the PDF file sample-report.pdf ; a more detailed explanation of this XML format is given in the XML Capture Definitions section :
Basically, the above data says that it wants to capture two things :
You may have noticed that both of the <rectangle> and <lines> contain subtags named <page> ; they define which pages of the input PDF file are applicable to the parent tag. For example :
All the coordinates, widths and heights listed in this definition have been taken from the information contained in file sample-report.txt, generated at the previous step (the above section). Setting up PdfToText to process capturesCaptures are processed independently of text extraction ; the only two things you have to do is :
Retrieving capture dataRetrieving capture data is fairly simple :
This will return an object of type PdfToTextCaptureLines. Each tag that has been defined in the XML definition file (sample-report.txt in our example) has a name ; for example, our rectangle shape has the name "Title", and the group of lines is named "ReportLines" (each report line having one column named "Column1"). Every capture name specified in the Capture definitions file can be accessed as a property name in the object returned by the GetCaptures() method :
However, the way these various informations are processed depend on the capture type :
or :
Rectangle captures are accessible by their page number. There will be a capture for each page of the document, even if not present in the list of applicable pages.
Inside a line, you can also reference a column by its name :
XML Capture definitionsThis section describes the format of an XML Capture definition. <captures> tagThe <captures> tag is the top-level node for the XML Capture definitions. It has no specific attributes and can contain one or more of the following subtags :
<rectangle> tagThe <rectangle> tag defines a rectangular area used to capture text enclosed by it. It has the following attributes :
The <rectangle> tag must specify at least one <page> subtag, to indicate the PdfToText class on which pages of the document the captured text should be searched. <page> subtagThe <page> subtag of the <rectangle> tag has the following attributes :
The special character "$" means "the last page". Expressions are allowed ; the following for example :
indicates that the rectangle area applies to page 1 and to the last 10 pages of the document. The other attributes for the <page> tag are the following :
<lines> tagThe <lines> tag allows to define a group of lines to be captured. It defines applicable pages, and provides definitions about each column to be captured. It is mainly used for capturing report lines and has the following attributes :
The <lines> tag can contain as many <page> and <column> subtags as needed. <page> subtagThe <page> subtag of the <lines> tag has more or less the same objective as the <page> subtag of the <rectangle> tag, with a few differences although. It is not used to define the shape of a rectangle, but rather the top and bottom coordinates of the first and last line of a page, along with the line height. The following attributes are available :
<column> subtagThe <column> subtag identifies a column position within a line. It has the following attributes :
Either the width or right attribute must be specified. Capture classes referenceThe object returned by the GetCaptures() method needs some explanation ; a distinction has been made between what is captured and how to access it. The GetCaptures() method returns an object hierarchy that answers the how ; every object in this hierarchy contains objects that answer the what. The method returns an object of class PdfToTextCaptures, described below. PdftoTextCaptures classThis class dynamically creates properties coming directly from the names specified with the <rectangle> and <lines> tags of the Capture XML definitions. Thus, if we take our example definition file and call the GetCaptures() method :
Then we will be able to access the properties defined in our capture file in the following way :
or :
Here is the correspondance between Capture XML definitions and the properties found in this object :
PdfToTextRectangleCapture classThis class allows to retrieve information about the text captured based on a <rectangle> definition. It behaves like an array containing elements of type PdfToTextCapturedRectangle. The reason why this class is an array is because the rectangle shape can be used to capture text at different locations on different pages. PdfToTextLinesCapture classThis class also behaves as an array that gives elements of type PdfToTextCaptureLine. It contains the lines that have been captured on the whole document. PdfToTextCapturedText class ###This is the base abstract class for the various shapes captured in the document (PdfToTextCapturedRectangle, etc.). It has the following properties :
PdfToTextCapturedRectangle classInherits from the PfToTextCapturedText class. It currently does not add any new properties or methods. PdfToTextCapturedLine classInherits from the PfToTextCapturedText class. Adds the following properties :
An object of this class can be iterated like an array. It also provides direct access to a PdfToTextCapturedColumn object by specifying its name as a property ; for example :
Of course, the column name has been specified in the Capture XML definition, with the name attribute of the <column> tag. |