New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

pdf2thumbnail

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pdf2thumbnail

Generate PDF thumbnails.

  • 1.0.2
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

pdf2thumbnail

Generate PDF thumbnails.
You can install this module using npm:

npm i pdf2thumbnail

Requirements

Requires imagemagick CLI tools to be installed.

There are numerous ways to install them.
For instance, if you're on OS X you can use Homebrew.

brew install imagemagick

For Linux, use yum.

sudo yum -y install ImageMagick

Example

  • Total pages of PDF.
    const {getTotalNumberOfPages} = require('pdf2thumbnail');
    
    const totalNumberOfPages = await getTotalNumberOfPages('sample.pdf');
    console.log(totalNumberOfPages);// =>29
    
  • Thumbnail all pages.
    The thumbnail file name is "<original file name>_<page number>.<extension>".
    const {writeThumbnails} = require('pdf2thumbnail');
    
    writeThumbnails('sample.pdf', './dir');
    // $ ll dir
    // -rw-rw-r-- 1 ec2-user ec2-user 43157 Aug  5 09:17 sample_1.jpg
    // -rw-rw-r-- 1 ec2-user ec2-user 24496 Aug  5 09:17 sample_2.jpg
    // ...
    
  • Specify thumbnail width, quality, and format.
    const {writeThumbnails} = require('pdf2thumbnail');
    
    writeThumbnails('sample.pdf', './dir', {
      width: 300,
      quality: 100,
      format: 'png'
    });
    // $ ll dir
    // -rw-rw-r-- 1 ec2-user ec2-user 42722 Aug  5 09:17 sample_1.png
    // -rw-rw-r-- 1 ec2-user ec2-user 22411 Aug  5 09:17 sample_2.png
    // ...
    
  • Thumbnail of the first page only.
    const {writeThumbnails} = require('pdf2thumbnail');
    
    writeThumbnails('sample.pdf', './dir', {
      start: 1,
      end: 1
    });
    
    // $ ll dir
    // -rw-rw-r-- 1 ec2-user ec2-user 43157 Aug  5 09:17 sample_1.jpg
    
  • Thumbnails for pages 2-5.
    const {writeThumbnails} = require('pdf2thumbnail');
    
    writeThumbnails('sample.pdf', './dir', {
      start: 2,
      end: 5
    });
    
    // $ ll dir
    // -rw-rw-r-- 1 ec2-user ec2-user 24496 Aug  5 09:17 sample_2.jpg
    // -rw-rw-r-- 1 ec2-user ec2-user 41054 Aug  5 09:17 sample_3.jpg
    // -rw-rw-r-- 1 ec2-user ec2-user 45361 Aug  5 09:17 sample_4.jpg
    // -rw-rw-r-- 1 ec2-user ec2-user 38269 Aug  5 09:17 sample_5.jpg
    

API

  • getTotalNumberOfPages(filePath: string): Promise<number>

    Get the total number of pages in the PDF document.

    Parameters:

    • filePath: string: Path of the PDF file.

    Return value:

    • {Promise&lt;number&gt;}: Total number of pages in the PDF document.
  • writeThumbnails(filePath: string, outDir: string, options: ThumbnailOptions = {}): Promise<void>

    Write a thumbnail for each page of the PDF document.

    Parameters:

    • filePath: string: Path of the PDF file.
    • outDir: string: Directory path to output thumbnails.
    • options.width?: number: Width of output thumbnail (px). Default is 300 (px).
    • options.quality?: number: The quality of the thumbnail to output (1-100). Default is 100.
    • options.format?: string: The format of the output thumbnail. Default is jpg.
    • options.start?: number: Start page position.
    • options.end?: number: End page position.

Author

Takuya Motoshima

  • github/takuya-motoshima
  • twitter/TakuyaMotoshima
  • facebook/takuya.motoshima.7

License

MIT

Keywords

FAQs

Package last updated on 04 Nov 2022

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc