29

I've tried opening the Accessibility menu and choosing black background with green font, but it seems this does not work if the document was originally scanned in Black/White mode. Is there any other way to enhance the PDF's contrast?

2
  • 2
    Unless you ran OCR on the scan, there is no text, just a picture of text, so no text-related settings will affect anything.
    – fixer1234
    Jul 7, 2016 at 21:46
  • 3
    Extract images (scanned pages) from PDF, use some image manipulation to enhance contrast, put images back. I don't know of any PDF viewers that allow you to manipulate image contrast directly.
    – dirkt
    Sep 13, 2016 at 9:49

8 Answers 8

27

If it has tons of pages, the easier tool is a command line one: http://www.imagemagick.org/script/download.php

(ImageMagick is a very popular image manipulation library.)

You will have to do three steps.

  1. Convert PDF pages to individual image files. See: Convert PDF to image with high resolution or Convert PDF to JPG images with ImageMagick - how to 0-pad file names?

    convert -density 600 your_pdf_filename.pdf  output-%02d.jpg
    
  2. Adjust image quality. If you have only a few pages, Photoshop or GIMP (free and open-source alternative to Photoshop) will simply import each page as an image. Update the contrast as you'd like and save. For more info see Gimp: how to remove background noise/artifacts and enhance handwritten text or continue to use ImageMagick: Batch-processing images of documents to look like a fax

    convert output*.jpg -normalize -threshold 80% final-%02d.jpg
    
  3. If you want a pdf back:

    convert final*.jpg my_new_highcontrast.pdf
    
5
  • 4
    Problem with this is, if you have lots of bookmarks in the pdf, they are all lost.
    – bgmCoder
    Apr 5, 2019 at 2:12
  • @bgmCoder good point. Moving from pdf to images and back to pdf will essentially kill every single PDF feature besides the content itself. Even pure text will become an image. But the question was about a PDF created from a scan, so I assumed it would only have images anyway.
    – gcb
    Nov 10, 2019 at 0:00
  • 1
    On windows the command is magick convert instead of convert. Additionally, Ghostscript must be installed otherwise you will get a FailedToExecuteCommand gswin32c.exe The system cannot find the file specified.
    – JoseOrtiz3
    Apr 2, 2020 at 3:29
  • Tip: if your book has more than 99 pages, use %03d instead of %02d, otherwise the pages will be in the wrong order, because page 100 will be after 10.
    – Topera
    Feb 27, 2021 at 21:13
  • Very good solution. Not sure what happened on my side I have to output each intermediate step into .png not .jpg so that my final .pdf won't be broken with purple color whole page.
    – haxpor
    Apr 9, 2021 at 8:48
7

I have a PDF with a lot of gray images (manga). So I used the answer of gcb, changing the 2nd command to:

convert output.jpg -level 25% output_contrast.jpg

Just change the level value percentage to what serves you.


Observation.

With the arg -threshold you get a "black and white" (only) image. But I want to keep the gray scale, which is possible with the arg -level: you keep the gray, letting the image with a darker or lighter gray scale.


The commands order will be:

convert your_pdf_filename.pdf output-%02d.jpg
convert output*.jpg -level 25% final-%02d.jpg
convert final*.jpg very_readable.pdf
4
  • 2
    So what is the advantage of this variation compared the answer by gcb?
    – Blackwood
    Dec 14, 2017 at 13:48
  • 3
    With "threshold" you get a "black and white" (only) image. With "level" you keep the gray, letting it "darker" or "lighter"
    – Zack
    Dec 14, 2017 at 14:37
  • 2
    That would be good information to edit into your answer.
    – Blackwood
    Dec 14, 2017 at 14:41
  • 6
    The -level parameter accepts one, two, or three numbers separated by a comma. For instance -level 30%,100%,0.3. The first is "black level" , next is "white level", and finally "gamma". Anything pixel darker than 30% becomes black, and pixel brighter than 100% becomes white, and then a nonlinear power law transformation with gamma=0.3 is applied for the in-between values (gamma=1.0 means linear, no transformation). Use a single image to quickly play around with the parameters to get desired result.
    – JoseOrtiz3
    Apr 2, 2020 at 4:35
5

In case you want a solution in python: github gist. The script converts the pdf to images, modifies their contrast and writes it back to pdf.

Usage example

