Skip to content

Instantly share code, notes, and snippets.

@harryawk
Last active November 23, 2021 03:08
Show Gist options
  • Save harryawk/98ec398facad8740eeaa26bb210a109b to your computer and use it in GitHub Desktop.
Save harryawk/98ec398facad8740eeaa26bb210a109b to your computer and use it in GitHub Desktop.
Convert PDF to Image on Windows
const app = (file) => {
const path = require('path');
const pdf = require('pdf-poppler');
let opts = {
format: 'jpeg',
out_dir: path.dirname(file),
out_prefix: path.basename(file, path.extname(file)),
page: null
};
pdf.convert(file, opts)
.then(res => {
console.log('Successfully converted');
})
.catch(error => {
console.error(error);
});
}
app('C:\\tmp\\convertme.pdf');
@harryawk
Copy link
Author

Pre-requisite

  1. node v12.x or later
  2. npm exist (i think it will exist when we install node)
  3. your OS is Windows (haven't tried on unix OS)

Steps to run the script

  1. Go to any directory
  2. Open cmd on that dir
  3. Run npm init, press enter all the way to the end
  4. Run npm i -S pdf-poppler
  5. Change the path here
  6. Run node app.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment