Advertisement
steve-shambles-2109

Web page to PDF V0.1

Dec 2nd, 2019
640
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.62 KB | None | 0 0
  1. """
  2. Web page to PDF V0.1 (just a test to see if it would work)
  3. By Steve Shambles March 2019
  4.  
  5. Works in latest Firefox browser on Windows 7.
  6. It may or may not work on other browsers and OS's?
  7.  
  8. You may need to:
  9. "pip install pyautogui"
  10. "pip install pyperclip"
  11.  
  12. More outrageously incompetent code at:
  13. https://stevepython.wordpress.com/
  14. """
  15.  
  16. import time
  17. from tkinter import Tk, simpledialog
  18. import webbrowser
  19.  
  20. import pyautogui
  21. import pyperclip
  22.  
  23. ROOT = Tk()
  24.  
  25. # Stop naff GUI window from showing, for now.
  26. ROOT.withdraw()
  27.  
  28. # Website that does the conversion.
  29. pdf_url = "http://www.html2pdf.it/"
  30.  
  31. # Ask user for the URL of page to convert via GUI input.
  32. # You can use ctr-v to paste a url into box.
  33. users_url = simpledialog.askstring(title='Convert To PDF',
  34.                                    prompt='URL to convert:')
  35.  
  36. # Copy users URL to the system clipboard.
  37. pyperclip.copy(users_url)
  38.  
  39. # Open PDF converter page in default web browser.
  40. webbrowser.open(pdf_url)
  41. time.sleep(5)
  42.  
  43. # Paste users URL into PDF converter sites entry box.
  44. pyautogui.hotkey('ctrl', 'v')
  45. time.sleep(2)
  46. # Send enter key to start conversion.
  47. pyautogui.press('enter')
  48.  
  49. # Not sure how long to wait while PDF converts, experiment.
  50. time.sleep(8)
  51.  
  52. # Now pdf should appear in browser.
  53. # To save it we need to do a ctrl-s.
  54. pyautogui.hotkey('ctrl', 's')
  55.  
  56. # File save dialog should come up now.
  57. # We just need to send the enter key to save it
  58. # to the browser's default save location.
  59.  
  60. # Pause here a little, so user can take control
  61. # and edit the save name of the pdf if wants to.
  62. time.sleep(3)
  63. pyautogui.press('enter')
  64.  
  65. print("Finished.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement