PDA

View Full Version : Assigning color in OnRecordStart


jdubois
February 27th, 2012, 11:02 AM
I have a product which references defined colors in the PDF document for various colored text and text boxes, etc. As example, color 1 is C=4 M=24 Y=50 K=25, color 2 is C=25 M=25 Y=0 K=0, etc. I have defined these colors in the fusion pro document under Advanced>Colors menu.

now the user would like to be able to change these colors within the fields of the Marcomm store. So for example, out of a list of 12 defined colors for the product, they would like to select and define from a drop down for color 1, color 2, color 3, etc. and have it utilize those values to create the PDF.

I have no idea how to define color values on the fly rather than through the fusion pro program, though I am assuming it can be done in some fashion with an OnRecordStart rule.

Can anyone help me with an example on how I might be able to accomplish this?

esmith
February 27th, 2012, 12:45 PM
I don't know that that can be done with JavaScript within a FP rule. I would think you would need to define all your colors in the Color palette and then offer a drop down box on MarcomCentral for the user to choose the colors they want from your existing palette.

Having said that, I just recently learned that it is possible to write a custom XML .dif file during the call from the portal to FPServer. Since the .dif file contains the color definitions, it stands to reason that colors could be defined via custom-generated .difs for each "order". Since I am just now "stepping in the shallow end" of this concept, you will need Dan's assistance (as will I).

ThomasLewis
February 27th, 2012, 03:58 PM
You can do this with the <color> tag. The only issue is it is expecting hex values. I wrote the following function to convert CMYK to hex:

function cmyk2hex(cmyk)
{
a = cmyk.split("-");
hex = "";

for (x=0;x<4;x++)
{
h = Math.round(a[x] * 2.55).toString(16);
if (h.length == 1) hex += "0" + h;
else hex += h;
}

return hex;
}

return '<color cmyk="' + cmyk2hex("100-0-40-0") + '">' + "text" + '</color>';

Just put your values in CMYK order between the hyphens.

esmith
February 28th, 2012, 05:19 AM
Nice solution Thomas. Thanks for sharing!