![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
pdf2thumbnail
Advanced tools
Generate PDF thumbnails.
Click here to see the change log.
Click here to learn how to use the web demo.
brew install imagemagick
sudo yum -y install ImageMagick
npm install --save pdf2thumbnail
Get the total number of pages in the PDF document.
pdf2thumbnail.getTotalNumberOfPages(pdfPathOrDataUrl);
const pdf2thumbnail = require('pdf2thumbnail');
const totalPages = await pdf2thumbnail.getTotalNumberOfPages('sample.pdf');
{Promise<number>} Total number of pages in the PDF document.
Write a thumbnail for each page of the PDF document.
pdf2thumbnail.writeThumbnails(pdfPathOrDataUrl, outputDir);
pdf2thumbnail.writeThumbnails(pdfPathOrDataUrl, outputDir, {width: 595});
pdf2thumbnail.writeThumbnails(pdfPathOrDataUrl, outputDir, {width: 595, quality: 100});
pdf2thumbnail.writeThumbnails(pdfPathOrDataUrl, outputDir, {width: 595, quality: 100, format: 'jpg'});
pdf2thumbnail.writeThumbnails(pdfPathOrDataUrl, outputDir, {width: 595, quality: 100, format: 'jpg', start: 1});
pdf2thumbnail.writeThumbnails(pdfPathOrDataUrl, outputDir, {width: 595, quality: 100, format: 'jpg', start: 1, end: 2});
pdf2thumbnail.writeThumbnails(pdfPathOrDataUrl, outputDir, {width: 595, quality: 100, format: 'jpg', start: 1, end: 2, archive: true});
pdf2thumbnail.writeThumbnails(pdfPathOrDataUrl, outputDir, {width: 595, quality: 100, format: 'jpg', start: 1, end: 2, archive: true, background: '#000'});
pdf2thumbnail.writeThumbnails(pdfPathOrDataUrl, outputDir, {width: 595, quality: 100, format: 'jpg', start: 1, end: 2, archive: true, background: '#000', offset: 30});
const pdf2thumbnail = require('pdf2thumbnail');
await pdf2thumbnail.writeThumbnails('sample.pdf', './result');
// $ ll result
// -rw-rw-r-- 1 ec2-user ec2-user 101656 Dec 20 18:49 sample_1.jpg
// -rw-rw-r-- 1 ec2-user ec2-user 141934 Dec 20 18:49 sample_2.jpg
// -rw-rw-r-- 1 ec2-user ec2-user 128636 Dec 20 18:49 sample_3.jpg
// -rw-rw-r-- 1 ec2-user ec2-user 384545 Dec 20 18:49 sample.jpg
const pdf2thumbnail = require('pdf2thumbnail');
await pdf2thumbnail.writeThumbnails('sample.pdf', './result', {width: 595, quality: 100, format: 'png'});
// $ ll result
// -rw-rw-r-- 1 ec2-user ec2-user 106689 Dec 20 18:49 sample_1.png
// -rw-rw-r-- 1 ec2-user ec2-user 169000 Dec 20 18:49 sample_2.png
// -rw-rw-r-- 1 ec2-user ec2-user 132571 Dec 20 18:49 sample_3.png
// -rw-rw-r-- 1 ec2-user ec2-user 361910 Dec 20 18:49 sample.png
const pdf2thumbnail = require('pdf2thumbnail');
await pdf2thumbnail.writeThumbnails('sample.pdf', './result', {start: 2, end: 3});
// $ ll result
// -rw-rw-r-- 1 ec2-user ec2-user 141934 Dec 20 18:49 sample_2.jpg
// -rw-rw-r-- 1 ec2-user ec2-user 128636 Dec 20 18:49 sample_3.jpg
// -rw-rw-r-- 1 ec2-user ec2-user 283503 Dec 20 18:49 sample.jpg
const pdf2thumbnail = require('pdf2thumbnail');
await pdf2thumbnail.writeThumbnails('sample.pdf', './result', {archive: true});
// ll result*
// -rw-rw-rw- 1 ec2-user ec2-user 718211 Dec 20 18:04 result.zip
// result:
// -rw-rw-r-- 1 ec2-user ec2-user 101656 Dec 20 18:04 sample_1.jpg
// -rw-rw-r-- 1 ec2-user ec2-user 141934 Dec 20 18:04 sample_2.jpg
// -rw-rw-r-- 1 ec2-user ec2-user 128636 Dec 20 18:04 sample_3.jpg
// -rw-rw-r-- 1 ec2-user ec2-user 384545 Dec 20 18:04 sample.jpg
{Promise<{thumbnailPaths: string[], mergedPath: string}>} Thumbnail Result.
This is an object with the following elements.
npm run test
# > pdf2thumbnail@1.0.2 test
# > jest
# PASS __tests__/pdf2image.test.js
# PDF to Thumbnail
# ? Should write thumbnails of all pages. (639 ms)
# ? Should write thumbnails for pages 2-3. (738 ms)
# ? Should be a thumbnail of the specified width. (515 ms)
# ? An archive of thumbnails should be created. (606 ms)
# ? Each thumbnail in the merged image should be written at 30px intervals. (656 ms)
# ? Should write thumbnails in png format. (896 ms)
# PASS __tests__/exception.test.js
# Case of exception
# ? Should throw an error if the PDF path parameter is empty. (331 ms)
# ? Should throw an error if the PDF is not found. (1 ms)
# ? Should throw an error if the width option is 0. (1 ms)
# ? Should throw an error if width option is less than 0. (1 ms)
# ? Should throw an error if quality option is 0. (1 ms)
# ? Should throw an error if quality option is less than 0. (1 ms)
# ? Should throw an error if quality option is greater than 100. (2 ms)
# ? Should throw an error if the start option is 0.
# ? Should throw an error if start option is less than 0.
# ? Should throw an error if end option is 0.
# ? Should throw an error if end option is less than 0.
# ? Should throw an error if offset option is less than 0.
# PASS __tests__/number-of-pages.test.js
# Total number of PDF pages
# ? Should get the number of pages in the PDF. (180 ms)
# Test Suites: 3 passed, 3 total
# Tests: 19 passed, 19 total
# Snapshots: 0 total
# Time: 6.17 s
# Ran all test suites.
Takuya Motoshima
[1.0.5] - 2023/6/8
FAQs
Generate PDF thumbnails.
We found that pdf2thumbnail demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.