Skip to content Skip to sidebar Skip to footer

Convert Pdf To Png Node.js

I'm building a Node.js application to convert PDF to PNGs and display on the user page. The app will work like this: User uploads a PDF to the server Server converts the PDFs pag

Solution 1:

Updated Answer

I think it all comes out at the end because Ghostscript is actually doing the work on behalf of IM. You may need to check how many pages there are in your PDF and then do a loop if you want fine-grained control.

# Get number of pages in "a.pdf"
pages=$(identify a.pdf | wc -l)

# Alternative, faster way of getting number of pages - pdfinfo is part of Poppler package
pages=$(pdfinfo a.pdf | grep "^Pages")

for all pages 0 .. (pages-1)
   convert a.pdf[$page] page-${page}.png
done

Original Answer

Not sure I 100% understand what you want, but I think it is something like this...

Say you have a 20-page PDF, called input.pdf. If you print the scene number, whose escape sequence is %s, like this

convert input.pdf -format"%s\n" -write info: z%d.png

you will get this:

Output

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

and these files:

ls z*
z0.png  z10.png z12.png z14.png z16.png z18.png z2.png  z4.png  z6.png  z8.png
z1.png  z11.png z13.png z15.png z17.png z19.png z3.png  z5.png  z7.png  z9.png

Post a Comment for "Convert Pdf To Png Node.js"