PDF2Pic

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!也欢迎投稿人!

Prerequisite先决条件

Don't have graphicsmagick and ghostscript yet?还没有graphicsmagic和ghostscript吗?

Follow this guide to install the required dependencies.按照本指南安装所需的依赖项。

Installation安装

npm install -S pdf2pic

Usage用法

Converting specific page of PDF from path, then saving as image file从路径转换PDF的特定页面,然后另存为图像文件

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;
});

Nuff talk, show me how:胡言乱语,告诉我如何:

More usage example can be found here.更多用法示例可在此处找到。

pdf2pic API

fromPath(filePath, options)

Initialize PDF to image conversion by supplying a file path通过提供文件路径初始化PDF到图像的转换

Functions功能

Converts specific page of the PDF to Image/Base64 by supplying a file path通过提供文件路径将PDF的特定页面转换为Image/Base64

fromPath(filePath, options).convert(pageNumber, isBase64)

Converts PDF to Image/Base64 by supplying a file path通过提供文件路径将PDF转换为Image/Base64

fromPath(filePath, options).bulk(pageNumber, isBase64)

Set GraphicsMagick's subclass or path设置GraphicsMagick的子类或路径

fromPath(filePath, options).setGMClass(subClass)

NOTE: should be called before calling convert() or bulk().注意:应该在调用convert()bulk()之前调用。


fromBuffer(buffer, options)

Initialize PDF to image conversion by supplying a PDF buffer通过提供PDF缓冲区初始化PDF到图像的转换

Functions功能

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)相同的函数只是更改了输入


fromBase64(b64string, options)

Initialize PDF to image conversion by supplying a PDF base64 string通过提供PDF base64字符串初始化PDF到图像的转换

Functions

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)相同的函数,只是更改了输入


options选项

Following are the options that can be passed on the pdf2pic api:以下是可以在pdf2pic api上传递的选项:

Contributing贡献

License许可证

pdf2pic is MIT licensed.