# How to Configure PDF Report Generation with pdf-config.json in anhtester/automationframeworkselenium

> Learn to configure PDF report generation using pdf-config.json in anhtester/automationframeworkselenium. Uncomment the dependency, enable initialization, and load JSON for custom reports.

- Repository: [Anh Tester/automationframeworkselenium](https://github.com/anhtester/automationframeworkselenium)
- Tags: how-to-guide
- Published: 2026-02-24

---

**To configure PDF report generation with pdf-config.json in the anhtester/automationframeworkselenium framework, uncomment the pdfextentreporter dependency in pom.xml, enable the ExtentPDFReporter initialization block in ExtentReportManager.java, and load the JSON configuration using the loadJSONConfig method.**

The anhtester/automationframeworkselenium project leverages ExtentReports for comprehensive test reporting. By integrating the **pdfextentreporter** library and modifying the central reporting class, you can generate styled PDF outputs alongside HTML reports. This guide explains exactly how to configure PDF report generation with pdf-config.json to customize document titles, colors, and layout attributes.

## Enable the PDF Reporter Dependency in pom.xml

The Maven dependency required for PDF generation is present but commented out in the project's POM file. Locate the dependency block around lines 197–202 in [`pom.xml`](https://github.com/anhtester/automationframeworkselenium/blob/main/pom.xml) and uncomment it to import the **ExtentPDFReporter** class from the *tech.grasshopper* library.

```xml
<dependency>
    <groupId>tech.grasshopper</groupId>
    <artifactId>pdfextentreporter</artifactId>
    <version>1.3.2</version>
</dependency>

```

Without this dependency, the `ExtentPDFReporter` class cannot be compiled or instantiated, preventing PDF generation entirely.

## Initialize the PDF Reporter in ExtentReportManager

The [`src/main/java/com/anhtester/reports/ExtentReportManager.java`](https://github.com/anhtester/automationframeworkselenium/blob/main/src/main/java/com/anhtester/reports/ExtentReportManager.java) file contains the reporting initialization logic. The PDF reporter code is commented out by default around lines 40–46. Uncomment this block and ensure it points to your [`pdf-config.json`](https://github.com/anhtester/automationframeworkselenium/blob/main/pdf-config.json) file.

```java
// PDF reporter – enable by uncommenting
ExtentPDFReporter pdf = new ExtentPDFReporter("reports/ExtentReports/PdfReport.pdf");
try {
    pdf.loadJSONConfig(new File("src/test/resources/pdf-config.json"));
} catch (IOException e) {
    throw new RuntimeException(e);
}
extentReports.attachReporter(pdf);

```

The `loadJSONConfig` method reads the JSON configuration and applies styling parameters such as title colors and attribute display settings to the generated document.

## Customize the PDF Output with pdf-config.json

The [`src/test/resources/pdf-config.json`](https://github.com/anhtester/automationframeworkselenium/blob/main/src/test/resources/pdf-config.json) file controls the visual presentation of your PDF reports. This configuration file supports 34+ customization options, including:

- **displayAttributeSummary** – Toggles the summary table of test attributes
- **title** – Sets the PDF document title
- **titleColor** – Defines the hex color code for the title (e.g., "964B00")
- **passColor**, **failColor**, **skipColor** – Specifies status indicator colors

Edit these values to match your branding requirements. For example, to update the title and color scheme:

```json
{
  "title": "Automation Test Report",
  "titleColor": "003366",
  "passColor": "28A745",
  "failColor": "DC3545",
  "skipColor": "FFC107",
  "displayAttributeDetails": true
}

```

Save your changes to [`pdf-config.json`](https://github.com/anhtester/automationframeworkselenium/blob/main/pdf-config.json) before executing the test suite.

## Verify the Generated PDF Report

Upon test completion, ExtentReports produces both the standard HTML report and the configured PDF document. The PDF generates at the path specified in the `ExtentPDFReporter` constructor, defaulting to `reports/ExtentReports/PdfReport.pdf`.

The framework also includes utility methods for file compression in [`src/test/java/com/anhtester/projects/crm/testcases/TestSimpleCode.java`](https://github.com/anhtester/automationframeworkselenium/blob/main/src/test/java/com/anhtester/projects/crm/testcases/TestSimpleCode.java). The `testZipFile()` and `testUnZipFile()` methods demonstrate how to package the [`pdf-config.json`](https://github.com/anhtester/automationframeworkselenium/blob/main/pdf-config.json) file for transport if needed.

## Summary

- Uncomment the **pdfextentreporter** dependency (version 1.3.2) in [`pom.xml`](https://github.com/anhtester/automationframeworkselenium/blob/main/pom.xml) to enable PDF functionality
- Uncomment and configure the **ExtentPDFReporter** initialization block in [`ExtentReportManager.java`](https://github.com/anhtester/automationframeworkselenium/blob/main/ExtentReportManager.java) around lines 40–46
- Use the **loadJSONConfig** method to load styling instructions from [`src/test/resources/pdf-config.json`](https://github.com/anhtester/automationframeworkselenium/blob/main/src/test/resources/pdf-config.json)
- Customize PDF appearance by editing JSON properties such as `titleColor`, `passColor`, and `displayAttributeSummary`
- Generated PDFs output to `reports/ExtentReports/PdfReport.pdf` by default

## Frequently Asked Questions

### Where is the pdf-config.json file located in the repository?

The [`pdf-config.json`](https://github.com/anhtester/automationframeworkselenium/blob/main/pdf-config.json) file is located at [`src/test/resources/pdf-config.json`](https://github.com/anhtester/automationframeworkselenium/blob/main/src/test/resources/pdf-config.json). This path is referenced in the [`ExtentReportManager.java`](https://github.com/anhtester/automationframeworkselenium/blob/main/ExtentReportManager.java) file when calling `pdf.loadJSONConfig(new File("src/test/resources/pdf-config.json"))`.

### Why is the PDF reporter commented out by default?

The PDF reporter is commented out to keep the default project footprint lightweight and avoid forcing users to download the pdfextentreporter dependency if they only require HTML reports. Uncommenting the code in both [`pom.xml`](https://github.com/anhtester/automationframeworkselenium/blob/main/pom.xml) and [`ExtentReportManager.java`](https://github.com/anhtester/automationframeworkselenium/blob/main/ExtentReportManager.java) activates the feature.

### Can I change the output location of the PDF report?

Yes. Modify the first argument passed to the `ExtentPDFReporter` constructor in [`ExtentReportManager.java`](https://github.com/anhtester/automationframeworkselenium/blob/main/ExtentReportManager.java). The default path is `"reports/ExtentReports/PdfReport.pdf"`, but you can specify any valid file system path where the framework has write permissions.

### What happens if the pdf-config.json file is missing or malformed?

If the JSON file is missing or contains syntax errors, the `loadJSONConfig` method throws an IOException. The current implementation in [`ExtentReportManager.java`](https://github.com/anhtester/automationframeworkselenium/blob/main/ExtentReportManager.java) wraps this in a RuntimeException, which will halt execution and display an error stack trace in the console logs.