How to convert selected pdf page with gm

◇◆丶佛笑我妖孽 提交于 2019-12-07 03:36:27

for only first pdf page use:

gm(file, 'pdf.pdf[0]').toBuffer(...)

for only second pdf page use:

gm(file, 'pdf.pdf[1]').toBuffer(...)

gm(file).selectFrame(0).toBuffer() // To get first page

gm(file).selectFrame(1).toBuffer() // To get second page

There is spindrift for manipulating pdf (includes image conversion).

You can define your pdf using (You don't have you use all of the commands):

var pdf = spindrift('in.pdf')
   .pages(7, 24)
   .page(1)
   .even()
   .odd()
   .rotate(90)
   .compress()
   .uncompress()
   .crop(100, 100, 300, 200) // left, bottom, right, top 

Later on convert to image:

// Use the 'index' property of an image element to extract an image: 
pdf.extractImageStream(0)

If you have to use gm, you can do what @Ben Fortune suggested in his comment and split the pdf first.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!