Fix PDF Validation EOF Error: Katalon Studio Guide

overcoming end of file error in pdf validation with katalon studio

Getting an End of File error when validating PDFs in Katalon Studio? Learn why dynamic PDF URLs cause it and how to fix it by downloading the file locally before reading it with PDFBox.

Key takeaways
The 30-second version of this article
The End of File error appeared because the PDF's URL changed on every run, so the file wasn't read properly.
The fix: download the PDF to a local file first, then load the local copy with PDFBox.
PDFBox 3.x uses Loader.loadPDF instead of PDDocument.load, so match the code to the library version you install.
If the PDF requires a login, the download may return HTML instead of a PDF and trigger the same error.

Hello, Katalon users and software testing enthusiasts! Today, we're looking at a common issue discussed in the Katalon Community: the "End of File" exception when validating PDFs.

The Issue at Hand

One of our community members, ragrawal, recently encountered an issue while validating PDFs using Katalon Studio. They were getting an ‘End of File, expected Line Error’ despite downloading the necessary JARs through External Libraries in Katalon Studio.

Debugging the Issue

The first step suggested by Timo_Kuisma, another community member, was to debug and print out what was being passed to PDFTextStripper. However, ragrawal was still getting the 'End of File Error’.

The Root Cause

Upon further investigation, it was discovered that the issue was due to the dynamic URL of the PDF. The last ID in the URL kept changing whenever the script was run. This led to the PDF file not being read properly.

The Solution

Timo_Kuisma suggested a workaround: download the PDF first to the local machine, then load it from the path where it’s downloaded. This approach ensures that the PDF file is read properly, thus avoiding the 'End of File Error’.

Implementing the Solution in Code

Here’s a sample code snippet that implements the solution:

import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
import java.nio.file.StandardCopyOption
import org.apache.pdfbox.pdmodel.PDDocument
import org.apache.pdfbox.text.PDFTextStripper
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

// Capture the current (dynamic) PDF URL at runtime
String pdfUrl = WebUI.getUrl()
WebUI.comment(pdfUrl)

// Download the PDF to a local file first
Path pdfPath = Paths.get(System.getProperty('java.io.tmpdir'), 'downloaded.pdf')
new URL(pdfUrl).openStream().withCloseable { input ->
    Files.copy(input, pdfPath, StandardCopyOption.REPLACE_EXISTING)
}

// Load the local copy and extract its text (PDFBox 2.x)
PDDocument document = PDDocument.load(pdfPath.toFile())
try {
    String pdfContent = new PDFTextStripper().getText(document)
    println(pdfContent)
} finally {
    document.close()
}

This script captures the PDF's URL at runtime, saves the file to a local temp folder, and then loads the local copy with PDFBox, so the dynamic URL can't change mid-read. It uses the PDFBox 2.x API; if you've added PDFBox 3.x to External Libraries, replace PDDocument.load(...) with Loader.loadPDF(...) (import org.apache.pdfbox.Loader). If the PDF sits behind a login, the download may return an HTML page instead of a PDF, which also triggers an End of File error, so check the saved file if the problem persists.

Conclusion

We hope this blog post has provided you with a deeper understanding of how to handle the ‘End of File Error’ exception when validating PDFs with Katalon Studio. Remember, our Katalon Community is a great resource for troubleshooting and learning from the experiences of other Katalon users.

The information in this blog post is based on a real-life scenario shared by a user on our Katalon Community forum and is intended to inspire peer-to-peer discussion and collaboration. Please always test solutions thoroughly before implementing them in a production environment.

Feel free to continue the discussion on the Katalon forum.

Son Huynh
Son HuynhSupport Engineer

Son Huynh is a Support Engineer at Katalon, based in Ho Chi Minh City, where he helps customers solve technical issues across the Katalon platform. Before joining Katalon in 2025, he spent three years as a Professional Services Engineer at ELCA Vietnam. He studied at California State Polytechnic University, Pomona.

Connect on LinkedIn →
Get started

Test everything. Ship with confidence.

From generating test cases to spotting failures, Katalon's AI works across your entire pipeline, automatically.

Live webinar

The Next Evolution of Manual Testing: Introducing Katalon AI Test Runner

Learn how to grow your QA team's capacity in the age of AI, then watch Katalon AI Test Runner turn manual test cases into automated runs, live.

2:00 to 3:00 PM IST
Almas AhmedSenior Account Manager
Sumit WankhedeSolutions Engineer Manager
Register now