napkin-sketchdocs 1.0.0 GitHub

Writing a drawing out: cheatsheet#

On this page

API hub · Reference · Quickstart · Cheatsheet

Reminders for writing a drawing out: the two calls, their options, the box, and what each format keeps.

The calls#

FormatrenderSketch(page, options)renderBook(book, options)Write it as
svga stringa string a pageUTF-8
pnga Uint8Arraya Uint8Array a pagebytes
pdfa stringone string, a PDF page a sketchlatin1
skbka string: a book of that pageone stringUTF-8
jsxa string: a script for that pageone string, a document a pageUTF-8

Options#

OptionDefaultMeaning
format'svg'svg, png, pdf, skbk or jsx
cropthe whole page'auto', { mode: 'auto', pad: 12 }, 'none', or { x, y, width, height }
registrationnoneOne box for every page; wins over crop
transparentfalseNo paper in the SVG, the PNG or the .jsx
scale1PNG pixels a page pixel
resolveLinknoneReads linked files for the PNG: resolveLinkFromDir(folder)
decodeImagenoneDecodes images the PNG cannot: anything but PNG
linkFolderbeside the scriptWhere a .jsx looks for linked files; writeBook and drawToFiles set it
onWarningnoneTold what a format left out or drew as a stand-in

The output verbs#

CategoryVerbWrittenDoes
Outputcropcrop auto [pad <length>]
crop none
crop <x> <y> <width> <height>
The box every output is cut to: auto fits the ink with room to spare, none keeps the page, or a box given outright.
Outputregistrationregistration <x> <y> <width> <height>One box every page is written in, so frames drawn by one script line up when they are played in sequence.

What each format keeps#

SVGPNGPDF.skbk.jsx
Layer tree and namesYes, named three waysCompositedFlattenedYesLayers and named groups, hidden and locked ones too
Bezier anchorsYes, two decimalsDrawnVector lines through the sampled pointsYesYes, two decimals
GradientsYesYesFlat fill, warnedYesYes
Dashes, profiles, Copic nibsYesYesYesYesYes
TextLive <text>, the named fontThe built-in faceHelveticaYesText frames, the named font where Illustrator has it
ImagesEmbeddedPNG; the rest with decodeImageJPEG only, warnedYesEmbedded
LinksThe referenceThe file with resolveLink, else the placeholderThe placeholderThe referencePlaced by link
ErasersA mask on the layerClear their own layerPaint the paper backYesPaint the paper back, warned
EffectsA <filter>, and data-effectsDrawnLeft out, warnedYesLeft out, warned
A SplatterIts lines, and data-effectsDrawnIts linesYesIts lines
A WarpThe bent shape, and data-effectsDrawnThe bent shapeYesThe bent shape
3DA group of its faces, and data-effectsDrawnIts facesYesA group of its faces
Transparencytransparent: truetransparent: trueA transparent page prints no paper-transparent: true

The box#

WantScriptOptions
The whole pagecrop nonecrop: 'none'
The inkcrop autocrop: 'auto'
The ink and roomcrop auto pad 12crop: { mode: 'auto', pad: 12 }
A boxcrop 40 40 200 100crop: { x: 40, y: 40, width: 200, height: 100 }
Frames that line upregistration 50 70 300 180registration: { x: 50, y: 70, width: 300, height: 180 }
The box before writinginkBox(page), renderBox(page, options)

Common mistakes#

WrongRightWhy
writeFileSync('card.pdf', pdf)writeFileSync('card.pdf', pdf, 'latin1')UTF-8 mangles an embedded image's bytes.
renderBook(book, { format: 'png' })renderBook(book, { format: 'png', ...output })The script's crop rides in output, not in the book.
A JPEG placed, a PNG renderedPass decodeImageThe PNG decodes only PNG itself; the image is left out, with a warning.