Sharpen PDF file

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
brighthero
Posts: 8
Joined: 2017-09-12T07:00:23-07:00
Authentication code: 1151

Sharpen PDF file

Post by brighthero » 2017-09-19T12:53:13-07:00

I have a PDF file with multiple pages only containing scanned images. What's the quickest way to sharpen the PDFs using imagemagick? Or do I have to convert the file into images first using another tool?

Thanks in advance!

Bonzo
Posts: 2863
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Sharpen PDF file

Post by Bonzo » 2017-09-19T12:58:23-07:00

Imagemagick will convert the pdf to a raster file so if you want to save it to a pdf you may better off using a dedicated pdf program.

If you want to save it as a jpg, png etc. Imagemagick can do that.

snibgo
Posts: 9479
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Sharpen PDF file

Post by snibgo » 2017-09-19T13:01:56-07:00

brighthero wrote:I have a PDF file with multiple pages only containing scanned images.
First, you can extract the raster images with pdfimages. Then sharpen those with IM and, if you want, put those in a PDF file.
snibgo's IM pages: im.snibgo.com

brighthero
Posts: 8
Joined: 2017-09-12T07:00:23-07:00
Authentication code: 1151

Re: Sharpen PDF file

Post by brighthero » 2017-09-19T13:02:54-07:00

Why woudn't "convert -density 300" work just the same way?

Bonzo
Posts: 2863
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Sharpen PDF file

Post by Bonzo » 2017-09-19T13:14:11-07:00

Why woudn't "convert -density 300" work just the same way?
What does this mean?

Did you read what snibgo and I said about raster files?

brighthero
Posts: 8
Joined: 2017-09-12T07:00:23-07:00
Authentication code: 1151

Re: Sharpen PDF file

Post by brighthero » 2017-09-19T13:15:38-07:00

convert -density 300 input.pdf -sharpen 0x1 output.pdf

This command seems to be doing the same thing, or am I mistaken? It seems to use Ghostscript under the hood.

User avatar
fmw42
Posts: 22232
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Sharpen PDF file

Post by fmw42 » 2017-09-19T14:54:26-07:00

You can get sharper results by increasing the density and then resizing. But saving as PDF will only put a vector shell around the rasterized pdf.

brighthero
Posts: 8
Joined: 2017-09-12T07:00:23-07:00
Authentication code: 1151

Re: Sharpen PDF file

Post by brighthero » 2017-09-20T08:30:55-07:00

Example: https://drive.google.com/file/d/0B1LWck ... sp=sharing

What would be an example script to do the sharpening the right way using the resizing?
The file size should be about the same as it was before.

User avatar
fmw42
Posts: 22232
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Sharpen PDF file

Post by fmw42 » 2017-09-20T09:26:24-07:00

Your PDF is not simply vector, but is a raster image contained in a vector shell. But PDF files have no size until you provide a density for viewing.

Have you tried either

Code: Select all

convert -density 150 "ImageMagick Example.pdf" test1.pdf

Code: Select all

convert -density 150 "ImageMagick Example.pdf" -unsharp 0x1 test2.pdf
Be sure your viewer is showing the result at a good density/resolution.

brighthero
Posts: 8
Joined: 2017-09-12T07:00:23-07:00
Authentication code: 1151

Re: Sharpen PDF file

Post by brighthero » 2017-09-20T11:04:01-07:00

Wow, that's works great, but now my file sizes are huge.
What's the best way to get back to much smaller file sizes?

User avatar
fmw42
Posts: 22232
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Sharpen PDF file

Post by fmw42 » 2017-09-20T11:48:13-07:00

Does this help?

Code: Select all

convert -density 150 "ImageMagick Example.pdf" -resize 50% -unsharp 0x1 test2.pdf

snibgo
Posts: 9479
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Sharpen PDF file

Post by snibgo » 2017-09-20T11:57:34-07:00

IM commands will rasterize each PDF page at whatever density you decide.

But your PDF file contains two JPEG images, with no vector data. pdfimages can extract the images, as JPEG files, without worrying about density. You can then sharpen these, or do whatever you want.
snibgo's IM pages: im.snibgo.com

brighthero
Posts: 8
Joined: 2017-09-12T07:00:23-07:00
Authentication code: 1151

Re: Sharpen PDF file

Post by brighthero » 2017-09-21T07:29:24-07:00

fmw42 wrote:
2017-09-20T11:48:13-07:00
Does this help?

Code: Select all

convert -density 150 "ImageMagick Example.pdf" -resize 50% -unsharp 0x1 test2.pdf
What parameters do I have to modify to make the sharpening even more intense?

snibgo
Posts: 9479
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Sharpen PDF file

Post by snibgo » 2017-09-21T09:04:24-07:00

See http://www.imagemagick.org/script/comma ... hp#unsharp . Use a larger gain, eg 1.5 or 5.0 or 20.
snibgo's IM pages: im.snibgo.com

Post Reply