wangsijie / pdf2jpg Goto Github PK
View Code? Open in Web Editor NEWConvert PDF pages to a single jpg by using pdf.js and node-canvas.
Home Page: pdf2jpg.vercel.app
License: MIT License
Convert PDF pages to a single jpg by using pdf.js and node-canvas.
Home Page: pdf2jpg.vercel.app
License: MIT License
Thanks for the library!
Can you allow the scale variable to be an optional, defaulted parameter?
I would submit a PR but others are blocked from creating branches.
index.js
const scale = 1; // Remove this line
.
.
.
async function app(pdfData, options = { scale: 1 }) { // Add parameter with same default value of 1
const doc = await pdfjsLib.getDocument(pdfData).promise;
const draw = new Draw();
for (let i = 0; i < doc.numPages; i++) {
const page = await doc.getPage(i + 1);
const viewport = page.getViewport({ scale: options.scale }); // Use options
.
.
.
using https://commons.wikimedia.org/wiki/File:ABC_de_l%27%C3%89lecteur.pdf as an example,
when calling the API as follows
const jpgBuffer = await pdf2jpg(buffer, { scale: 1, page: 1 })
the generated image is mostly black. A small yellow square is at the bottom. (the first page).
This seems to come from index.js line 65:
height += Math.ceil(viewport.height);
which I think is supposed to be
height = Math.ceil(viewport.height);
还没有详细测试一页一页输出能否自动识别页面方向。
would be nice to just convert a singe page instead of the whole pdf
{page: pages.length}
如果能自定义页码范围就更好了,如:
{page: [2, pages.length -1]}
我知道可以自己写循环,但需要直接引用 pdfjs-dist,提供个接口显然更方便。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.