# 2D barcode - Programming 15 digit code

## Recommended Posts

I am in need of generating a 2D barcode using 15 digits.

01 – Digit 1 and 2 – these are the sheet count of the current sheet for the record

04 – Digits 3 and 4 – this is the total sheet count for the record

Digits 5-9- we won’t use for now so they all need to be “0” (6 and 7 are the ones we can program to tell it if a certain record gets an additional insert)

Digits 10-15 we can use for the 6 digit Sequence Code

Example

030500000025066

This is sheet 3 of a 4 sheet set with Seq number of 025066

Can someone help with setting up code for this?

##### Share on other sites

What is the "6 digit Sequence Code"? And what kind of 2D barcode are you trying to make?

I think you want something like this:

```var data = FormatNumber("00", FusionPro.Composition.impositionSheetNumber) +
FormatNumber("00", FusionPro.Composition.impositionTotalSheets) + "00000" +
FormatNumber("000000", FusionPro.Composition.outputRecordNumber);
return MakeQRBarcode(data);```

##### Share on other sites

• 2 weeks later...

Thanks Dan, this is helping. We are making progress. This is what we currently have working. However, the currentPageNumber is not working how we would like. We need the code to do sheet count and not page count - for example;

Pages 1-2 = 1

Pages 3-4 = 2

Pages 4-5 = 3

etc...

Current programming:

var dataforbarcode = FormatNumber("00", FusionPro.Composition.currentPageNumber) + FormatNumber("00", FusionPro.Composition.totalPages/2) + "00000" + Field('SEQUENCE');

var dmbarcodeobj = new DataMatrixBarcode;

dmbarcodeobj.encodingmode = "C40";

dmbarcodeobj.pointSize = 6;

return dmbarcodeobj.Make(dataforbarcode);

##### Share on other sites

, the currentPageNumber is not working how we would like. We need the code to do sheet count and not page count

Did you try using FusionPro.Composition.impositionSheetNumber and FusionPro.Composition.impositionTotalSheets, as in my example?

##### Share on other sites

Yes - we did use FusionPro.Composition.impositionSheetNumber and FusionPro.Composition.impositionTotalSheets but it was generating no results. We are thinking this may be due to there is no imposition? So we did attach an imposition and the TotalSheets became a "1" for all pages and no result for SheetNumber. Any ideas??
##### Share on other sites

Yes - we did use FusionPro.Composition.impositionSheetNumber and FusionPro.Composition.impositionTotalSheets but it was generating no results. We are thinking this may be due to there is no imposition?

Well, yeah. Maybe I'm missing something, in which case I apologize, but that question makes no sense to me. If you're not using imposition, then what does a "sheet" even mean?

You have imposed sheets if you're using imposition. If you're not imposing, you only have 1-up output pages, in which case "sheets" are really just pages, and "sheet" numbers are really just page numbers (unless you're intending to print duplexed, but the output PDF itself has no inherent concept of that).

You may be starting to get an idea of why it's hard to answer questions like this without seeing the job files. I can only guess at the larger context of what you're trying to do.

So we did attach an imposition and the TotalSheets became a "1" for all pages and no result for SheetNumber. Any ideas??

Without seeing the job files? No. At the very least, I would need to see the FPI file to know what kind of imposition you're doing. But I may need to see the whole job to really understand what you're asking.

##### Share on other sites

Hi Dan

We tried it again using your rule and have noticed that when processing records that are each 10 pages (5 duplex sheets printed) in length;

The impositionSheetNumber gives us "01" for the first record (all 10 sheets read the same - 01) and then "06" for the next record and "11" for the next....

The impositionTotalSheets gives us a "00" for all records and sheets.

##### Share on other sites

Hi Dan

Attached is the FPI. Thanks for the help and let me know if you need anything else.

UHC_ICP_2018_English_2018_cntl.zip

##### Share on other sites

Okay, thanks for posting the job. I think I understand now. (Though I hope what you posted is dummy data, not real people's information.)

I was confused initially by your use of the term "sheet". To me, that's indicative of multi-up imposition, like a post card job where you're imposing multiple cards on an output sheet. This isn't an imposed job like that at all, it's just a booklet. So you can ditch the FPI file. Sorry for the confusion.

I think that when you say "sheet", you really mean each pair of duplexed pages, which you do describe here:

We need the code to do sheet count and not page count - for example;

Pages 1-2 = 1

Pages 3-4 = 2

Pages 4-5 = 3

So your original rule was pretty close. I think this is what you want:

```var dataforbarcode = FormatNumber("00", Math.floor((FusionPro.Composition.currentPageNumber + 1) / 2)) +
FormatNumber("00", Math.ceil(FusionPro.Composition.totalPages / 2)) +
"00000" + Field("SEQUENCE");

var dmbarcodeobj = new DataMatrixBarcode;
dmbarcodeobj.encodingmode = "C40";
dmbarcodeobj.pointSize = 6;
return dmbarcodeobj.Make(dataforbarcode);```

This assumes that the first page is the "front" of a sheet with the second page on the back, not a "cover" page on its own sheet.

A couple of other tips: I found it much easier to analyze this by temporarily changing the rule to this:

```var dataforbarcode = FormatNumber("00", Math.floor((FusionPro.Composition.currentPageNumber + 1) / 2)) +
FormatNumber("00", Math.ceil(FusionPro.Composition.totalPages / 2)) +
"00000" + Field("SEQUENCE");

return dataforbarcode;```

And also changing each of the little text frames calling out the barcode rule to call it out in a regular font, such as Arial. (Note that you don't need to put the callout of the rule itself in the barcode font; as you can see when you validate the rule, it uses an <f name="IDAutomationDMatrix"> tag to put the data in the correct font, without having to do that manually.) Or just put that into the other frame on the page that has the "page x of y" in it. Then you don't have to keep scanning barcodes until you get the right numbers.

I'll also note that there is a lot of code in your rules that could be significantly simplified/reduced. When coding, I like to keep in mind the principle of "DRY", as in, "Don't Repeat Yourself." For instance, OnRecordStart could be reduced to this:

```var pagesToActivate = [];

var pageNames =
[
"", // index 0 (zero)
"1_HeartDisease",
"2_HeartFailure",
"3_Breathing",
"4_Kidney",
"5_Diabetes",
"6_Depression",
"7_OtherConditions",
"8_NoConditions",
"9_Pres[color="SlateGray"]c[/color]riptions",
"10_Falls",
"11_Cane",
"12_Caregiving",
"13_CareManager",
"14_Hospitalization",
"15_MemoryLoss",
"16_Medic[color="SlateGray"]a[/color]lForms",
];

for (var i = 1; i <= 16; i++) // fields "P1" through "P16"
{
var val = Int(Field("P" + i));
var pageName = pageNames[val];
if (pageName)
pagesToActivate.push(pageName);
}

var protocol = Int(Field("PROTOCOL"));

var EACClosingCodes = [101,102];
if (EACClosingCodes.indexOf(protocol) >= 0)
pagesToActivate.push("18_EAClosing Letter");

var ClosingCodes = [201,301,303,305,306,307,308,309,310,311,313,315,501,502,511,512,521,522,601,602,
701,703,704,705,706,707,710,711,712,713,714,715,716,717,718,723,724,725,726,727,728,729,730,731,732,733,734,735,736,
801,900,901,903];
if (ClosingCodes.indexOf(protocol) >= 0)
pagesToActivate.push("18_ClosingLetter");

for (var i in pagesToActivate)
FusionPro.Composition.SetBodyPageUsage(pagesToActivate[i], true);

return pagesToActivate.join("\n");
```

Not only is there a lot less duplicated code, you can also easily see what pages will be activated by simply validating the rule in the Rule Editor.

This could be reduced further. For instance, you don't really need to name all of the pages; you can just use the page numbers instead, like so:

```var pagesToActivate = [];

for (var i = 1; i <= 16; i++) // fields "P1" through "P16"
{
var val = Int(Field("P" + i));
if (val)
pagesToActivate.push(i + 1); // Cover page is page 1.
}

var protocol = Int(Field("PROTOCOL"));

var EACClosingCodes = [101,102];
if (EACClosingCodes.indexOf(protocol) >= 0)
pagesToActivate.push("18_EAClosing Letter");

var ClosingCodes = [201,301,303,305,306,307,308,309,310,311,313,315,501,502,511,512,521,522,601,602,
701,703,704,705,706,707,710,711,712,713,714,715,716,717,718,723,724,725,726,727,728,729,730,731,732,733,734,735,736,
801,900,901,903];
if (ClosingCodes.indexOf(protocol) >= 0)
pagesToActivate.push("18_ClosingLetter");

for (var i in pagesToActivate)
FusionPro.Composition.SetBodyPageUsage(pagesToActivate[i], true);

return pagesToActivate.join("\n");
```

The result is slightly more obtuse when you click Validate, but the end result from composition will be the same.

You could further simplify the second part by using range specifications (similar to the code here):

```var pagesToActivate = [];

for (var i = 1; i <= 16; i++) // fields "P1" through "P16"
{
var val = Int(Field("P" + i));
if (val)
pagesToActivate.push(i + 1); // Cover page is page 1.
}

var protocol = Int(Field("PROTOCOL"));

var EACClosingCodes = [101,102];
if (EACClosingCodes.indexOf(protocol) >= 0)
pagesToActivate.push("18_EAClosing Letter");

// enter single records separated by comma (#,) and ranges within subarrays ([#,#])
function NumberInRange(val, ranges)
{
for (var i in ranges)
if (val == ranges[i] || ((ranges[i] instanceof Array) && val >= ranges[i][0] && val <= ranges[i][1]))
return true;

return false;
}

var ClosingCodes = [ 201, 301, 303, [305, 311], 313, 315, 501, 502, 511, 512, 521, 522, 601, 602,
701, [703, 707], [710, 718], [723,736], 801, 900, 901, 903];

if (NumberInRange(protocol, ClosingCodes))
pagesToActivate.push("18_ClosingLetter");

for (var i in pagesToActivate)
FusionPro.Composition.SetBodyPageUsage(pagesToActivate[i], true);

return pagesToActivate.join("\n");
```

There may be larger ranges than what you have there, such as [701, 736], in which case that code could be reduced even more.

Finally, this whole job could be just a two-page template, where you bring in selected pages from the main brochure PDF as resources (with the multi-page resource trick), instead of as used or unused Body pages from the PDF template. Then you won't need to spend as much time copy-and-pasting all the little frames for the pages numbers and the barcodes, and, if the pages you need to insert change, you just need to change the resource PDF, and the OnRecordStart rule, . I've attached an example showing how to do this in a two-page template. Note that the code in OnRecordStart has been moved to a regular Text rule called "inserted_pages".

UHC_ICP_2018_English_2018_cntl-Dan-5.pdf

##### Share on other sites

Here's another version of the template which gets rid of most of the other repetitive rules and fixes the Intelligent Mail barcode.

UHC_ICP_2018_English_2018_cntl-Dan-6.pdf

##### Share on other sites

Hi Dan

We have been testing this today and so far it has been great. I want to thank you for your help as it is very much appreciated!

## 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.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

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

×
×

• #### FusionPro.com

• MarcomCentral
×
• Create New...