Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ lib/*
node_modules/
tests/output/*.png
tests/output/*.jpg
tests/output/*.pdf
tests/output/*.cpuprofile
*.DS_Store*
.aider*
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,23 @@ Ratta Supernote has often commented that the file-format is yet unstable and sho

For some quick snippets, take a look at the [smoke tests](./tests/main.test.ts).

### Generating searchable PDFs

`toPdf` renders each page's raster image into a PDF page and overlays the recognized handwriting (RTR) text invisibly at the location it was written, so the PDF is searchable and words can be selected/copied from the image. See [tests/pdf.test.ts](./tests/pdf.test.ts) for a full example.

```ts
import { SupernoteX, toPdf } from 'supernote-typescript';

const note = new SupernoteX(buffer);
const pdfBytes = await toPdf(note);
```

The default font (Helvetica) only supports Latin text. Pass `fontBytes` with a Unicode TTF/OTF to support other scripts:

```ts
const pdfBytes = await toPdf(note, { fontBytes: await fs.readFile('NotoSans-Regular.ttf') });
```

## Developer Notes

### Test Individual Suite
Expand Down
285 changes: 284 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
],
"scripts": {
"build": "tsc",
"clean": "rm -f tests/output/*.png tests/output/*.jpg tests/output/*.cpuprofile",
"clean": "rm -f tests/output/*.png tests/output/*.jpg tests/output/*.pdf tests/output/*.cpuprofile",
"lint": "eslint .",
"test": "vitest run",
"test-watch": "vitest",
Expand Down Expand Up @@ -43,13 +43,16 @@
"@vitest/coverage-v8": "4.1.10",
"eslint": "10.8.0",
"globals": "17.7.0",
"pdf-parse": "^2.4.5",
"prettier": "3.9.6",
"typescript": "6.0.3",
"vitest": "4.1.10"
},
"dependencies": {
"@pdf-lib/fontkit": "^1.1.1",
"color": "^5.0.3",
"fs-extra": "^11.4.0",
"image-js": "^1.7.0"
"image-js": "^1.7.0",
"pdf-lib": "^1.17.1"
}
}
Loading