|
| 1 | +''' |
| 2 | +Copyright 2021 Robert Schroll |
| 3 | +
|
| 4 | +This program is free software: you can redistribute it and/or modify |
| 5 | +it under the terms of the GNU General Public License as published by |
| 6 | +the Free Software Foundation, either version 3 of the License, or |
| 7 | +(at your option) any later version. |
| 8 | +
|
| 9 | +This program is distributed in the hope that it will be useful, |
| 10 | +but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +GNU General Public License for more details. |
| 13 | +
|
| 14 | +You should have received a copy of the GNU General Public License |
| 15 | +along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 16 | +''' |
| 17 | + |
| 18 | +import argparse |
| 19 | +import io |
| 20 | +import sys |
| 21 | +import zipfile |
| 22 | + |
| 23 | +from . import render |
| 24 | +from .sources import ZipSource |
| 25 | + |
| 26 | +def main(): |
| 27 | + parser = argparse.ArgumentParser(description="Render a PDF file from a Remarkable document.") |
| 28 | + parser.add_argument('input', help="Filename of zip file, or root-level unpacked file of document. Use '-' to read zip file from stdin.") |
| 29 | + parser.add_argument('output', nargs='?', default='', help="Filename where PDF file should be written. Omit to write to stdout.") |
| 30 | + args = parser.parse_args() |
| 31 | + |
| 32 | + source = args.input |
| 33 | + if source == '-': |
| 34 | + # zipfile needs to seek, so we need to read this all in |
| 35 | + source = ZipSource(zipfile.ZipFile(io.BytesIO(sys.stdin.buffer.read()))) |
| 36 | + if args.output: |
| 37 | + fout = open(args.output, 'wb') |
| 38 | + else: |
| 39 | + fout = sys.stdout.buffer |
| 40 | + |
| 41 | + stream = render(source) |
| 42 | + fout.write(stream.read()) |
| 43 | + fout.close() |
| 44 | + return 0 |
| 45 | + |
| 46 | +if __name__ == '__main__': |
| 47 | + sys.exit(main()) |
0 commit comments