Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert pdf with 300dpi bitmaps to svg

I'm creating a tool to convert pdf's into svg. These pdf's contain graphical data, including large bitmaps at 300 dpi and a bunch of vectors as well. Poking around here on stackoverflow, I've found pdf2svg, which great -- works like a charm, and the vector data is perfect. But it looks like the bitmaps are getting downscaled to 72dpi. The dimensions are still 8x10 in inches, but you can tell that the dpi isn't right when you zoom in. Soft of makes sense that the default values would presume 72 dpi, but I need the full resolution bitmap images.

pdf2svg uses poppler and cairo to make the conversion. I've poked around in the code, and I see where it's creating a poppler page and a cairo surface, and I've seen in the documentation that a poppler page has a concept of "scale" that seems relevant, but I can't figure out where to plug it in. I tried (experimentally) hardcoding the height and width passed into cairo_svg_surface_create to the correct values, but it made the dimensions applied to the whole svg larger, without affecting the embedded bitmap.

poppler_page_get_size (page, &width, &height);

// Open the SVG file
surface = cairo_svg_surface_create(svgFilename, width, height);
drawcontext = cairo_create(surface);

// Render the PDF file into the SVG file
poppler_page_render(page, drawcontext);
cairo_show_page(drawcontext);

I don't think what I'm trying to do is very esoteric, so I'm hoping someone who has experience with the libraries will see my error right away. Any help, of course, would be immensely appreciated.

like image 902
Paul Degnan Avatar asked May 12 '12 01:05

Paul Degnan


1 Answers

I just made the change to the source as described in http://lists.freedesktop.org/archives/poppler/2011-December/008451.html and it worked perfectly - the images seem to be at their native resolution.

Replace

poppler_page_render(page, drawcontext);

with

poppler_page_render_for_printing(page, drawcontext);
like image 193
Jake Weston Avatar answered Sep 30 '22 09:09

Jake Weston