$ python pdf_contrast.py 2.3 -i in.pdf -o out.pdf
Loading pdf in.pdf
Pages: 48
Contrast x2.3: 100%|███████████████████████| 48/48 [00:02<00:00, 18.42pages/s]
Saving pdf to out.pdf
2
  • Very helpful script!. Since I already had a pipeline manipulating each page, just added enhancer = ImageEnhance.Contrast(pil_img); enhanced_img = enhancer.enhance(contrast) and voila!, images & the end pdf now have more contrast!
    – rrh
    Nov 26, 2022 at 15:16
  • cannot find the file specified >> Unable to get page count. Is poppler installed and in PATH? :/
    – oldboy
    Jan 13, 2023 at 3:59
4

Nuance Paperport has the ability to increase contrast on scanned pdf pages.

The free software NAPS2 is also able to do this, either in combination with scanning or after importing a scanned page. NAPS2 also has other features, e. g. to crop and to automatically deskew a scanned page. On my machine (Core i5, 8 GB) import is a bit slow, but the page editing seems to work fine.

2
  • NAPS2 works great - it is easy enough and intuitive, but if you have any bookmarks already in the pdf, they will all be lost.
    – bgmCoder
    Apr 5, 2019 at 2:20
  • NAPS2 was a great answer.
    – user606723
    Oct 14, 2023 at 21:13
2

For Windows, I wrote a batch file .bat to automatically generate the PDF upon drag-and-drop onto the batch file. (linux/OSX would require translating this to a shell script)

You first need to have ImageMagick (allow installer to add to PATH so magick convert works from the command line) and GhostScript installed. Don't worry, they are easy to install.

Here is the batch file. Make a file pdf_darkener.bat with the following contents:

@echo off
echo Darkening the pdf at %1 
echo Converting PDF to JPGs...
magick convert -density 500 %1 darken_pdf_preprocess_%%02d.jpg
echo Darkening JPGs...
magick convert darken_pdf_preprocess*.jpg -level 50%%,100%%,0.3 darken_pdf_postprocess_%%02d.jpg
echo Converting JPGs to PDF...
magick convert darken_pdf_postprocess*.jpg darkened.pdf
echo Deleting JPGs...
del darken_pdf_*.jpg
echo Done!
pause

Drag any PDF file onto the batch file. Wait for operations to complete (slowness / level of detail is controlled by density 500, higher = more pixels, bigger file size, slower). The output pdf will be in the same directory as the original pdf. The batch file cleans up after itself, deleting the intermediate jpgs created during processing.

enter image description here

enter image description here

Note that this contrast-increasing operation is controlled by three numbers: 50%%,100%%,0.3 which means 50%, 90%, and 0.3. These are black_level, white_level, and gamma, according to the ImageMagick documentation. black_level is the percentage of brightness below which everything gets mapped to pure black, visa-versa for white. Gamma controls a non-linear mapping for the in-between values (1.0 is linear).

Please share any improvements or useful modifications in the comments section.

1

You can convert pdf to jpg online . Adjust pictures on a photo editor. I used Adobe Lightroom to adjust contrast on multiple photos at once with synchronized settings to save time. Then convert JPG to PDF online

1

If you are not comfortable with Image Magick and command line and want more control over the process, I suggest using Foxit PdfPhantom (Business Version) along with adobe Photoshop. You can simply convert your pdf to any image format that you want with Foxit under the Convert tab. Then you can use Photoshop to apply a specific sequence of operations to a series of photos. For this purpose, see this tutorial. Finally, you can turn back to pdf using Foxit.

1
  • tried Foxit to export to JPG, TIFF, JP2 on max settings - it degrades the quality of picture. Not working solution May 14, 2020 at 7:38
0

I do not think that any of the PDF viewers have built in filters or adjustments for pictures, only for fonts backgrounds and colors.

You could adjust your monitor, and/or if your video card software supports it adjust the video cards, video settings. Save the video settings in a profile to use again, for this purpose, it would not be too bad.

You could print it and adjust your printer (most printer preferances allow adjusting).
You could Screen grab it , then paste it into a picture/photo editor and adjust.
If your "allowed" and have PDF creation program you could fix each picture used, and remake it.
If you have Adobees photoshop program, some versions of it would open a PDF, I do not know what it could do.

See also Adjust PDF Contrast with Adobe Reader/Acrobat?
It has some very good and easy answers if the PDF is not locked down.

You did not indicate if it is one picture, or many, which would help the question. You did not indicate the operating system (even a tag for it works). adding that information to the question will improve being able to answer.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .