Skip to content

Instantly share code, notes, and snippets.

@woctezuma
Last active April 25, 2024 11:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save woctezuma/30dd7d17d0b374c4d299c873d91abe11 to your computer and use it in GitHub Desktop.
Save woctezuma/30dd7d17d0b374c4d299c873d91abe11 to your computer and use it in GitHub Desktop.
JPG to PDF

Required softwares

How to binarize the JPG file with GIMP

  1. Open the JPG file with GIMP.
  2. Image > Echelle et taille de l'image > Hauteur : 1920 > Mise à l'échelle
  3. (optional) Couleurs > Désaturation > Couleurs vers gris > Valider
  4. Use the rectangular selection tool to manually replace image borders with a white background.
  5. Couleurs > Seuil > Auto > manually adjust the threshold > Valider

The resizing step is optional. It helps to significantly decrease the processing time for the Désaturation step.

How to convert to PDF with ImageMagick

  1. Open the folder which contains the image file with Windows File Explorer.
  2. Select the adress bar, type cmd, and press Enter.
  3. Run one of the ImageMagick commands below.

Either:

convert -density 80 -page a4 jpg.jpg pdf.pdf

or, to further decrease the file size of the PDF:

convert -resize 50% -density 80 -page a4 jpg.jpg pdf.pdf

Reference: https://stackoverflow.com/a/62446349/376454

How to ensure the page fits no matter the printer with Microsoft Edge

  1. Open the PDF file with Microsoft Edge.
  2. Imprimer (Ctrl+P) > Couleur : Noir et blanc > Echelle (%) : Ajuster à la zone d'impression > Imprimer

This step is optional. It ensures that you won't have bad surprises when printing the document, due to

  • a discrepancy between Fit and Actual size,
  • a lack of options on the printer.

How to convert from PDF to multiple PNG images with ImageMagick & Ghostscript

convert -density 300 -colorspace sRGB pdf.pdf -alpha off png-%04d.png

In case of a black background where there should be a white background, try:

convert -density 300 -background white -colorspace sRGB pdf.pdf -alpha remove png-%04d.png

References:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment