Skip to content

PDF Actions

PDF Actions are actions to interact with PDF files during automations.

Text Box

To easilly identify and works with complex PDF files, Marvin user the concept of Text Boxes.

A Text box is a square that rounds all texts on a PDF file, making it simple to grab information from PDF files, without need to do any complex text manipulations or search.

Text Box in Practice

Consider that we have a PDF file as shown in the image above, and we want to get text information from them: Sample PDF file

Using the pdfparser.exe tool that came with Marvin, you can highlight all boxes inside the PDF, making it simple get PDF content.

Now the same PDF has all text highlighten on text boxes.

Sample PDF file with boxes highlighted

To get any of this information you just need to give a search box and Marvin will retrieve you all texts inside that area, with no text manipulation needed.

To get the X,Y position you can use the PDF image with boxes hightlighted from pdfparser.exe and get the X,Y using your favorite image editor as MS Paint.

Further in this page, you can get more informations about each pdf action, and how to use it.

A Search Box is a rectangle inside the PDF file where Marvin can search for any texts inside it.

Search box will always have 4 coordinates: X1, Y1, X2 and Y2.

X1 - the Left most position of the search box

Y1 - the Top most position of the search box

X2 - the Right most position of the search box

Y2 - the Bottom most position of the search box

X,Y position example for search box

Example 1:

At this example we will return a single text box value. To do this, we need to give Marvin a search box as shown in the image above in red:

Search box example in red

This search box will return the text Value 1.

Example 2:

At this example we will get more than one text box at the same search. To do this, we need to give Marvin a search box as shown in the image above in red:

Search box example in red

In the given example, the search box will return the content of two different text boxes, separated by [text] line:

Column 1:
[text]
Value 1

Actions

pdf.get_text

Get all text boxes inside the search box area, starting left/up on X1,Y1 ending right/bottom on X2, Y2.

Parameters:

pdf - can be a path to a PDF file or a PDF object already opened by pdf.open_file.

page_num - defines the page number to get all texts from. Pages always starts from one.

x1 - left position of the search box

y1 - top position of the search box

x2 - right position of the search box

y2 - right position of the search box

intersection_mode (optional) - defines how Marvin will understand if a text box is inside the search area or not. For more information read the intersection mode section.

factor (optional) - this is the factor used by the chosen intersection_mode. For more information read the intersection mode section.

Returns:

text - Text from all text boxes inside the search box area. If more than one text box were found, the text inside each text box will be separated by a [text] line.

pdf.get_text_at

Get all text boxes that crosses the given X, Y position. Beside use a search box, this action uses the X, Y position.

Parameters:

pdf - can be a path to a PDF file or a PDF object already opened by pdf.open_file.

page_num - defines the page number to get all texts from. Pages always starts from one.

x - X coordinate to find a text box

y - Y coordinate to find a text box

Returns:

text - Text from all text boxes that crosses the given X,Y position. If more than one text box were found, the text inside each text box will be separated by a [text] line.

pdf.get_text_by_reference

Get all text boxes inside the search box area. The box area is defined as a reference of the reference_text relative position.

Parameters:

pdf - can be a path to a PDF file or a PDF object already opened by pdf.open_file.

page_num - defines the page number to get all texts from. Pages always starts from one.

reference_text - a text that its box must be used as a reference for the search box position

x1_offset - how many pixels the search box is from the left of the reference_text (negative for left side and positive for right side)

y1_offset - how many pixels the search box is from the top of the reference_text (negative for upper and positive for down)

x2_offset - how many pixels the search box is from the right of the reference_text (negative for left side and positive for right side)

y2_offset - how many pixels the search box is from the bottom of the reference_text (negative for upper and positive for down)

intersection_mode (optional) - defines how Marvin will understand if a text box is inside the search area or not. For more information read the intersection mode section.

factor (optional) - this is the factor used by the chosen intersection_mode. For more information read the intersection mode section.

Returns:

text - Text from all text boxes inside the search box area. If more than one text box were found, the text inside each text box will be separated by a [text] line.

pdf.get_texts

Used to retrive more than one information at the same time, given each search a diferent process var name. This actions searches for text boxes inside a list of search boxes.

Parameters:

pdf - can be a path to a PDF file or a PDF object already opened by pdf.open_file.

page_num - defines the page number to get all texts from. Pages always starts from one.

boxes - a list of search boxes with each search boxes having a specific process var name, defined as:

[
    {'proc_var1': (X1, Y1, X2, Y2)},
    {'proc_var2': (X1, Y1, X2, Y2)},
]

intersection_mode (optional) - defines how Marvin will understand if a text box is inside the search area or not. For more information read the intersection mode section.

factor (optional) - this is the factor used by the chosen intersection_mode. For more information read the intersection mode section.

Returns:

text - Text from all text boxes inside the search box area. If more than one text box were found, the text inside each text box will be separated by a [text] line.

pdf.open_file

Opens a PDF file and returns it as a object for future usage on other actions.

Parameters:

pdf - path to a PDF file.

Returns:

pdf - PDF object representing the given PDF file.