0

I have read through a few questions/answers that provide test codes to print to pdf using Selenium(chromedriver) that work for standard web pages - see below:

import pandas as pd
import numpy as np
import json
from selenium import webdriver

appState = {
    "recentDestinations": [
        {
            "id": "Save as PDF",
            "origin": "local",
            "account": ""
        }
    ],
    "selectedDestinationId": "Save as PDF",
    "version": 2
}

profile = {'printing.print_preview_sticky_settings.appState': json.dumps(appState)}

chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option('prefs', profile)
chrome_options.add_argument('--kiosk-printing')

driver = webdriver.Chrome(executable_path='PATH_TO\chromedriver.exe',chrome_options=chrome_options)
driver.get('https://stackoverflow.com/questions/54184647/how-to-send-ctrl-p-to-a-web-browser-in-python/54185741')
driver.execute_script('window.print();')

but does not work for a .htm path: https://www.sec.gov/Archives/edgar/data/857855/000085785520000011/ucbi1231201910-k.htm

i.e.

driver.get('https://www.sec.gov/Archives/edgar/data/857855/000085785520000011/ucbi1231201910-k.htm')
driver.execute_script('window.print();')

I can manually Save as PDF so not sure what to do

HowdyDude
  • 483
  • 2
  • 5
  • 14
  • 1
    see [How to convert webpage into PDF by using Python](https://stackoverflow.com/questions/23359083/how-to-convert-webpage-into-pdf-by-using-python). I can save this page in PDF using first answer - without Selenium. It creates PDF with 141 pages. And it can be problem for Selenium - too many data which needs too much time to generate PDF – furas Mar 06 '20 at 12:08
  • You mind sending your code? I tried to install PyQT5 and caused some issues with Conda/Spyder (wouldn't open) and had to uninstall/install again. – HowdyDude Mar 06 '20 at 17:26
  • 1
    I used code from first answer - `import pdfkit` `pdfkit.from_url(' https://www.sec.gov/Archives/edgar/data/857855/000085785520000011/ucbi1231201910-k.htm', 'out.pdf')`. I don't knows if it need PyQT5 but I have it installed for a long time. I don't use Conda and Spyder so I don't know if it makes problem. – furas Mar 06 '20 at 17:46
  • Ok cool, post mentioned different solutions - most of which involved pyqt, i'll try the pdfkit. Thanks! – HowdyDude Mar 06 '20 at 17:59

0 Answers0