A utility for converting pdf to image and base64 format.用于将pdf转换为图像和base64格式的实用程序。github
IMPORTANT NOTE: Please support this library by donating via PayPal, your help is much appreciated.重要提示:请通过PayPal捐赠来支持这个库,非常感谢您的帮助。Contributors are also welcome!也欢迎投稿人!
Follow this guide to install the required dependencies.按照本指南安装所需的依赖项。
npm install -S pdf2pic
import { fromPath } from "pdf2pic";
const options = {
density: 100,
saveFilename: "untitled",
savePath: "./images",
format: "png",
width: 600,
height: 600
};
const storeAsImage = fromPath("/path/to/pdf/sample.pdf", options);
const pageToConvertAsImage = 1;
storeAsImage(pageToConvertAsImage).then((resolve) => {
console.log("Page 1 is now converted as image");
return resolve;
});
More usage example can be found here.更多用法示例可在此处找到。
Initialize PDF to image conversion by supplying a file path通过提供文件路径初始化PDF到图像的转换
Converts specific page of the PDF to Image/Base64 by supplying a file path通过提供文件路径将PDF的特定页面转换为Image/Base64
fromPath(filePath, options).convert(pageNumber, isBase64)
filePath
- options
- pageNumber
- isBase64
- convert()
will return base64 output insteadtrue
,convert()
将返回base64输出Converts PDF to Image/Base64 by supplying a file path通过提供文件路径将PDF转换为Image/Base64
fromPath(filePath, options).bulk(pageNumber, isBase64)
filePath
- options
- pageNumber
- pageNumber
to -1
to select all pagespageNumber
设置为-1
以选择所有页面pageNumber
[1,2,3]
1
isBase64
- bulk()
will return an array of base64 output insteadtrue
,bulk()
将返回base64输出的数组Set GraphicsMagick's subclass or path设置GraphicsMagick的子类或路径
fromPath(filePath, options).setGMClass(subClass)
NOTE: should be called before calling 注意:应该在调用convert()
or bulk()
.convert()
或bulk()
之前调用。
filePath
- options
- subClass
- true
以使用imagemagick subClass
to true to use imagemagicksubClass
设置为true
以使用imagemagicksubClass
to locate gm path specifiedsubClass
以定位指定的gm路径Initialize PDF to image conversion by supplying a PDF buffer通过提供PDF缓冲区初始化PDF到图像的转换
Converts specific page of the PDF to Image/Base64 by supplying a buffer通过提供缓冲区将PDF的特定页面转换为Image/Base64
fromBuffer(buffer, options)(pageNumber, isBase64)
Functions same as 与fromPath(filePath, options)(pageNumber, isBase64)
only input is changedfromPath(filePath, options)(pageNumber, isBase64)
相同的函数只是更改了输入
Converts PDF to Image/Base64 by supplying a buffer通过提供缓冲区将PDF转换为Image/Base64
fromBuffer(buffer, options).bulk(pageNumber, isBase64)
Functions same as 与fromPath(filePath, options).bulk(pageNumber, isBase64)
only input is changedfromPath(filePath, options).bulk(pageNumber, isBase64)
相同的函数只是更改了输入
Set GraphicsMagick's subclass or path设置GraphicsMagick的子类或路径
fromBuffer(buffer, options).setGMClass(subClass)
Functions same as 与fromPath(filePath, options).setGMClass(subClass)
only input is changedfromPath(filePath, options).setGMClass(subClass)
相同的函数只是更改了输入
Initialize PDF to image conversion by supplying a PDF base64 string通过提供PDF base64字符串初始化PDF到图像的转换
Converts specific page of the PDF to Image/Base64 by supplying a base64 string通过提供Base64字符串将PDF的特定页面转换为Image/Base64
fromBase64(b64string, options)(pageNumber, isBase64)
Functions same as 与fromPath(filePath, options)(pageNumber, isBase64)
only input is changedfromPath(filePath, options)(pageNumber, isBase64)
相同的函数,只是更改了输入
Converts PDF to Image/Base64 by supplying a base64 string通过提供Base64字符串将PDF转换为Image/Base64
fromBase64(b64string, options).bulk(pageNumber, isBase64)
Functions same as 与fromPath(filePath, options).bulk(pageNumber, isBase64)
only input is changedfromPath(filePath, options).bulk(pageNumber, isBase64)
相同的函数,只是更改了输入
Set GraphicsMagick's subclass or path设置GraphicsMagick的子类或路径
fromBase64(b64string, options).setGMClass(subClass)
Functions same as 与fromPath(filePath, options).setGMClass(subClass)
only input is changedfromPath(filePath, options).setGMClass(subClass)
相同的函数,只是更改了输入
Following are the options that can be passed on the pdf2pic api:以下是可以在pdf2pic api上传递的选项:
quality
- format
- width
- height
- density
- savePath
- saveFilename
- compression
- pdf2pic is MIT licensed.