Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
```
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
autopy
pyautogui
img2pdf
15 changes: 11 additions & 4 deletions app.py → vitalsource-printer.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#!/usr/bin/env python3

import argparse
import os
import tempfile
import time

import autopy
import pyautogui
import img2pdf


Expand All @@ -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

Expand Down