├── .gitattributes ├── README.md ├── LICENSE └── notability2pdf.py /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # notability2pdf 2 | 3 | Extract PDF files from notability (*.note). Note, the notability files must contain PDF files within them. 4 | 5 | Usage: 6 | - Place notability files in "in" directory 7 | - Run "notability2pdf.py" 8 | - PDF files are placed into "out" directory 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Steven Tang 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /notability2pdf.py: -------------------------------------------------------------------------------- 1 | import os 2 | import shutil 3 | import zipfile 4 | 5 | if not os.path.exists('in'): 6 | os.makedirs('in') 7 | print('Add *.note files to in/ folder') 8 | if not os.path.exists('out'): 9 | os.makedirs('out') 10 | if not os.path.exists('temp'): 11 | os.makedirs('temp') 12 | 13 | directory = os.fsencode('in') 14 | notefiles = [f.decode('utf-8') for f in os.listdir(directory) if f.decode('utf-8').endswith('.note')] 15 | 16 | for filename in notefiles: 17 | with zipfile.ZipFile(f'in/{filename}','r') as zip_ref: 18 | directory = f'temp/{filename[slice(-5)].strip()}' 19 | try: 20 | zip_ref.extractall(directory) 21 | except: 22 | print(f'Failed extracting: {directory}') 23 | continue 24 | 25 | folder_name = next(os.walk(directory))[1][0] 26 | print(f'Extracted: {folder_name}') 27 | pdf_folder_path = f'temp/{folder_name}/{folder_name}/PDFs' 28 | try: 29 | pdfs = os.listdir(pdf_folder_path) 30 | if len(pdfs) > 1: 31 | for (i, pdf) in enumerate(pdfs): 32 | shutil.move(f'{pdf_folder_path}/{pdf}', f'out/{folder_name} ({i}).pdf') 33 | elif len(pdfs) == 1: 34 | pdf = pdfs[0] 35 | shutil.move(f'{pdf_folder_path}/{pdf}', f'out/{folder_name}.pdf') 36 | else: 37 | raise FileNotFoundError 38 | except FileNotFoundError: 39 | print('No PDFs detected in {filename}, ensure that {filename} contains a PDF') 40 | 41 | shutil.rmtree('temp') 42 | --------------------------------------------------------------------------------