## 3 Methods
### Overview of the Employed Techniques
#### 3.1.1 Core Python Packages  
This section gives an insight into four techniques used for text extraction from PDF documents, namely Pypdf2 [39], Pdfminersix [40], Pymupdf [41], and Pdfotext [32]. Pypdf2 is a Python toolkit or package for working with PDF files in the Python programming language. It evolved from the package Pypdf [42], which is no longer maintained by its original creator. Pypdf2 can extract data from PDF files and split, merge, or manipulate PDF files. This package must be used in the Python programming language, and there is no single executable script available for this package. This package converts all text from each PDF file as a page; the section selection option is not available in this package. The Pypdf2 tool uses StringIO instead of FileStreams and is thus more memory efficient. To extract text with this tool, the PDF file must be loaded as a binary object using the tool's pdfFileObj. Then this object is parsed using the PdfFileReader method. The text is extracted from this object using the extractText method. This extractText method checks whether the binary object is a TextStringObject or not. If it is a TextStringObject, the tool saves the object as text and returns the text to the user. Algorithm 1 describes the steps to extract the text using the Pypdf2 tool. ```
1:Input: pdf file
2:Output: text file
3:Get the pdf file as binary object \(pdfFileObj\)
4:Assign the \(pdfFileObj\) to \(pdfReader\) object
5:Get the page number count from the \(pdfReader\) object
6:for each page do
7:extract text using \(extractText\)
8:append \(extracted\) in memory
9:endfor
10:return\(extracted\)\(\_text\)
```  
**Algorithm 1** Text extraction using Pypdf2 tool  
Pdfminer.six  
Pdfminer-six is a fork of the original Pdfminer [43] package. This version is maintained by the community, as the original Pdfminer package is no longer supported. The Pdfminer-six package is focused on text extraction and analysis. It extracts data directly from PDFfiles. This package can be used with the Python programming language as well as with a single executable script. In addition to direct text conversion from PDF files, this package also provides functions for extracting tables, interactive forms in Acroform, images, and tagged content. This tool extracts text from PDF files using a layout analysis algorithm (LA) [44]. The LA works in three phases. First, it groups characters into words and lines, then it arranges lines into boxes, and finally, it arranges the boxes hierarchically and returns the text content. To extract text from PDF documents using the pdfminer.six tool, the target PDF file is loaded as a binary object, and this binary object is then parsed using the PDFParser method. After parsing the document using the PDFResourceManager, it is split into different page objects from which the texts are extracted as StringIO objects. Finally, the texts are extracted from the StringIO object and saved as a plain text file. Algorithm 2 presents the flow for extracting text using Pdfminer.six package. ```
Input: pdf file Output: text file
1: Define \(output\_string\) as StringIO
2: Get the pdf file as binary object by PDFParser
3: Initialize \(PDFResourceManager\)
4: Define \(device=TextConverter(srcrmgr,output\_string,lparams=LAPParams())\)
5: Generate \(PDFPageInterpreter\) with device and resource manager
6:for each page do
7: process page
8: append extracted text to \(output\_string\)
9:endfor
10: Get extracted text from \(output\_string\) and store as a plain text file
11:return text file
```  
**Algorithm 2** Text extraction using Pdfminer.six tool  
Pymupdf  
It is a Python wrapper for mupdf [45], a lightweight toolkit for rendering PDF, xps, and ebooks. It provides various features for rendering PDF files with high quality and high processing speed. This package must be used in the Python programming language and does not provide a single executable script. Pymupdf extracts text from PDF documents using the tool's TextPage class. A TextPage consists of blocks, such as paragraphs.