# Is it possible to read pdf file from url ex : "http://site.com/thispdf"

**URL:** <https://forum.katalon.com/t/is-it-possible-to-read-pdf-file-from-url-ex-http-site-com-thispdf/10346>\
**Category:** Web Testing\
**Tags:** web-testing, katalon-studio\
**Created:** [April 18, 2018, 6:39am UTC](https://forum.katalon.com/t/is-it-possible-to-read-pdf-file-from-url-ex-http-site-com-thispdf/10346 "2018-04-18T06:39:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Didit\_Setiawan](https://avatars.discourse-cdn.com/v4/letter/d/9de0a6/32.png) [@Didit\_Setiawan](https://forum.katalon.com/u/Didit_Setiawan)\
**Post date:** [April 18, 2018, 6:39am UTC](https://forum.katalon.com/t/is-it-possible-to-read-pdf-file-from-url-ex-http-site-com-thispdf/10346/1 "2018-04-18T06:39:55Z")

</div>

Just want to ask, is it possible to read pdf document but the link is  
“[http://site.com/thispdf](http://site.com/thispdf)”

instead of

“[Login | HSTS Redirection Community](http://site.com/thispdf.pdf)”

this pdf is generated automatically so it’s not saved or stored on web storage.  
If anyone have solution please answer my question. Thank You.

---

<div class="post-metadata">

**Author:** ![Marek\_Melocik](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/marek_melocik/32/371_2.png) [@Marek\_Melocik](https://forum.katalon.com/u/Marek_Melocik)\
**Post date:** [April 18, 2018, 7:53am UTC](https://forum.katalon.com/t/is-it-possible-to-read-pdf-file-from-url-ex-http-site-com-thispdf/10346/2 "2018-04-18T07:53:47Z")

</div>

Hi Didit,

I am afraid that you should need some 3rd party Java library to read PDF files.

You want to download it and parse/read afterwards? Or what do you want to do with the file?

---

<div class="post-metadata">

**Author:** ![Didit\_Setiawan](https://avatars.discourse-cdn.com/v4/letter/d/9de0a6/32.png) [@Didit\_Setiawan](https://forum.katalon.com/u/Didit_Setiawan)\
**Post date:** [April 18, 2018, 8:36am UTC](https://forum.katalon.com/t/is-it-possible-to-read-pdf-file-from-url-ex-http-site-com-thispdf/10346/3 "2018-04-18T08:36:16Z")

</div>

> Marek Melocik said:
> 
> Hi Didit,
> 
> I am afraid that you should need some 3rd party Java library to read PDF files.
> 
> You want to download it and parse/read afterwards? Or what do you want to do with the file?

already using java 3rd library, pdfbox  
the problem is cannot open stream(BufferedInputStream) because server detect unauthorized access(it requires authentication header), (othercase)using httpurlconnection, we can set property like this httpConn.setRequestProperty(“Authorization”, basicAuth) to pass header authentication, is there any option for openstream like setrequestproperty on openconnection

---

<div class="post-metadata">

**Author:** ![mydung.nguyen9192](https://avatars.discourse-cdn.com/v4/letter/m/ad7895/32.png) [@mydung.nguyen9192](https://forum.katalon.com/u/mydung.nguyen9192)\
**Post date:** [March 20, 2019, 4:21pm UTC](https://forum.katalon.com/t/is-it-possible-to-read-pdf-file-from-url-ex-http-site-com-thispdf/10346/4 "2019-03-20T16:21:24Z")

</div>

I have the same problem. Do you have any solusion?

---

<div class="post-metadata">

**Author:** ![Timo\_Kuisma](https://avatars.discourse-cdn.com/v4/letter/t/8baadc/32.png) [@Timo\_Kuisma](https://forum.katalon.com/u/Timo_Kuisma)\
**Post date:** [March 20, 2019, 5:17pm UTC](https://forum.katalon.com/t/is-it-possible-to-read-pdf-file-from-url-ex-http-site-com-thispdf/10346/5 "2019-03-20T17:17:09Z")

</div>

HI,

```
are you able to save it to your pc?
you can try to use browser properties for that, which browser used?

```

not sure, but something like that

> **[Selenium Webdriver Handle Firefox Or Chrome Download Popup](https://www.dev2qa.com/selenium-webdriver-handle-firefox-or-chrome-download-popup/)**
>
> When you use Firefox to download a zip or pdf file in selenium webdriver automation test scripts, you may find a download dialog popup which you can not handle always. When you download a pdf use Chrome browser, you may find the pdf is opened in...

[https://www.toolsqa.com/selenium-webdriver/how-to-download-files-using-selenium/](https://www.toolsqa.com/selenium-webdriver/how-to-download-files-using-selenium/)

---

<div class="post-metadata">

**Author:** ![Timo\_Kuisma](https://avatars.discourse-cdn.com/v4/letter/t/8baadc/32.png) [@Timo\_Kuisma](https://forum.katalon.com/u/Timo_Kuisma)\
**Post date:** [March 22, 2019, 3:38pm UTC](https://forum.katalon.com/t/is-it-possible-to-read-pdf-file-from-url-ex-http-site-com-thispdf/10346/6 "2019-03-22T15:38:54Z")

</div>

Hi,  
disable chrome browser pdf viewer option from the chrome setting.

```
Testcase

//set chrome options
driver = setChromeOptions(folder)
DriverFactory.changeWebDriver(driver)

//verify pdf
driver.get('https://pressbooks.com/sample-books/')
driver.findElement(By.xpath("//article[@id='post-2344']/div/ul/li/a")).click()
def url = WebUI.getUrl()
println url
String pdfContent = CustomKeywords.'readPdfFile.verifyPdfContent.readPdfFileVerify'(url)
Assert.assertTrue(pdfContent.contains('The PressBooks version of The Metamorphosis, by Franz Kafka.'))

public WebDriver setChromeOptions(File folder){
	
	ChromeOptions optionsBeta = new ChromeOptions();
	String downloadPath = folder.getAbsolutePath()
	//String downloadsPath = System.getProperty("user.home") + "/Downloads";
	println ("downloadpath "+downloadPath)
	
	Map<String, Object> chromePrefs = new HashMap<String, Object>()
	chromePrefs.put("profile.default_content_settings.popups", 0);
	chromePrefs.put("download.default_directory", downloadPath)
	chromePrefs.put("download.prompt_for_download", false)
	chromePrefs.put("plugins.plugins_disabled", "Chrome PDF Viewer");
	
	optionsBeta.setExperimentalOption("prefs", chromePrefs)
	DesiredCapabilities cap = DesiredCapabilities.chrome()
	cap.setCapability(ChromeOptions.CAPABILITY, optionsBeta)
	
	System.setProperty("webdriver.chrome.driver", DriverFactory.getChromeDriverPath())
	WebDriver driver = new ChromeDriver(cap);
	return driver
}

Keyword

	@Keyword
	public String readPdfFileVerify(String pdfUrl){

		URL TestURL = new URL(pdfUrl);
		BufferedInputStream bis = new BufferedInputStream(TestURL.openStream());
		PDDocument doc = PDDocument.load(bis);
		String pdfText = new PDFTextStripper().getText(doc);
		doc.close();
		bis.close();
		println(pdfText);
		return pdfText;

	}
```

---

<div class="post-metadata">

**Author:** ![Timo\_Kuisma](https://avatars.discourse-cdn.com/v4/letter/t/8baadc/32.png) [@Timo\_Kuisma](https://forum.katalon.com/u/Timo_Kuisma)\
**Post date:** [March 22, 2019, 3:43pm UTC](https://forum.katalon.com/t/is-it-possible-to-read-pdf-file-from-url-ex-http-site-com-thispdf/10346/7 "2019-03-22T15:43:45Z")

</div>

Hi,

```
first disable pdf viewer option from chrome settings.

Testcase

File folder

folder = new File(UUID.randomUUID().toString())
folder.mkdir()

//set chrome options
driver = setChromeOptions(folder)
DriverFactory.changeWebDriver(driver)

//verify pdf
driver.get('https://pressbooks.com/sample-books/')
driver.findElement(By.xpath("//article[@id='post-2344']/div/ul/li/a")).click()
def url = WebUI.getUrl()
println url
String pdfContent = CustomKeywords.'readPdfFile.verifyPdfContent.readPdfFileVerify'(url)
Assert.assertTrue(pdfContent.contains('The PressBooks version of The Metamorphosis, by Franz Kafka.'))

public WebDriver setChromeOptions(File folder){
	
	ChromeOptions optionsBeta = new ChromeOptions();
	String downloadPath = folder.getAbsolutePath()
	println ("downloadpath "+downloadPath)
	
	Map<String, Object> chromePrefs = new HashMap<String, Object>()
	chromePrefs.put("profile.default_content_settings.popups", 0);
	chromePrefs.put("download.default_directory", downloadPath)
	chromePrefs.put("download.prompt_for_download", false)
	chromePrefs.put("plugins.plugins_disabled", "Chrome PDF Viewer");
	
	optionsBeta.setExperimentalOption("prefs", chromePrefs)
	DesiredCapabilities cap = DesiredCapabilities.chrome()
	cap.setCapability(ChromeOptions.CAPABILITY, optionsBeta)
	
	System.setProperty("webdriver.chrome.driver", DriverFactory.getChromeDriverPath())
	WebDriver driver = new ChromeDriver(cap);
	return driver
}

Keyword

	@Keyword
	public String readPdfFileVerify(String pdfUrl){

		URL TestURL = new URL(pdfUrl);
		BufferedInputStream bis = new BufferedInputStream(TestURL.openStream());
		PDDocument doc = PDDocument.load(bis);
		String pdfText = new PDFTextStripper().getText(doc);
		doc.close();
		bis.close();
		println(pdfText);
		return pdfText;

	}
```
