I have a set up where I print the page as pdf using selenium+gecko. But, whatever I do, it does not seem to respect the download.dir
option I set nor the download filename.
Here are my settings:
self.profile = webdriver.FirefoxProfile()
self.headers = {'User-Agent' : uagent, \
'Accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', \
'Accept-Language' : 'en-gb,en;q=0.5', \
'Accept-Charset' : 'ISO-8859-1,utf-8;q=0.7,*;q=0.7', \
'Keep-Alive' : '115', \
'Connection' : 'keep-alive', \
'Cache-Control' : 'max-age=0'}
self.profile.set_preference('browser.link.open_newwindow', 1)
self.profile.set_preference("general.useragent.override", uagent)
self.profile.set_preference("browser.download.manager.showWhenStarting", False)
self.profile.set_preference("browser.download.dir", '/home/foo/')
self.profile.set_preference("print_printer", "Mozilla Save to PDF")
self.profile.set_preference("print.always_print_silent", True)
self.profile.set_preference("print.show_print_progress", False)
self.profile.set_preference('print.save_as_pdf.links.enabled', True)
self.profile.set_preference("print.printer_Mozilla_Save_to_PDF.print_to_file", True)
self.profile.set_preference("print.printer_Mozilla_Save_to_PDF.print_to_filename", "file.pdf")
self.binary = FirefoxBinary('/path/to/Downloads/dir/firefox/firefox')
I have also tried:
self.profile.set_preference("print.print_to_filename", "file.pdf")
To print I do:
browser = webdriver.Firefox(firefox_profile=self.profile, \
firefox_binary=self.binary, executable_path='/some/path/dir/and/orm/driver/geckodriver')
browser.execute_script("window.print();")
When I execute this I get the PDF in the directory I execute the script from and always as mozilla.pdf
I am not sure what settings to use to change this.
I tried changing the page name to see if this will have any effect, but still, it prints out as mozilla.pdf
So yea, I am looking for a solution which can:
- set the directory of the pdf
- set the name of the pdf
:(