Skip to content

Commit

Permalink
Merge pull request #7 from tind/support-standard-fonts
Browse files Browse the repository at this point in the history
Update and support standard fonts
  • Loading branch information
thms-rmb authored Mar 7, 2022
2 parents 0d52643 + 20d76dc commit bd3794c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "pdf-thumbnails",
"version": "0.4.0",
"version": "0.5.0",
"main": "src/app.js",
"repository": "https://www.github.com/tind/pdf-thumbnails",
"license": "MIT",
"dependencies": {
"canvas": "~2.9.0",
"commander": "~8.3.0",
"pdfjs-dist": "~2.12.313"
"commander": "~9.0.0",
"pdfjs-dist": "~2.13.216"
},
"devDependencies": {
"mocha": "~9.2.0"
Expand Down
3 changes: 2 additions & 1 deletion src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@ program
.option("-p, --pagenum <pagenum>", "page number", _parseInt, 1)
.option("-w, --width <width>", "width", _parseInt, 300)
.option("-q, --quality <quality>", "jpeg quality", _parseFloat, 1.0)
.option("-F, --standard-fonts <dir>", "standard fonts", "/tmp/fonts/")
.arguments("<file...>")
.action(async (files, options, command) => {
const canvasFactory = new NodeCanvasFactory();
try {
for (const file of files) {
const outputPath = join(options.output, basename(file, ".pdf") + ".jpg");
const contents = await readFile(file);
const jpegBuffer = await getThumbnail(contents, options.pagenum, options.width, options.quality, canvasFactory);
const jpegBuffer = await getThumbnail(contents, options.pagenum, options.width, options.quality, options.standardFonts, canvasFactory);

await writeFile(outputPath, jpegBuffer);
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class NodeCanvasFactory {
}
}

async function getThumbnail(data, pageNum = 1, width = 300, quality = 1.0, canvasFactory = new NodeCanvasFactory()) {
const loadingTask = pdfjsLib.getDocument({data: data});
async function getThumbnail(data, pageNum = 1, width = 300, quality = 1.0, standardFonts = '/tmp/fonts/', canvasFactory = new NodeCanvasFactory()) {
const loadingTask = pdfjsLib.getDocument({data: data, standardFontDataUrl: standardFonts});
const document = await loadingTask.promise;
const page = await document.getPage(pageNum);

Expand Down

0 comments on commit bd3794c

Please sign in to comment.