def to_pixbuf_with_cairo(input, scale, rotate)
doc = Poppler::Document.new(input)
page = doc[0]
width, height = page.size.collect {|x| x * scale}
surface_width, surface_height = compute_size(width, height, rotate)
surface = Cairo::ImageSurface.new(Cairo::FORMAT_ARGB32,
surface_width, surface_height)
cr = Cairo::Context.new(surface)
half_width = surface_width / 2.0
half_height = surface_height / 2.0
cr.translate(half_width, half_height)
cr.rotate(rotate / 180.0 * Math::PI)
cr.translate(-half_width, -half_height)
cr.translate((surface_width - width) / 2.0,
(surface_height - height) / 2.0)
cr.set_source_rgb(1, 1, 1)
cr.rectangle(0, 0, width, height)
cr.fill
cr.scale(scale, scale)
cr.render_poppler_page(page)
temp = Tempfile.new("pdf2")
cr.target.write_to_png(temp.path)
cr.target.finish
Gdk::Pixbuf.new(temp.path)
end