User Tools

Site Tools


cs:pdf_to_pictures

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
cs:pdf_to_pictures [2019/02/07 15:16]
paolo_bolzoni Add border parameter
cs:pdf_to_pictures [2019/02/11 16:30] (current)
paolo_bolzoni Trim paper horizontally
Line 1: Line 1:
 ======= Convert PDF to pictures ======= ======= Convert PDF to pictures =======
  
-Seldom printers fail to print a PDF file, a is converting ​the file to a sequence of pictures; basically ​doing the whole process ​to decide ​where the inks should go in your computer before sending the result to the printer.+Seldom printers fail to print a PDF file, a possible solution ​is to convert ​the file to a sequence of pictures; basically ​this means to do the whole process ​that decides ​where the inks should go in your computerbefore sending the result to the printer.
  
-Ghostscript does most of the hard work creating the pictures, however it does not apply any kind of antialiasing ​so when creating a picture in the printing resolution (usually 300 DPI) the result will be poor.+Ghostscript does most of the hard work creating the pictures, however it does not apply any kind of smoothing to the curves ​so when creating a picture in the printing resolution (usually 300 DPI) the result will be poor.
  
 To workaround this problem we use a trick similar to videogames antialiasing. We create the picture 4 times larger and we resize it later to the correct size applying smoothing algorithms. To workaround this problem we use a trick similar to videogames antialiasing. We create the picture 4 times larger and we resize it later to the correct size applying smoothing algorithms.
  
-Finally we losslessy put all the pictures in a new PDF. The resulting PDF will have no text, no fonts or anything a part of pictures. So it lost much of its convenience and the resulting file will be much larger, however printers will not fail to print it.+Finally we losslessy put all the pictures in a new PDF. The resulting PDF will have no text, no fonts or anything a part of pictures. So it loses much of its convenience and the resulting file will be much larger, however printers will not fail to print it.
  
 Software used: Software used:
Line 18: Line 18:
   $ gs -sDEVICE=pngalpha -o output-%04d.png -r1200 input.pdf   $ gs -sDEVICE=pngalpha -o output-%04d.png -r1200 input.pdf
  
-Please note that 1200 is four time the wanted resolution, we want to print to 300DPI.+Please note that 1200 is four times the wanted resolution, we want to print to 300DPI.
  
  
Line 31: Line 31:
  
  
 +====== Excessive memory usage ======
 +
 +It is possible to use greater resolutions to print for example with 600DPI, just use ''​-r2400''​. But the ''​convert''​ step may require too much memory to resize the output ''​.png''​ files. It is the case, it is possible to limit the amount of memory using environment variables:
 +
 +  MAGICK_TEMPORARY_PATH=. MAGICK_AREA_LIMIT=1024mb ​ convert ...
 +  ​
 +''​convert''​ will store its temporary files in the current directory and avoid using more than 1Gb of memory. The process might be slower, but it will end correctly.
 +  ​
 +Here is [[https://​www.imagemagick.org/​script/​resources.php#​environment|the list of environment variables that ImageMagick understands]].
 +
 +
 +====== Change paper size ======
 +
 +''​img2pdf''​ creates a ''​.pdf''​ file with the requested page size. But if the original ''​.pdf''​ was in another format the pages might have weird borders as the result will be squeezed, but not deformed. To print a letter size ''​.pdf''​ in A4 for example will result in very tall top and bottom borders; this happens because the letter paper size is wider and shorter, when squeezed in the A4 the horizontal borders will be almost the same (because the picture is just a bit smaller), but the vertical ones will be much taller.
 +
 +It is worth a try to trim the pictures to have the new paper size. To do so you need to know the correct size of the picture and ''​convert''​. For example, if you want to print 300DPI, the picture size will be the paper size **in inches** times 300.
 +
 +The command, for a 300DPI A4 will be:
 +
 +  $ convert input.png -gravity Center -crop 2481x3507+0+0 +repage output.png ​
 +
 +It is also possible to add ''​-gravity Center -crop 2481x3507+0+0 +repage''​ directly in Step two just before the output filename.
cs/pdf_to_pictures.1549552594.txt.gz ยท Last modified: 2019/02/07 15:16 by paolo_bolzoni