question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multi Page pdf conversion

See original GitHub issue

First of all, this project is amazing.

I have a question is about sharp api.

I am converting multi-pages pdf files to jpeg (each page is a separate file). What would be most efficient way to do this? This is a sample implementation that I am using now.

const input = getBufferSomeHow()
const metatada = await sharp(input).metadata()
const conversions = []
for (let i = 0; i < metadata.pages; i++) {
  conversions.push(
   sharp(input, {
       density: myDensity,
       pages: 1,
       page: i,
   }.jpeg().toBuffer())
}
const buffers = await Promise.all(conversions)

When I say most efficient I mean that “given an input buffer that is a multipage pdf, what is the best way to use that buffer to convert its pages in single jpeg files? Is the approach of instantiating sharp every time valid?”. Would sharp.clone help in any way?

Thank you 😄 .

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
lovellcommented, Nov 1, 2019

Both your approaches look good to me given the complete PDF/GIF is already in memory, or at least on a fast local filesystem. libvips’ default caching should help too - use sharp.cache() to check.

0reactions
dnlupcommented, Apr 28, 2020

@brecke Last thing, you might find this useful

Read more comments on GitHub >

github_iconTop Results From Across the Web

Multiple pages per sheet online & free
PDF Layout: You can easily set multiple pages per sheet (e.g. for printing) in your PDF with this online tool - just in...
Read more >
PDF N-up tool - multiple pages per sheet - PDFResizer.com
PDF multiple pages per sheet (N-up) converter. Welcome to a free online tool for rearranging PDF document layout to print multiple pages per...
Read more >
Merge PDF Pages Into One Page - AvePDF
Convert multiple PDF pages into one page. Drop in your multipage PDF and merge all PDF pages into 1 single page. 100% free...
Read more >
PDF N-up tool - multiple pages per sheet - DeftPDF
Plan PDF Layouts for printing. You can easily set multiple pages per sheet (e.g. for printing) in your PDF with this Free online...
Read more >
How to Make a Multi Page PDF with Simple Clicks - EaseUS
To make multi-page PDF files, Soda PDF Editor is an excellent option. It has a fantastic online "Merge" tool that lets you instantly...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found