An open API service indexing awesome lists of open source software.

https://github.com/katalon-studio/katalon-studio-pdf-keywords-plugin


https://github.com/katalon-studio/katalon-studio-pdf-keywords-plugin

critical

Last synced: 7 months ago
JSON representation

Awesome Lists containing this project

README

          

# Katalon Studio PDF Keywords Plugin

The PDF Keywords Plugin allows testers to manipulate existing PDF documents and extract content from them. This plugin comes with a sample test case that helps you develop further to suit your testing's purposes.
## Set Parameter

The PDF Keywords plugin uses the PDFbox library. To activate the plugin, follow these steps:

1. Download **Apache PDFBox version 2.0.24**. You can download it here: [Apache PDFBox](https://www.apache.org/dyn/closer.lua/pdfbox/2.0.24/pdfbox-app-2.0.24.jar).
2. Return to Katalon Studio, go to **Project > Settings > Library Management**.
3. In the **External Libraries**, click **Add** to browse the .jar file downloaded from Step 1. Click **Apply and Close**. Katalon Studio automatically imports the library into the project.
## Execute Test Cases

### Enable the PDF Keywords Plugin

1. Download and unzip the **PDF Keywords Plugin** project.
2. Copy and paste your testing PDF files in **Project Folder\Data Files**.
3. Open the **PDF Keywords Plugin** project in Katalon Studio. To create a new test case, go to **File > New > Test Case**.
4. In the new test case, switch to the **Script** tab, use the sample code below to enable the **PDF Keywords Plugin**:

``` groovy
import com.kms.katalon.core.util.KeywordUtil as KeywordUtil
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import internal.GlobalVariable as GlobalVariable
import com.kms.katalon.core.configuration.RunConfiguration as RunConfiguration

// To specify the path to data files
String path = RunConfiguration.getProjectDir() + '/Data Files/'

```

### Use the PDF Keywords Plugin

PDF keywords Plugin offers 14 custom keywords to help you start automating tests with PDF documents.

- To get the total number of pages of the PDF documents, use the following keyword:

getPageNumber

### Description

This keyword gets the total number of pages in the document.
### Parameters

Parameter
Type
Mandatory
Description

File

String

Required
The absolute file path

### Example

To get the total number of pages of the **Test_text1.pdf** PDF document, copy and paste the sample code as below:

``` groovy
import com.kms.katalon.core.util.KeywordUtil as KeywordUtil
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import internal.GlobalVariable as GlobalVariable
import com.kms.katalon.core.configuration.RunConfiguration as RunConfiguration

String path = RunConfiguration.getProjectDir() + '/Data Files/'

CustomKeywords.'com.kms.katalon.keyword.pdf.PDF.getPageNumber'(path + 'test_text1.pdf')

```

 

- To format the content of the PDF file as plain text, use any of the following keywords:

getTextFromPage

### Description

This keyword formats a specific PDF page as plain text.
### Parameters

Parameter
Type
Mandatory
Description

File

String

Required
The absolute file path

startPage

int

Required
The page number of the desired PDF page

### Example

To get the Page 3 of the **Test_text1.pdf** PDF document as plain text, copy and paste the sample code as below:

``` groovy
import com.kms.katalon.core.util.KeywordUtil as KeywordUtil
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import internal.GlobalVariable as GlobalVariable
import com.kms.katalon.core.configuration.RunConfiguration as RunConfiguration

String path = RunConfiguration.getProjectDir() + '/Data Files/'

CustomKeywords.'com.kms.katalon.keyword.pdf.PDF.getTextFromPage'(path + 'test_text1.pdf', 3)

```

getTextInPageRange

### Description

This keyword formats a selected range of pages from the PDF as plain text.

### Parameters

Parameter
Type
Mandatory
Description

File

String

Required
The absolute file path

startPage

int

Required
The starting page number of the page range

endPage

int

Required
The ending page number of the page range

### Example

To get pages 1-3 of the **Test_text1.pdf** PDF document as plain text, copy and paste the sample code as below:

``` groovy
import com.kms.katalon.core.util.KeywordUtil as KeywordUtil
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import internal.GlobalVariable as GlobalVariable
import com.kms.katalon.core.configuration.RunConfiguration as RunConfiguration

String path = RunConfiguration.getProjectDir() + '/Data Files/'

CustomKeywords.'com.kms.katalon.keyword.pdf.PDF.getTextInPageRange'(path + 'test_text1.pdf', 1, 3)

```

getAllText

### Description

This keyword formats the entire PDF as plain text.
### Parameters

Parameter
Type
Mandatory
Description

File

String

 Required
The absolute file path

### Example

To get all pages of the **Test_text1.pdf** PDF document as plain text, copy and paste the sample code as below:

``` groovy
import com.kms.katalon.core.util.KeywordUtil as KeywordUtil
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import internal.GlobalVariable as GlobalVariable
import com.kms.katalon.core.configuration.RunConfiguration as RunConfiguration

String path = RunConfiguration.getProjectDir() + '/Data Files/'

CustomKeywords.'com.kms.katalon.keyword.pdf.PDF.getAllText'(path + 'test_text1.pdf')

```

 

- To compare the content between two PDF files, use any of the following keywords:

compareFromPage

### Description

This keyword compares a particular page of two given PDF documents. The value returns true if the pages match, false if they don't.
### Parameters

Parameter
Type
Mandatory
Description

file1

String

Required
The absolute file path of the expected file

file2

String

Required
The absolute file path of the actual file

startPage

int

Required
The page number of the specific PDF page

excludePattern

def

Optional
The strings need to exclude from the comparison

### Example

1. To compare Page 3 of the **Test_text1.pdf** and the **Test_text2.pdf** without excluding any strings, copy and paste the sample code as below:

``` groovy
import com.kms.katalon.core.util.KeywordUtil as KeywordUtil
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import internal.GlobalVariable as GlobalVariable
import com.kms.katalon.core.configuration.RunConfiguration as RunConfiguration

String path = RunConfiguration.getProjectDir() + '/Data Files/'

CustomKeywords.'com.kms.katalon.keyword.pdf.PDF.compareFromPage'(path + 'test_text1.pdf', path + 'test_text2.pdf', 3, null)

```
2. To compare Page 3 of the **Test_text1.pdf** and the **Test_text2.pdf** excluding the **1998**, **1999** strings, copy and paste the sample code as below:

``` groovy
import com.kms.katalon.core.util.KeywordUtil as KeywordUtil
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import internal.GlobalVariable as GlobalVariable
import com.kms.katalon.core.configuration.RunConfiguration as RunConfiguration

String path = RunConfiguration.getProjectDir() + '/Data Files/'

CustomKeywords.'com.kms.katalon.keyword.pdf.PDF.compareFromPage'(path + 'test_text1.pdf', path + 'test_text2.pdf', 3, ['1998', '1999'])

```

compareInPageRange

### Description

This keyword compares a range of pages from two given PDF documents. The value returns true if the pages match, false if they don't.

### Parameters

Parameter
Type
Mandatory
Description

file1

String

Required
The absolute file path of the expected file

file2

String

Required
The absolute file path of the actual file

startPage

int

Required
The starting page number of the page range

endPage

int

Required
The ending page number of the page range

excludePattern

def

Optional
The strings need to exclude from the comparison

### Example

1. To compare pages 1-3 of the **Test_text1.pdf** and the **Test_text2.pdf** without excluding any strings, copy and paste the sample code as below:

``` groovy
import com.kms.katalon.core.util.KeywordUtil as KeywordUtil
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import internal.GlobalVariable as GlobalVariable
import com.kms.katalon.core.configuration.RunConfiguration as RunConfiguration

String path = RunConfiguration.getProjectDir() + '/Data Files/'

CustomKeywords.'com.kms.katalon.keyword.pdf.PDF.compareInPageRange'(path + 'test_text1.pdf', path + 'test_text2.pdf', 1, 3, null)

```
2. To compare pages 1-3 of the **Test_text1.pdf** and the **Test_text2.pdf** excluding the **1998**, **1999** strings, copy and paste the sample code as below:

``` groovy
import com.kms.katalon.core.util.KeywordUtil as KeywordUtil
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import internal.GlobalVariable as GlobalVariable
import com.kms.katalon.core.configuration.RunConfiguration as RunConfiguration

String path = RunConfiguration.getProjectDir() + '/Data Files/'

CustomKeywords.'com.kms.katalon.keyword.pdf.PDF.compareInPageRange'(path + 'test_text1.pdf', path + 'test_text2.pdf', 1, 3, ['1998', '1999'])

```

compareAllPages

### Description

This keyword compares all pages of two given PDF documents. The value returns true if the pages match, false if they don't.

### Parameters

Parameter
Type
Mandatory
Description

file1

String

Required
The absolute file path of the expected file

file2

String

Required
The absolute file path of the actual file

excludePattern

def

Optional
The strings need to exclude from the comparison

### Example

1. To compare all pages of the **Test_text1.pdf** and the **Test_text2.pdf** without excluding any strings, copy and paste the sample code as below:

``` groovy
import com.kms.katalon.core.util.KeywordUtil as KeywordUtil
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import internal.GlobalVariable as GlobalVariable
import com.kms.katalon.core.configuration.RunConfiguration as RunConfiguration

String path = RunConfiguration.getProjectDir() + '/Data Files/'

CustomKeywords.'com.kms.katalon.keyword.pdf.PDF.compareAllPages'(path + 'test_text1.pdf', path + 'test_text2.pdf', null)

```
2. To compare all pages of the **Test_text1.pdf** and the **Test_text2.pdf** excluding the **1998**, **1999** strings, copy and paste the sample code as below:

``` groovy
import com.kms.katalon.core.util.KeywordUtil as KeywordUtil
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import internal.GlobalVariable as GlobalVariable
import com.kms.katalon.core.configuration.RunConfiguration as RunConfiguration

String path = RunConfiguration.getProjectDir() + '/Data Files/'

CustomKeywords.'com.kms.katalon.keyword.pdf.PDF.compareAllPages'(path + 'test_text1.pdf', path + 'test_text2.pdf', ['1998', '1999'])

```

 

- To compare two PDF files pixel by pixel for content and format, use the following keyword:

compareByPixel

### Description

This keyword compares a range of pages from two PDF documents pixel by pixel for the content and format. The value returns true if the pages match, false if they don't.
### Parameters

Parameter
Type
Mandatory
Description

file1

String

Required
The absolute file path of the expected file

file2

String

Required
The absolute file path of the actual file

startPage

int

Required
The starting page number of the page range

endPage

int

Required
The ending page number of the page range

highlightImageDifferences

boolean

Required
To highlight differences in the images

showAllDifferences

boolean

Required
To compare all pages of the PDF files.

By default, the test exits as soon as the value returns as false.

To turn off default setting, go to Keywords > PDFUtils.groovy in Katalon and set bCompareAllPages as true.

### Example

To compare all pages of the **Test_text1.pdf** and the **Test_text2.pdf** pixel by pixel for content and format, copy and paste the sample code as below:

``` groovy
import com.kms.katalon.core.util.KeywordUtil as KeywordUtil
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import internal.GlobalVariable as GlobalVariable
import com.kms.katalon.core.configuration.RunConfiguration as RunConfiguration

String path = RunConfiguration.getProjectDir() + '/Data Files/'

CustomKeywords.'com.kms.katalon.keyword.pdf.PDF.compareByPixel'(path + 'test_image1_diff.pdf', path + 'test_image2_diff.pdf', -1, -1, true, false)

```

 

- To save PDF pages as images, use any of the following keywords:

savePageAsImage

### Description

To save a specific PDF page as an image. By default, the images are saved to your **Project Folder\Data Files\Temp**.
### Parameters

Parameter
Type
Mandatory
Description

File

String

Required
The absolute file path

startPage

int

Required
The page number of the desired PDF page

### Example

To save the Page 3 of the **Test_text1.pdf** PDF document as an image, copy and paste the sample code as below:

``` groovy
import com.kms.katalon.core.util.KeywordUtil as KeywordUtil
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import internal.GlobalVariable as GlobalVariable
import com.kms.katalon.core.configuration.RunConfiguration as RunConfiguration

String path = RunConfiguration.getProjectDir() + '/Data Files/'

CustomKeywords.'com.kms.katalon.keyword.pdf.PDF.savePageAsImage'(path + 'test_text1.pdf', 3)

```

savePageRangeAsImages

### Description

To save a range of PDF pages as images. By default, the images are saved to your **Project Folder\Data Files\Temp**.
### Parameters

Parameter
Type
Mandatory
Description

file1

String

Required
The absolute file path of the expected file

startPage

int

Required
The starting page number of the page range

endPage

int

Required
The ending page number of the page range

### Example

To save pages 1-3 of the **Test_text1.pdf** PDF document as images, copy and paste the sample code as below:

``` groovy
import com.kms.katalon.core.util.KeywordUtil as KeywordUtil
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import internal.GlobalVariable as GlobalVariable
import com.kms.katalon.core.configuration.RunConfiguration as RunConfiguration

String path = RunConfiguration.getProjectDir() + '/Data Files/'

CustomKeywords.'com.kms.katalon.keyword.pdf.PDF.savePageRangeAsImages'(path + 'test_text1.pdf', 1, 3)

```

saveAllPagesAsImages

### Description

This keyword saves all pages of the PDF document as images. By default, the images are saved to your **Project Folder\Data Files\Temp**.

### Parameters

Parameter
Type
Mandatory
Description

File

String

Required
The absolute file path

### Example

To save all pages of the **Test_text1.pdf** PDF document as images, copy and paste the sample code as below:

``` groovy
import com.kms.katalon.core.util.KeywordUtil as KeywordUtil
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import internal.GlobalVariable as GlobalVariable
import com.kms.katalon.core.configuration.RunConfiguration as RunConfiguration

String path = RunConfiguration.getProjectDir() + '/Data Files/'

CustomKeywords.'com.kms.katalon.keyword.pdf.PDF.saveAllPagesAsImages'(path + 'test_text1.pdf')

```

 

- To extract and save images from PDF pages, use any of the following keywords:

extractImagesFromPage

### Description

This keyword extracts all the embedded images from a specific PDF page. By default, the images are saved to your **Project Folder\Data Files\Temp**.
### Parameters

Parameter
Type
Mandatory
Description

File

String

Required
The absolute file path

startPage

int

Required
The page number of the desired PDF page

### Example

To extract all images from Page 3 of the **Test_text1.pdf** PDF document, copy and paste the sample code as below:

``` groovy
import com.kms.katalon.core.util.KeywordUtil as KeywordUtil
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import internal.GlobalVariable as GlobalVariable
import com.kms.katalon.core.configuration.RunConfiguration as RunConfiguration

String path = RunConfiguration.getProjectDir() + '/Data Files/'

CustomKeywords.'com.kms.katalon.keyword.pdf.PDF.extractImagesFromPage'(path + 'test_text1.pdf', 3)

```

extractImagesInPageRange

### Description

This keyword extracts all the embedded images from a range of PDF pages. By default, the images are saved to your **Project Folder\Data Files\Temp**.
### Parameters

Parameter
Type
Mandatory
Description

file1

String

Required
The absolute file path of the expected file

startPage

int

Required
The starting page number of the page range

endPage

int

Required
The ending page number of the page range

### Example

To extract all images from pages 1-3 of the **Test_text1.pdf** PDF document, copy and paste the sample code as below:

``` groovy
import com.kms.katalon.core.util.KeywordUtil as KeywordUtil
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import internal.GlobalVariable as GlobalVariable
import com.kms.katalon.core.configuration.RunConfiguration as RunConfiguration

String path = RunConfiguration.getProjectDir() + '/Data Files/'

CustomKeywords.'com.kms.katalon.keyword.pdf.PDF.extractImagesFromPage'(path + 'test_text1.pdf', 1, 3)

```

extractAllImages

### Description

This keyword extracts all the embedded images from all pages in the PDF document. By default, the images are saved to your **Project Folder\Data Files\Temp**.

### Parameters

Parameter
Type
Mandatory
Description

File

String

Required
The absolute file path

### Example

To extract all images from all pages of the **Test_text1.pdf** PDF document, copy and paste the sample code as below:

``` groovy
import com.kms.katalon.core.util.KeywordUtil as KeywordUtil
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import internal.GlobalVariable as GlobalVariable
import com.kms.katalon.core.configuration.RunConfiguration as RunConfiguration

String path = RunConfiguration.getProjectDir() + '/Data Files/'

CustomKeywords.'com.kms.katalon.keyword.pdf.PDF.extractAllImages'(path + 'test_text1.pdf')

```

 

You can also customize the **VerifyPDFkeywords** sample test case that comes along with this project for your testing purpose.

6. Check the test case results in the **Log viewer** tab.

Results in Log Viewer Tab

## License

Copyright (c) Katalon LLC. All rights reserved.

Licensed under the LICENSE AGREEMENT FOR KATALON AUTOMATION FRAMEWORK.