Skip to content

Instantly share code, notes, and snippets.

@trueskawka trueskawka/notability.ipynb Secret
Last active Jan 20, 2020

What would you like to do?
Export a Notability note as SVG and PNG.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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'
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))
current_x = 0
current_y = 0
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
You can’t perform that action at this time.