pdf2thumbnail
Advanced tools
Comparing version 1.0.0 to 1.0.1
# Changelog | ||
All notable changes to this project will be documented in this file. | ||
## [1.0.0] - 2022-08-05 | ||
## [1.0.1] - 2022/11/4 | ||
### Fixed | ||
- Updated README to make it easier to read. | ||
## [1.0.0] - 2022/8/5 | ||
### Fixed | ||
- First release. |
{ | ||
"name": "pdf2thumbnail", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Generate PDF thumbnails.", | ||
@@ -5,0 +5,0 @@ "main": "dist/build.common.js", |
125
README.md
@@ -24,68 +24,83 @@ # pdf2thumbnail | ||
## Example | ||
```js | ||
const {getTotalNumberOfPages, writeThumbnails} = require('pdf2thumbnail'); | ||
- Total pages of PDF. | ||
```js | ||
const {getTotalNumberOfPages} = require('pdf2thumbnail'); | ||
// Total pages of PDF. | ||
const totalNumberOfPages = await getTotalNumberOfPages(`${__dirname}/sample.pdf`); | ||
console.log(totalNumberOfPages);// =>29 | ||
const totalNumberOfPages = await getTotalNumberOfPages('sample.pdf'); | ||
console.log(totalNumberOfPages);// =>29 | ||
``` | ||
- Thumbnail all pages. | ||
The thumbnail file name is "<original file name>_<page number>.<extension>". | ||
```js | ||
const {writeThumbnails} = require('pdf2thumbnail'); | ||
// Thumbnail all pages. | ||
// $ ll out1/ | ||
// -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 | ||
// ... | ||
writeThumbnails(`${__dirname}/sample.pdf`, `${__dirname}/out1`); | ||
writeThumbnails('sample.pdf', `${__dirname}/out1`); | ||
// $ ll out1/ | ||
// -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. | ||
```js | ||
const {writeThumbnails} = require('pdf2thumbnail'); | ||
// Specify thumbnail width, quality, and format. | ||
// $ ll out2/ | ||
// -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 | ||
// ... | ||
writeThumbnails(`${__dirname}/sample.pdf`, `${__dirname}/out2`, { | ||
width: 300, | ||
quality: 100, | ||
format: 'png' | ||
}); | ||
writeThumbnails('sample.pdf', `${__dirname}/out2`, { | ||
width: 300, | ||
quality: 100, | ||
format: 'png' | ||
}); | ||
// $ ll out2/ | ||
// -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. | ||
```js | ||
const {writeThumbnails} = require('pdf2thumbnail'); | ||
// Thumbnail of the first page only. | ||
// $ll out3/ | ||
// -rw-rw-r-- 1 ec2-user ec2-user 43157 Aug 5 09:17 sample_1.jpg | ||
writeThumbnails(`${__dirname}/sample.pdf`, `${__dirname}/out3`, { | ||
start: 1, | ||
end: 1 | ||
}); | ||
writeThumbnails('sample.pdf', `${__dirname}/out3`, { | ||
start: 1, | ||
end: 1 | ||
}); | ||
// Thumbnails for pages 2-5. | ||
// $ ll out4/ | ||
// -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 | ||
writeThumbnails(`${__dirname}/sample.pdf`, `${__dirname}/out4`, { | ||
start: 2, | ||
end: 5 | ||
}); | ||
``` | ||
// $ll out3/ | ||
// -rw-rw-r-- 1 ec2-user ec2-user 43157 Aug 5 09:17 sample_1.jpg | ||
``` | ||
- Thumbnails for pages 2-5. | ||
```js | ||
const {writeThumbnails} = require('pdf2thumbnail'); | ||
writeThumbnails('sample.pdf', `${__dirname}/out4`, { | ||
start: 2, | ||
end: 5 | ||
}); | ||
// $ ll out4/ | ||
// -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. | ||
- ### getTotalNumberOfPages(filePath: string): Promise<number> | ||
Get the total number of pages in the PDF document. | ||
Parameters: | ||
- `filePath: string`: Path of the PDF file. | ||
Parameters: | ||
- `filePath: string`: Path of the PDF file. | ||
Return value: | ||
- `{Promise<number>}`: Total number of pages in the PDF document. | ||
Return value: | ||
- `{Promise<number>}`: 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. | ||
- ### 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. | ||
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. | ||
@@ -92,0 +107,0 @@ ## Author |
2231784
114