# How can I Enable Chrome's "Download PDFs" Option Using Preferences

**URL:** <https://forum.katalon.com/t/how-can-i-enable-chromes-download-pdfs-option-using-preferences/137758>\
**Category:** Miscellaneous\
**Created:** [July 19, 2024, 7:13pm UTC](https://forum.katalon.com/t/how-can-i-enable-chromes-download-pdfs-option-using-preferences/137758 "2024-07-19T19:13:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dave\_Evers](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/dave_evers/32/435_2.png) [@Dave\_Evers](https://forum.katalon.com/u/Dave_Evers)\
**Post date:** [July 19, 2024, 7:13pm UTC](https://forum.katalon.com/t/how-can-i-enable-chromes-download-pdfs-option-using-preferences/137758/1 "2024-07-19T19:13:16Z")

</div>

KSE: Version: 9.5.0, Build 217  
Windows 11 Enterprise (64-bit)  
Chrome Version 126.0.6478.183 (Official Build) (32-bit)

My use case: Automatically download a page’s PDF file when the user opens a page using Chrome, then programmatically check the PDF for some defined text.

Hello folks, Does anyone know which Katalon Chrome ‘Desired Capabilities’ settings I can use to enable Chrome’s ' **Download PDFs**" option (PDFs auto download when a page is opened). I’ve see a few suggestions but they have not been clear in their syntax usage. A clear example would be very much appreciated, thank you for any help/pointers.

 ![image](https://europe1.discourse-cdn.com/katalon/original/3X/7/a/7aa010b8813e8587b3d7bdab11d654db3fb01b29.png)

---

<div class="post-metadata">

**Author:** ![system](https://europe1.discourse-cdn.com/katalon/original/3X/d/5/d55596ab02785a255798e87ede769734747b30c4.svg) [@system](https://forum.katalon.com/u/system)\
**Post date:** [July 19, 2024, 7:13pm UTC](https://forum.katalon.com/t/how-can-i-enable-chromes-download-pdfs-option-using-preferences/137758/2 "2024-07-19T19:13:16Z")

</div>

Hi there,

Thank you very much for your topic. Please note that it may take a little while before a member of our community or from Katalon team responds to you.

Thanks!

---

<div class="post-metadata">

**Author:** ![Elly\_Tran](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/elly_tran/32/21874_2.png) [@Elly\_Tran](https://forum.katalon.com/u/Elly_Tran)\
**Post date:** [July 20, 2024, 4:23am UTC](https://forum.katalon.com/t/how-can-i-enable-chromes-download-pdfs-option-using-preferences/137758/3 "2024-07-20T04:23:13Z")

</div>

Looking forward to the support from other community members. Let’s join hand helping @Dave_Evers

---

<div class="post-metadata">

**Author:** ![Dave\_Evers](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/dave_evers/32/435_2.png) [@Dave\_Evers](https://forum.katalon.com/u/Dave_Evers)\
**Post date:** [July 22, 2024, 7:53pm UTC](https://forum.katalon.com/t/how-can-i-enable-chromes-download-pdfs-option-using-preferences/137758/4 "2024-07-22T19:53:27Z")

</div>

I figured out a solution using **Chrome preferences**.  
First create a custom keyword as below, (see PdfDownloader).  
Next call the custom keyword from your test case.

**Custom keyword: PdfDownloader**

```auto
package tools
import java.nio.file.Path
import java.nio.file.Paths
import com.kms.katalon.core.annotation.Keyword
import com.kms.katalon.core.configuration.RunConfiguration

public class PdfDownLoader {
	@Keyword
	def setDownloadDirectoryAndPreferences() {
		// Get desired capabilities for WebDriver
		Map desiredCapabilities = RunConfiguration.getDriverPreferencesProperties("WebUI")
		// Set project download folder path
		String projectDownloadFolder = System.getProperty("user.home") + "/Downloads"

		// Create Path objects for project and download folder
		Path projectPath = Paths.get(projectDownloadFolder)
		Path downloadPath = projectPath.resolve(projectPath)

		// Print download path
		println('DownloadPath: ' + downloadPath)

		// Convert download path to string
		def customizedDownloadDirectory = downloadPath.toString()

		// Get existing preferences or create a new map
		Map prefs = desiredCapabilities.get("prefs")
		if (prefs == null) {
			prefs = [:]
		}

		// Set download directory and other preferences
		prefs.put("download.default_directory", customizedDownloadDirectory)
		prefs.put("download_dir", customizedDownloadDirectory)
		prefs.put("download.directory_upgrade", true)
		prefs.put("download.prompt_for_download", false)
		prefs.put("plugins.always_open_pdf_externally", true)
		prefs.put("profile.default_content_settings.popups", "0")
		prefs.put("profile.content_settings.exceptions.automatic_downloads.*.setting", "1")

		// Set WebDriver preferences properties
		RunConfiguration.setWebDriverPreferencesProperty("prefs", prefs)
		RunConfiguration.setWebDriverPreferencesProperty("args", [
			"--no-sandbox",
			"--disable-dev-shm-usage"
		])
		RunConfiguration.setWebDriverPreferencesProperty("useAutomationExtension", "false")
	}
}
// Call this keyword before opening a Browser session
// Call using: CustomKeywords.'tools.PdfDownLoader.setDownloadDirectoryAndPreferences'()

```

**Test Case: downloadSamplePdf**

```auto
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

// Calls the PdfDownloader Keyword
CustomKeywords.'tools.PdfDownLoader.setDownloadDirectoryAndPreferences'()

//Opens the sample pdf
WebUI.openBrowser('https://pdfobject.com/pdf/sample.pdf')

//CustomKeywords.'tools.PdfDownLoader.setDownloadDirectoryAndPreferences'() does the downloading
//once the page is open

```
