Rendering pdf pages on Windows works great but saving the rendered image using image.save() creates corrupted files. I tried both saving to 'png' and 'jpg' and both images were broken. Exactly the same code works fine on MacOS and Linux. It looks like the image files are truncated on Windows. Perhaps the file doesn't get closed properly? page_renderer pr; pr.set_render_hint(page_renderer::antialiasing, true); pr.set_render_hint(page_renderer::text_antialiasing, true); image img = pr.render_page(p, dpi, dpi); if(!img.is_valid()) throw std::runtime_error("PDF rendering failure."); if(!img.save(filename, format, dpi)) throw std::runtime_error("Failed to save file" + filename); I am using poppler 0.57.0 on mingw-w64/gcc 4.9.3 but I have been able to reproduce this problem with all other versions of poppler and mingw-w64.
Created attachment 135236 [details] [review] patch for cpp image writer
I have finally found the problem. The file is opened in text mode "w" instead of binary mode "wb". In cpp/poppler-image.cpp on line 374 it says: FILE *f = fopen(file_name.c_str(), "w"); This should be: FILE *f = fopen(file_name.c_str(), "wb"); Attached a patch.
Pushed
Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.