Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto download PDF in Firefox

I want Firefox to directly download the PDF files instead of showing them in browser. I used following settings

FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.setPreference("browser.download.folderList", 2);
firefoxProfile.setPreference("browser.download.manager.showWhenStarting", false);
firefoxProfile.setPreference("browser.download.dir", "c:\\tmp");
firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/pdf");
WebDriver driver = new FirefoxDriver(firefoxProfile);
// Its just a sample URL 
driver.get("http://www.energy.umich.edu/sites/default/files/pdf-sample.pdf");

On about:config page I can see that this setting are successfully reflected also the response type is application/pdf.

enter image description here

When Webdriver launches Firefox I can see following option.

enter image description here

It should be "Save File".

Still Firefox is showing PDF in browser. I am using Firefox 29.0.1, does the preference values have changed?

like image 615
Ajinkya Avatar asked May 22 '14 07:05

Ajinkya


People also ask

How do I enable automatic Downloads in Firefox?

Chosen Solution. Click the Firefox button, go to Options | Options | General and in the Downloads menu, checkmark the option "Always ask me where to save files". Click the Firefox button, go to Options | Options | General and in the Downloads menu, checkmark the option "'''Always ask me where to save files'''".

How do I make a PDF download automatically?

On the right, go to the Content section, and click on Additional content settings. Click on PDF documents. On the next page, turn on (enable) the Download PDF files instead of automatically opening them in Chrome option. You are done.

How do I get Firefox to open PDF files automatically?

Go to Preferences->Applications and see what actions are assigned for PDF and Portable Document Format. It should be "preview in firefox" for it to open directly in Firefox.


1 Answers

The same as above for a remote Firefox Webdriver using Python Selenium:

from selenium import webdriver

from selenium.webdriver.firefox.options import Options

options = Options()
profile = webdriver.FirefoxProfile()
profile.set_preference("browser.download.folderList", 2)
profile.set_preference("browser.download.manager.showWhenStarting", False)
profile.set_preference("browser.download.dir", "/data");
profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/pdf");
profile.set_preference("pdfjs.disabled", True)
profile.set_preference("plugin.scan.Acrobat", "99.0")
profile.set_preference("plugin.scan.plid.all", False)

driver = webdriver.Remote(
    browser_profile=profile,
    command_executor='http://localhost:4444/wd/hub',
    desired_capabilities=options.to_capabilities()
)
driver.get("https://www.ti.com/lit/ds/symlink/sa555.pdf");
like image 179
Alex44 Avatar answered Oct 21 '22 18:10

Alex44