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?".
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 »

1) Yes, this can be done, but requires you to manually draw a mask around the text you want changed. Here is an example:

Input PDF converted to a png at 72 dpi (you can change the dpi to a higher value if you want a larger image or higher resolution)

Code: Select all

convert -density 72 method.pdf tmp1.png
Image


Manually draw a red box around the text you want to become red using some other tool such as Photoshop or GIMP, etc. The color is not important so long as it is not black or white.
Image


Modify the mask to be white on black background

Code: Select all

convert tmp2.png -alpha off -fill black +opaque red -fill white -opaque red tmp3.png
Image


Composite the image, a red image and the mask together to make the final PNG image. You can replace PNG with PDF if you want.

Code: Select all

convert tmp1.png \( -clone 0 -channel rgba -fill red -colorize 100 \) tmp3.png -compose over -composite method_mod.png
Image


2) ImageMagick is not a vector processor. So it cannot change vector text. Once rasterized, you can add text in any white area, but you cannot insert text between other words and change the location of any other text in an automatic manner. You could crop the text into words and recompose all the words in different locations, but this would be rather hard to do automatically.
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,

Sorry, I couldn't get it done here.

Please see;

tmp1.png
https://www.dropbox.com/s/xxf7cjj8uiydrha/tmp1.png?dl=0

tmp2.png
https://www.dropbox.com/s/7jx9usnhfe0pov1/tmp2.png?dl=0

tmp3.png
https://www.dropbox.com/s/bz3ts3qwsi2ercq/tmp3.png?dl=0

I ran LibreOffice Draw to mask WhatsApp


I found an alternative;
1) Open method.pdf with LibreOffice Draw
2) Select and copy WhatsApp
3) Paste it on LibreOffice Writer and change the color of WhatsApp to red
4) With ScreeShot select and copy the red colour WhatApp
5) Paste it on LibreOffice Draw as Bipmap image and move the image to cover the black color WhatsApp
6) Export the modified Draw document as PDF file

Please see the upload method_edited.pdf
https://www.dropbox.com/s/4kln5z2enyomk ... d.pdf?dl=0

Regards
satimis
Post Reply