How to change pdf font color

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?".
satimis
Posts: 30
Joined: 2017-04-13T19:20:03-07:00
Authentication code: 1151

How to change pdf font color

Post by satimis »

Hi all,

Please advise how to use 'convert' to change font colour on a PDF file?

Thanks

Regards
satimis
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to change pdf font color

Post by fmw42 »

Please always provide your IM version and platform/OS.

Note that ImageMagick will rasterize your PDF, process the raster image, then put a vector shell around the rasterized image. It will not preserve any vector graphics in your PDF.

See http://www.imagemagick.org/Usage/formats/#vector

If you still want to proceed, then post a link to one of your PDF files. You can post to any free hosting service and put your URL here so we can download your file.
satimis
Posts: 30
Joined: 2017-04-13T19:20:03-07:00
Authentication code: 1151

Re: How to change pdf font color

Post by satimis »

Hi fmw42,

Thanks for your advice.

OS - Ubuntu 16.04

Imagemagick
⟫ apt-cache policy imagemagick

Code: Select all

imagemagick:
  Installed: 8:6.8.9.9-7ubuntu5.3
  Candidate: 8:6.8.9.9-7ubuntu5.3
  Version table:
 *** 8:6.8.9.9-7ubuntu5.3 100
        100 /var/lib/dpkg/status
     8:6.8.9.9-7 500
        500 http://ubuntu.01link.hk xenial/main amd64 Packages
PDF File
https://www.dropbox.com/s/veyywew9dfshb ... d.pdf?dl=0

Regards
satimis
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to change pdf font color

Post by fmw42 »

try this:

Code: Select all

convert -density 300 method.pdf -fuzz 10% -fill red -opaque black result.pdf
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to change pdf font color

Post by fmw42 »

An alternate and possibly better method is

Code: Select all

convert -density 300 method.pdf -alpha copy -background red -flatten result.pdf
satimis
Posts: 30
Joined: 2017-04-13T19:20:03-07:00
Authentication code: 1151

Re: How to change pdf font color

Post by satimis »

fmw42 wrote: 2017-06-19T15:33:35-07:00 An alternate and possibly better method is

Code: Select all

convert -density 300 method.pdf -alpha copy -background red -flatten result.pdf
Your advice works here. Thanks

Before posting I tried following command but failed;

Code: Select all

convert method.pdf -fuzz XX% -fill red -opaque white result.pdf
Can I use color code such as #FB4A1C/#DEFB1C etc. ?

Edit:
Following command works seamlessly to change background color;

Code: Select all

$ convert method.pdf -background "#ffd9cf" -flatten result.pdf

Regards
satimis
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to change pdf font color

Post by fmw42 »

Yes, hex colors are permitted. On unix systems, they need to enclosed in quotes as you have done.

See the following for the forms of colors that IM can handle: http://www.imagemagick.org/script/color.php
satimis
Posts: 30
Joined: 2017-04-13T19:20:03-07:00
Authentication code: 1151

Re: How to change pdf font color

Post by satimis »

fmw42 wrote: 2017-06-19T18:11:27-07:00 Yes, hex colors are permitted. On unix systems, they need to enclosed in quotes as you have done.

See the following for the forms of colors that IM can handle: http://www.imagemagick.org/script/color.php
Following command works for me. Thanks

Code: Select all

convert -density 300 method.pdf -alpha copy -background '#1cb7fb' -flatten result.pdf
Is it possible to do follows;

1) Changing ONLY WhatsApp on the file to red and other text remaining in black?
2) Adding the word 'public' in red before Wi-Fi connection?

With pdftk
1) I can merge certain pages from within multiple .pdf files into one new document.
2) set locking password to .pdf file
etc.

Can I do those with ImageMagick convert?

Thanks

Regards
satimis
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to change pdf font color

Post by fmw42 »

satimis wrote:
Is it possible to do follows;

1) Changing ONLY WhatsApp on the file to red and other text remaining in black?
2) Adding the word 'public' in red before Wi-Fi connection?
1) You would have to create a black/white mask to use to select where you wanted to change to red and where to leave as black. See http://www.imagemagick.org/Usage/compose/#compose

