-
-
Save trueskawka/7ff89ff12e6529e6cca65015956eaf6e to your computer and use it in GitHub Desktop.
Export a Notability note as SVG and PNG.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import biplist | |
import struct | |
import matplotlib.pyplot as plt | |
import argparse | |
parser = argparse.ArgumentParser(description='Convert Notability files to SVG and PNG. Unzip the Notability file first.\n After running the script, images will be in the same directory as the .note file.') | |
parser.add_argument('filepath', type=str, nargs=1, help='a path to the unzipped Notability directory') | |
parser.add_argument('size', type=int, nargs=2, help='width and height of the resulting SVG and PNG') | |
args = parser.parse_args() | |
note_name = args.filepath[0] | |
note = note_name + '/Session.plist' | |
try: | |
plist = biplist.readPlist(note) | |
except e: | |
print('Not a readable plist: ', e) | |
def unpack_struct(string, fmt, size): | |
return struct.unpack('{num}{format}'.format(num=int(len(string)/size), format=fmt), string) | |
drawings = plist['$objects'][8] | |
points = unpack_struct(drawings['curvespoints'], 'f', 4) | |
xs = points[0::2] | |
ys = points[1::2] | |
widths = unpack_struct(drawings['curveswidth'], 'f', 4) | |
colors = unpack_struct(drawings['curvescolors'], 'B', 1) | |
colors = [x / 255 for x in colors] | |
colors_list = [colors[i:i+4] for i in range(0, len(colors), 4)] | |
num_points = unpack_struct(drawings['curvesnumpoints'], 'i', 4) | |
x_size, y_size = args.size | |
plotty = plt.figure(figsize=(x_size, y_size)) | |
plt.ylim(max(ys), min(ys)) | |
plt.xlim(min(xs), max(xs)) | |
plt.axis('off') | |
current_x = 0 | |
current_y = 0 | |
type(list(num_points)) | |
for i, curve in enumerate(num_points): | |
max_x = current_x + curve | |
max_y = current_y + curve | |
plt.plot(xs[current_x:max_x], ys[current_y:max_y], color=colors_list[i], linewidth=(x_size/5)*widths[i]) | |
current_x = max_x | |
current_y = max_y | |
plotty.savefig(note_name + '.png', transparent=True, bbox_inches=0) | |
plotty.savefig(note_name + '.svg', transparent=True, bbox_inches=0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment