Jump to content

Changing Color on a QR Code


Recommended Posts

I'm trying to make a QR code that is a spot color. I've got the QR code created (as a graphic), however i can't seem to figure out how to change the color.

I did try to create a text QR code, however it looks like it is in a different format and doesn't give me the all the contact fields I need.

Link to comment
Share on other sites

I looked at that, however I have 2 problems with that rule:

1. It looks like a MECARD format, where the graphic rule is a VCARD. I need the extra fields that VCARD offers, I'm not sure how to use the text rule to create a VCARD instead of a MECARD.

2. it appears that I can only adjust the sizing of the QR code by changing the "PointSize" attribute, however it looks like it has to be a whole number, I need the QR code to fit in a space, so I would need a point size of something like 3.625.

 

Thanks,

Jake

Link to comment
Share on other sites

As Alex mention create a text rule making sure to check "treat return strings as tagged text". Following code I've used for 2D code, just swapped out DataMatrixBarcode and use QRBarcode instead:

 

//var barcode = new DataMatrixBarcode;

var barcode = new QRBarcode;

barcode.processTilde=false;

barcode.preferredFormat = 3;

barcode.encodingMode="ASCII";

barcode.pointSize=7;

return barcode.Make(Field("f1"));

 

Insert the variable into a text frame and apply the spot color you created to it.

 

In preview it works for me and attached is the PDF I generated.

test.pdf

Link to comment
Share on other sites

Tou,

Thanks for the reply. I can get the text QR code to work in the color I need, however what I'm not sure how to do is create a VCARD (instead of a MECARD), and how to get the font size to not be a whole number (I need the font size something like 3.625).

Link to comment
Share on other sites

I can get the text QR code to work in the color I need, however what I'm not sure how to do is create a VCARD (instead of a MECARD), and how to get the font size to not be a whole number (I need the font size something like 3.625).

 

I'm not sure what fields you are using, but here is an example. You can insert Fields, Rules and Static Text.

 

// vCard 3.0 format
// http://en.wikipedia.org/wiki/vCard

var info = {
   N: Field("LastName") + ';' + Field("FirstName") + ';;;',
   FN: Field("FirstName") + ' ' + Field("LastName"),
   ORG: 'Insert Company Name',
   "EMAIL;type=INTERNET;type=WORK": Field("Email"),
   "TEL;type=CELL": Field("Mobile"),
   "TEL;type=WORK": Field("DirectPhone"),
   "TEL;type=WORK;type=FAX": Field("DirectFax"),
   "ADR;type=WORK": ";;" + Field("Address1") + ';' + Field("City") + ';' + Field("State") + ';' + Field("Zip") + ';',
   "URL;type=WORK": Field("Website"),
}

var result = ["BEGIN:VCARD", "VERSION:3.0"];
for (var label in info)
{
   if (info[label])
       result.push(label + ":" + info[label]);
}
result.push("END:VCARD");

var EncodingMode = "Byte";
var ErrorCorrectionMode = "M";
var PreferredFormat = "0";
var PointSize = "[color="Red"]3.625[/color]";
var NoFontTag = false;
var Font = "IDAutomation2D";
var ProcessTilde = false;

return MakeQRBarcode(result.join(Chr(13) + Chr(10)), ProcessTilde,
         EncodingMode, ErrorCorrectionMode, PreferredFormat,
         PointSize, NoFontTag, Font);

 

I suggest taking a look at http://en.wikipedia.org/wiki/vCard

Edited by David Miller
Link to comment
Share on other sites

David,

Thanks for the help. I was able to get the correct data into the vCard from your response.

However, it seems like the PointSize variable rounds down to a whole number, so even when I put 3.625, it outputs the font size as 3.

I was able to get around this by adjusting the PreferredFormat number. By putting that at 17 instead of 0 it got the size pretty close. It seems that the PreferredFormat variable also rounds down.

It would be nice to be able to more precisely control the size, but this solutions got it to within 1/16" of the size it is supposed to be, which will work in this case.

Link to comment
Share on other sites

David,

Thanks for the help. I was able to get the correct data into the vCard from your response.

However, it seems like the PointSize variable rounds down to a whole number, so even when I put 3.625, it outputs the font size as 3.

I was able to get around this by adjusting the PreferredFormat number. By putting that at 17 instead of 0 it got the size pretty close. It seems that the PreferredFormat variable also rounds down.

It would be nice to be able to more precisely control the size, but this solutions got it to within 1/16" of the size it is supposed to be, which will work in this case.

The MakeQRBarcode function (and the QRBarcode.Make function it calls, both of which are defined in Builtins.js) does indeed truncate the point size to an integer. To get around that, you can make your own version of the function which doesn't truncate the size, like so:

function MakeQRBarcodePreciseSize(DataToEncode, ProcessTilde, EncodingMode, ErrorCorrection, PreferredFormat, PointSize, NoFontTag, Font)
{
 var encoded = EncodeQRBarcode(DataToEncode, ProcessTilde, EncodingMode, ErrorCorrection, PreferredFormat);

 var ReplacedBR = ReplaceSubstring(encoded, "\r\n", "<br>");
 var ReplacedSpaces = ReplaceSubstring(ReplacedBR, " ", "");

 if (isNaN(PointSize))
   return ReplacedSpaces;

 var WithPointSize = "<z newsize=\"" + Number(PointSize) + "\">" + "<leading newsize=\"" + Number(PointSize) * 10 + "\">" + ReplacedSpaces;
 if (NoFontTag)
   return WithPointSize;

 var WithFontTag = "<f name=\"" + Font + "\">" + WithPointSize;

 return WithFontTag;
}

You can add the above code right in your rule, or in the JavaScript Globals. (Please do not modify Builtins.js.) Then you can just call the function at the end of your rule, instead of MakeQRBarcode, like so:

return MakeQRBarcodePreciseSize(result.join(Chr(13) + Chr(10)), ProcessTilde,
         EncodingMode, ErrorCorrectionMode, PreferredFormat,
         PointSize, NoFontTag, Font);

 

I can also tell you that FusionPro 10 will allow customization of both the foreground and background colors of a graphic QR barcode.

Link to comment
Share on other sites

However, it seems like the PointSize variable rounds down to a whole number, so even when I put 3.625, it outputs the font size as 3. I was able to get around this by adjusting the PreferredFormat number. By putting that at 17 instead of 0 it got the size pretty close. It seems that the PreferredFormat variable also rounds down.

 

Sorry. I should have noticed that in validation. The integer of PointSize and PreferredFormat is being used.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...