FirefoxOptions options = new FirefoxOptions();
FirefoxProfile profile = new FirefoxProfile();
// Accept Untrusted Certificates
profile.setAcceptUntrustedCertificates(true);
profile.setAssumeUntrustedCertificateIssuer(false);
//Directly download PDF
profile.setPreference("browser.helperApps.neverAsk.openFile", "application/pdf");
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/pdf");
profile.setPreference("pdfjs.disabled", true); // disable the built-in PDF viewer
// Set Firefox profile to capabilities
options.setCapability(FirefoxDriver.PROFILE, profile);
I have used above code to configure firefox so that it directly downloads the PDF when clicked on a PDF link using selenium webdriver. When an automation script clicks on a link that download the PDF, the script downloads the file directly but it loses the original name but downloaded as 'Document' refer attachment for screenshot of downloaded files.