removing gray background from pdf

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
syscon
Posts: 4
Joined: 2014-12-07T10:40:35-07:00
Authentication code: 6789

removing gray background from pdf

Post by syscon »

I need help to remove gray background from a pdf file and save it as pdf if possible.
The document has two gray backgrounds.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: removing gray background from pdf

Post by Bonzo »

You should make an image available for testing as you will not get a very useful answer without.
syscon
Posts: 4
Joined: 2014-12-07T10:40:35-07:00
Authentication code: 6789

Re: removing gray background from pdf

Post by syscon »

I was trying to upload portion of the image but I couldn't find any option to make an attachement.
How add the attachment?

The two gray colors I want to remove from pdf are HEX: d2d2d2 and HEX: b8b8b8
I used gimp to get the HEX colors.

Here is the link to the image: http://i850.photobucket.com/albums/ab70 ... cument.jpg
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: removing gray background from pdf

Post by fmw42 »

First, do not use jpg from pdf. The jpg compression with make the gray colors vary. You would be best to upload the PDF or at least convert to PNG. You can post to any free hosting service and put the URLs here.

What do you mean by remove? Make transparent?

With jpeg you will need to add some small fuzz value. Try varying the fuzz value to get what you need.

Code: Select all

convert document.jpg -fuzz 1% -channel rgba -fill none -opaque "#d2d2d2" -opaque "#b8b8b8" result.png
If on windows you may need to double the %

When posting questions to this forum, please always provide your version of IM and platform.
syscon
Posts: 4
Joined: 2014-12-07T10:40:35-07:00
Authentication code: 6789

Re: removing gray background from pdf

Post by syscon »

fmw42 wrote:[snip]
When posting questions to this forum, please always provide your version of IM and platform.
Thank you for offering solution.
The IM ver. is: imagemagick-6.8.9.9 on Linux (Gentoo)

I don't care if it is transparent or white, I just want to get rid of the gray backgound when printing to save on toner as the gray scale is entire page. I just need to print the pdf file, I don't need to save it.

Note my input is pdf file: document.pdf
when I tried:

Code: Select all

convert document.pdf -fuzz 1% -channel rgba -fill none -opaque "#d2d2d2" -opaque "#b8b8b8" result2.pdf
The gray scale is till there, but the font is very choppy.
When I increased the "-fuzz 15%" the background is gone but the font is choppy and hard to read.
When I converted the PDF to PNG:
http://i850.photobucket.com/albums/ab70 ... cument.png
and use:

Code: Select all

convert document.png -fuzz 1% -channel rgba -fill none -opaque "#d2d2d2" -opaque "#b8b8b8" result2.pdf
The result is perfect. But it requires converting PDF to png.
convert document.pdf to document.png is making font very choppy.

Maybe there is a way to get rid of all colors except "black", is there? It might be simpler.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: removing gray background from pdf

Post by fmw42 »

We would need to see your PDF document to see what the issue might be. But for PDF (if vector), you can use the -density argument before reading the PDF to make it much higher resolution, then change the colors, then scale it down to a smaller size if you want.
syscon
Posts: 4
Joined: 2014-12-07T10:40:35-07:00
Authentication code: 6789

Re: removing gray background from pdf

Post by syscon »

fmw42 wrote:We would need to see your PDF document to see what the issue might be. But for PDF (if vector), you can use the -density argument before reading the PDF to make it much higher resolution, then change the colors, then scale it down to a smaller size if you want.
Thank you again.
Yes, implementing -desity helped. It is a bit slower to convert but the font quality is much better.

Code: Select all

 convert -density 300 document.pdf -fuzz 10% -channel rgba -fill none -opaque "#d2d2d2" -opaque "#b8b8b8" result1.pdf
Post Reply