{"id":477,"date":"2011-02-01T23:41:44","date_gmt":"2011-02-01T21:41:44","guid":{"rendered":"http:\/\/mattiesworld.gotdns.org\/weblog\/2011\/02\/01\/convert-pdf-to-image-files\/"},"modified":"2011-02-01T23:41:44","modified_gmt":"2011-02-01T21:41:44","slug":"convert-pdf-to-image-files","status":"publish","type":"post","link":"https:\/\/world.shibby.be\/weblog\/2011\/02\/01\/convert-pdf-to-image-files\/","title":{"rendered":"Convert PDF to image files"},"content":{"rendered":"<p>Another entry in <a href=\"https:\/\/world.shibby.be\/weblog\/2008\/11\/20\/converting-multiple-images-into-a-pdf-on-linux\/\">my<\/a> PDF <a href=\"https:\/\/world.shibby.be\/weblog\/2008\/11\/25\/even-more-pdf-fun-on-linux\/\">series<\/a>. \ud83d\ude42 <\/p>\n<p>At work I had to convert a few PDFs into jpeg files. The PDF files actually contain just images, so extracting the images would&#8217;ve been as good, but converting PDF pages to images is easier. \ud83d\ude42 At least on windows. On linux you could use <a href=\"http:\/\/www.cyberciti.biz\/faq\/easily-extract-images-from-pdf-file\/\">pdfimages<\/a>, which should be available for your distro through some <a href=\"http:\/\/poppler.freedesktop.org\/\">poppler<\/a> util package.<\/p>\n<p>A general approach is to use the versatile <a href=\"http:\/\/www.imagemagick.org\">ImageMagick<\/a> software. Using the <strong>convert<\/strong> command, it&#8217;s simply a matter of:<\/p>\n<p><code>convert -density 200x200 -quality 85% inputfile.pdf outputfile%03d.jpg<\/code><\/p>\n<p>to convert inputfile.pdf to a set of jpeg files. Of course you can choose any supported output format you like: png\/bmp\/gif\/etc.. The density option is important as it specifies the output dpi which is only 72 by default. Imagemagick uses <a href=\"http:\/\/pages.cs.wisc.edu\/~ghost\/\">Ghostscript<\/a> to do the pdf reading, so on windows you have to make sure that environment is set up correctly. In my case I had to add its bin directory to the path and set the working dir to the lib path as it didn&#8217;t find gs_init.ps otherwise (adding to the path didn&#8217;t help). If you know a better way, please let me know in the comments. I also specified the quality option to have a jpeg quality factor of 85, which is 75 by default.<\/p>\n<p>Since I had to process a batch of them, I thought it would be nice to have a cool batch script to do them automatically. Here is what I came up with:<\/p>\n<p><code>C:<br \/>\nset path=%path%;C:\\programs\\gs\\gs8.54\\bin<br \/>\ncd C:\\programs\\gs\\gs8.54\\lib<br \/>\nfor %%C in (%*) do call :startconvert %%C<br \/>\ngoto :eof<\/p>\n<p>:startconvert<br \/>\nconvert -density 200x200 -quality 85%% %1 %~dp1%~n1%%03d.jpg<br \/>\ngoto :eof<br \/>\n<\/code><\/p>\n<p>Replace the paths as appropiate. To use the bat file, simply drag and drop one or more pdf file on the bat file. It will put jpeg files in the same directory as the pdf file and number them using 3 digits (<strong>%03<\/strong>d printf format). <strong>%~dp1<\/strong> stands for the full path of the 1st argument file, <strong>%~n1<\/strong> for the name only (without extension). Also note you have to escape all other %&#8217;s.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Another entry in my PDF series. \ud83d\ude42 At work I had to convert a few PDFs into jpeg files. The PDF files actually contain just images, so extracting the images would&#8217;ve been as good, but converting PDF pages to images is easier. \ud83d\ude42 At least on windows. On linux you could use pdfimages, which should &hellip; <a href=\"https:\/\/world.shibby.be\/weblog\/2011\/02\/01\/convert-pdf-to-image-files\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Convert PDF to image files<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,6,7],"tags":[],"class_list":["post-477","post","type-post","status-publish","format-standard","hentry","category-linux","category-software","category-windows"],"_links":{"self":[{"href":"https:\/\/world.shibby.be\/weblog\/wp-json\/wp\/v2\/posts\/477","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/world.shibby.be\/weblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/world.shibby.be\/weblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/world.shibby.be\/weblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/world.shibby.be\/weblog\/wp-json\/wp\/v2\/comments?post=477"}],"version-history":[{"count":0,"href":"https:\/\/world.shibby.be\/weblog\/wp-json\/wp\/v2\/posts\/477\/revisions"}],"wp:attachment":[{"href":"https:\/\/world.shibby.be\/weblog\/wp-json\/wp\/v2\/media?parent=477"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/world.shibby.be\/weblog\/wp-json\/wp\/v2\/categories?post=477"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/world.shibby.be\/weblog\/wp-json\/wp\/v2\/tags?post=477"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}