Print Page | Close Window

How to change all text to black by JavaScript

Printed From: Foxit's Planet PDF Forum
Category: Lets Talk PDF
Forum Name: JavaScript
Forum Description: Discussions relating to the use of JavaScript within PDF.
Printed Date: 25 Aug 2019 at 2:28pm
Software Version: Web Wiz Forums 11.10 -

Topic: How to change all text to black by JavaScript
Posted By: oald
Subject: How to change all text to black by JavaScript
Date Posted: 18 Sep 2011 at 4:15pm
I'm using Acrobat Professional 8 and want to have a script to change all text to black, I search in Google and find that there is similar question asked in but it is for printing, I wonder is there a way to just change all text to black? Your help is really appreciated! -
codes provided:
var pp = this.getPrintParams();
pp.colorOverride = pp.constants.colorOverrides.mono;
I also read the JS API Reference and find there is an object colorConvertPage, but I cannot understand the example given:
Get a colorConvertAction object, set it up to convert everything to RGB. (Note that we do not convert any alternate spaces, hence the “space type” match is for anything but alternate spaces.)

// Get a color convert action
var toRGB = this.getColorConvertAction();
// Set up the action for a conversion to RGB
toRGB.matchAttributesAny = -1;
toRGB.matchSpaceTypeAny = ~toRGB.constants.spaceFlags.AlternateSpace;
toRGB.matchIntent = toRGB.constants.renderingIntents.Any;
toRGB.convertProfile = "Apple RGB";
toRGB.convertIntent = toRGB.constants.renderingIntents.Document;
toRGB.embed = true;
toRGB.preserveBlack = false;
toRGB.useBlackPointCompensation = true;
toRGB.action = toRGB.constants.actions.Convert;
// Convert the first page of the document
var result = this.colorConvertPage(0,[toRGB],[]);

Posted By: try67
Date Posted: 18 Sep 2011 at 4:29pm
No. JavaScript can't change the properties of text in a PDF, unless this text is in a text field.

- Acrobat Expert - Contact me personally at
Check out my custom-made scripts website:

Posted By: prodok
Date Posted: 18 Sep 2011 at 7:21pm
However, but I am not sure whether it has been already implemented in the Acrobat version you are running, you can use the Preflight functionality to do quite a bit of changes. I think changing color is possible (because changing from RGB to CMYK is a very common Preflight fixing task).

You would do this manually, but if you have to do this task frequently, you can set up a batch sequence.

Hope this can help.

Max Wyss.

Posted By: oald
Date Posted: 25 Sep 2011 at 3:01pm
Hi Try67,
Thanks so much for your prompt reply! Then I wonder how I can make it, can we make it by developing a plug-in?

Posted By: try67
Date Posted: 25 Sep 2011 at 3:09pm
Actually, it might be possible with colorConvertPage, but I have not used it so I can't help you out with it, I'm afraid.

- Acrobat Expert - Contact me personally at
Check out my custom-made scripts website:

Posted By: oald
Date Posted: 25 Sep 2011 at 3:59pm

Hi try67,

Thanks for your follow up! Just now I tried the way suggested by prodok, there is the function "Convert to grayscale" in Preflight: - -
I have a try and find that colors such as red, green and purple will be converted to gray rather than black, I wonder if I can edit preflight profile to change all text to black?
Before: - -
After: - -
Your help and instructions are really appreciated!

Posted By: oald
Date Posted: 20 Oct 2011 at 9:19am

Today I read Thom Parker's article "What's New with Acrobat 8 JavaScript?"  ( - ) and there is a paragraph about the method colorConvertPage:

"Acrobat 8.0 has three new power features, page content color conversion, booklet printing and the Net Object. A power feature is one that does a lot with very little code and the first one on the list is a good example. The Doc Object has a new function called colorConvertPage(). This amazing function converts the colorspaces for every element drawn on a PDF page; images, text and paths.  For example, say you need to convert to CMYK before sending your document out for printing. With this function you can convert not just to CMYK, but to any of several color profiles available on your system. Acrobat ships with several well-known, industry-wide color profiles. Of course, colorspace conversion can be done with the Preflight Tool and the Touchup Object Tool, but this capability allows color-space conversion to be part of an automation or workflow script."

Is is possible to convert the color space to Gray ('G") and set the color for all text to (["G",0])?


My Product Information:
Acrobat Pro 8.1.6, Windows

Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.10 -
Copyright ©2001-2017 Web Wiz Ltd. -