diff --git a/README.md b/README.md index aff4f20..a72d1f1 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,27 @@ # Print a book from VitalSource Bookshelf to PDF -This script simulates mouse click in the next page button and takes screenshot of -current page in the opened book. +This script simulates mouse click in the next page button and takes screenshot +of current page in the opened book. +This script depends on pyautogui for automating mouse clicks and screenshots. +pyautogui uses the Pillow module for screenshots. OS X uses the "screencapture" +command. Linux uses the "scrot" command, which you may need to install. ## Usage ```bash pip install -r requirements.txt -python app.py top_left right_bottom next_button total_page -# Ex: python app.py 153,78 892,990 941,537 785 +python vitalsource-printer.py top_left right_bottom next_button total_page +# Ex: python vitalsource-printer.py 153,78 892,990 941,537 785 +``` + +## Finding Cursor Coordinates + +To find the coordinates you will need to supply as inputs for the +script, you may use "position()" function of the pyautogui module. + +```bash +python +>>> import pyautogui +>>> pyautogui.position() # while cursor is on desired location ``` diff --git a/requirements.txt b/requirements.txt index c9dd2eb..efe58f6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ -autopy +pyautogui img2pdf diff --git a/app.py b/vitalsource-printer.py similarity index 79% rename from app.py rename to vitalsource-printer.py index 8fc0877..5e19415 100644 --- a/app.py +++ b/vitalsource-printer.py @@ -1,8 +1,11 @@ +#!/usr/bin/env python3 + import argparse import os import tempfile +import time -import autopy +import pyautogui import img2pdf @@ -15,9 +18,13 @@ def screenshot(top_left, right_bottom, next_page, total_page): file_name = os.path.join(temp_dir, 'book-page-{}.png'.format(page_num)) images.append(file_name) - autopy.mouse.move(*next_page) - autopy.mouse.click(delay=1) - autopy.bitmap.capture_screen((top_left, rect_size)).save(file_name) + # Take a screenshot + pyautogui.screenshot(file_name, + region=(top_left[0], top_left[1], rect_size[0], + rect_size[1])) + # click the next button + pyautogui.click(x=next_page[0], y=next_page[1]) + time.sleep(1) # wait a second return images