2) You can use -draw or -annotate to add new text. See http://www.imagemagick.org/Usage/text/#draw and http://www.imagemagick.org/Usage/text/#annotate
satimis wrote: With pdftk
1) I can merge certain pages from within multiple .pdf files into one new document.
2) set locking password to .pdf file
etc.

Can I do those with ImageMagick convert?
1) Yes you can combine pages from one PDF with another PDF, but you have to rasterize both PDFs to the same density and then enclose that rasterized image in a vector PDF shell. So the text is no longer vector text and cannot be edited in a PDF editor.

2) ImageMagick does not have any controls that I know about for locking or unlocking PDF files.
satimis
Posts: 30
Joined: 2017-04-13T19:20:03-07:00
Authentication code: 1151

Re: How to change pdf font color

Post by satimis »

fmw42 wrote: 2017-06-19T20:58:27-07:00 - snip -

1) Yes you can combine pages from one PDF with another PDF, but you have to rasterize both PDFs to the same density and then enclose that rasterized image in a vector PDF shell. So the text is no longer vector text and cannot be edited in a PDF editor.

2) ImageMagick does not have any controls that I know about for locking or unlocking PDF files.
Your advice noted and thanks

Having tried to convert the background of a .pdf file to transparent but failed;
1)
convert image.pdf -background '#00000000' -flatten result.pdf

2)
convert image.pdf -background transparent -flatten result.pdf

3
convert image.pdf image.png
convert image.png -background transparent -flatten result.png

all failed.

Regards
satimis
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to change pdf font color

Post by fmw42 »

try this:

Code: Select all

convert -density 300 method.pdf -alpha off -transparent white result.png
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to change pdf font color

Post by fmw42 »

Your method.pdf is already transparent. But not all viewers will show the background transparency. In ImageMagick on Unix, try

Code: Select all

display method.pdf
satimis
Posts: 30
Joined: 2017-04-13T19:20:03-07:00
Authentication code: 1151

Re: How to change pdf font color

Post by satimis »

fmw42 wrote: 2017-06-19T21:29:46-07:00 try this:

Code: Select all

convert -density 300 method.pdf -alpha off -transparent white result.png
Tried;
⟫ convert -density 300 image.pdf -alpha off -transparent white image_transp.png
⟫ display image_transp.png

It works. Thanks

Image .pdf
https://www.dropbox.com/s/ygu65v1z2o7gf ... 1.pdf?dl=0

Why we need "-desity 300" up?

Edit:
⟫ convert -density 300 image.pdf -alpha off -transparent white image_transp.pdf
⟫ display image_transp.pdf
also works

satimis
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to change pdf font color

Post by fmw42 »

PDF files are vector files. They have no size. You can expand the window they are in and the image expands. When you convert to a raster image, you need to tell the PDF what density to use. The larger the density, the bigger the dimensions of the resulting raster image. Pick a density that makes your results readable.
satimis
Posts: 30
Joined: 2017-04-13T19:20:03-07:00
Authentication code: 1151

Re: How to change pdf font color

Post by satimis »

fmw42 wrote: 2017-06-19T20:58:27-07:00
satimis wrote:
Is it possible to do follows;

1) Changing ONLY WhatsApp on the file to red and other text remaining in black?
2) Adding the word 'public' in red before Wi-Fi connection?
1) You would have to create a black/white mask to use to select where you wanted to change to red and where to leave as black. See http://www.imagemagick.org/Usage/compose/#compose

2) You can use -draw or -annotate to add new text. See http://www.imagemagick.org/Usage/text/#draw and http://www.imagemagick.org/Usage/text/#annotate
Hi,

Could you please explain in more detail.

1)
What I expect to achieve is the complete text in method.pdf remain untouched,i.e. in black colour. Only the word WhatsApp changes to red color.

2)
Only add a word 'public' in red color before Wi-Fi and the complete text of method.pdf remains untouched, i.e. in black color,

Regards
satimis
Post Reply