Search code examples
python-3.xscreenshot

Convert a full webpage to a PDF or combine screenshots into one image


I am looking for convert a webpage to a PDF. I searched this like "take screenshot of all webpage". In everywhere, everybody refers python "selenium" module. But didn't find anything about "all page". Don't want to a single screenshot. My whis is like PDF format.

Already tried to imgkit. Is there any option?


Solution

  • I found the answer. First module's name is "Selenium-Screenshot".It takes screenshots and compare them in 1 image. For more detailed discussion: Taking a whole page screenshot with Selenium Marionette in Python

    from Screenshot import Screenshot_Clipping
    from selenium import webdriver
    
    ob=Screenshot_Clipping.Screenshot()
    
    options = webdriver.ChromeOptions()   #created for headless chrome
    options.add_argument('headless')
    options.add_argument('window-size=1920x1080')    #change resolution of screenshots
    
    driver = webdriver.Chrome(chrome_options=options)
    url = "your_url"
    driver.get(url)
    img_url=ob.full_Screenshot(driver, save_path=r'.', image_name='Myimage.png')
    driver.close()
    driver.quit()