Tips & Tricks

Change field shading with JavaScript when printing

November 15, 2002

Advertisement
Advertisement
 

What if you want to display shaded fields to assist with on screen filling out of forms, but when you print the final version, you want the fields to be unshaded. And, you want to use your own custom color to shade the fields?

Well, with a little bit of JavaScript, the problem is solved below. See this working example in PDF.

  • To write the least amount of JavaScript, create field names that are hierarchical. For example, if you have 5 fields - Name, Company, URL, Email, and Phone - if you name them as "color.Name", "color.Company", "color.URL", "color.Email", and "color.Phone" then you only need one JavaScript command to turn on/off all the fields at once.
  • Create custom RGB color at the Document Level:
color.MyColor = new Array("RGB", .75, 1, 1);

Note: Although Acrobat displays the color as 191,255,255 in the Color Palette, you will have to divide each by 255 to get the values required for the color Array.

  • Create a document level JavaScript to "turn off" the color:
function PrintNoColors()
{
var f=this.getField("color");
f.fillColor = color.white;
}
  • Create a document level JavaScript to "turn on" the color:
function ResetColor()
{
var f=this.getField("color");
f.fillColor = color.MyColor;
}
  • Add the function "PrintNoColors()" on "Doc Will Print" (Tools > JavaScripts > Document Actions)
  • Add the function "ResetColor()" on the "Doc Did Print" (Tools > JavaScripts > Document Actions)
Related Products at PDF Store

PDFlib TET

Reliably extract text from any PDF file with this library/component. TET makes available the text co... View full product details
Download free demo

Nitro PDF Professional

Nitro PDF Professional, your PDF creation and editing product. Priced at $99, Nitro PDF Pro is the m... View full product details
Download free demo

ARTS PDF Aerialist

Take Acrobat to the next level with advanced splitting and merging; flexible bookmark creation and m... View full product details
Download free demo

PDF In-Depth Free Product Trials Ubiquitous PDF

Nitro PDF Professional

the perfect PDF product for business and enterprise, combining an extremely competitive price with a...

Download free demo

XpdfViewer

This ActiveX control (OCX) provides a PDF file viewer component, enabling developers to add PDF viewing...

Download free demo

Ubiquitous PDF: PDF eBooks-Library

If you are looking for a good store of PDF content, you could do a lot worse than visiting eBooks-Library.com...

September 03, 2009
Search Planet PDF
more searching options...







Download PDF Creator

Download The Best of Planet PDF volume 2
Planet PDF Newsletter
Most Popluar Articles
Features

Collating PDFs using JavaScript

Despite the numerous benefits, there can be potential issues with the conversion of paper documents into electronic archives. When scanning paper pages into PDF, it's possible to end up with the odd- and even-numbered pages in separate PDF files. It can be very time-consuming to collate them manually, but there is an easier way. Sean Stewart explains.

Featured Product

BCL easyPDF SDK

BCL easyPDF SDK is a set of PDF Programming Libraries designed specifically to help Software Developers / Programmers build and deploy enterprise class PDF applications for corporate wide PDF...

Platinum Sponsor
Create & Edit PDF - Nitro PDF Software

ARTS PDF

Silver Sponsors

PDF-Tools enfocus

QuickPDF: The Unrivaled PDF Developer Toolkit