2

PDF ファイルのページを GtkIconView に表示したいと考えています。これを実現するには、GtkTreeModel に GDK_TYPE_PIXBUF 型の列が必要です。PDF ページを Pixbuf にレンダリングするにはどうすればよいですか?

page、a 、私はこれをPopplerPage試しました:

surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 320, 240)
page.render(surface)
img = Gdk.pixbuf_get_from_surface(surface, 0, 0, 320, 240)

((*&(&cr->ref_count)->ref_count) > 0)ただし、コマンドを実行するとアサーションに関するエラーが発生しますrender

4

2 に答える 2

2

Finally, I figured out. I have to render to a cairo Context, like this:

surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, w, h)
ctx = cairo.Context(surface)
page.render(ctx)
img = Gdk.pixbuf_get_from_surface(ctx.get_target(), 0, 0,
        ctx.get_target().get_width(),
        ctx.get_target().get_height())
于 2013-01-29T03:02:33.030 に答える
0

これを試して

 # get pdf
 pdf = mkpdf(ds,sample=True)

# render pdf onto pixbuf
pixbuf = Pixbuf(COLORSPACE_RGB,False,8,286,225)
doc = poppler.document_new_from_data(pdf,len(pdf),password='')
page0=doc.get_page(0)
page0.render_to_pixbuf(0,0,8,11,1,0,pixbuf)

# save pixbuf as png
# There has to be a better way to get the image?
lst=[]
pixbuf.save_to_callback(lambda b,l: l.append(b), 'png', user_data=lst)
png=''.join(lst)

return png

参照

于 2013-01-28T19:50:18.807 に答える