Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Web page to PDF V0.1 (just a test to see if it would work)
- By Steve Shambles March 2019
- Works in latest Firefox browser on Windows 7.
- It may or may not work on other browsers and OS's?
- You may need to:
- "pip install pyautogui"
- "pip install pyperclip"
- More outrageously incompetent code at:
- https://stevepython.wordpress.com/
- """
- import time
- from tkinter import Tk, simpledialog
- import webbrowser
- import pyautogui
- import pyperclip
- ROOT = Tk()
- # Stop naff GUI window from showing, for now.
- ROOT.withdraw()
- # Website that does the conversion.
- pdf_url = "http://www.html2pdf.it/"
- # Ask user for the URL of page to convert via GUI input.
- # You can use ctr-v to paste a url into box.
- users_url = simpledialog.askstring(title='Convert To PDF',
- prompt='URL to convert:')
- # Copy users URL to the system clipboard.
- pyperclip.copy(users_url)
- # Open PDF converter page in default web browser.
- webbrowser.open(pdf_url)
- time.sleep(5)
- # Paste users URL into PDF converter sites entry box.
- pyautogui.hotkey('ctrl', 'v')
- time.sleep(2)
- # Send enter key to start conversion.
- pyautogui.press('enter')
- # Not sure how long to wait while PDF converts, experiment.
- time.sleep(8)
- # Now pdf should appear in browser.
- # To save it we need to do a ctrl-s.
- pyautogui.hotkey('ctrl', 's')
- # File save dialog should come up now.
- # We just need to send the enter key to save it
- # to the browser's default save location.
- # Pause here a little, so user can take control
- # and edit the save name of the pdf if wants to.
- time.sleep(3)
- pyautogui.press('enter')
- print("Finished.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement