Switch media based on page # = value in data

In my data, I have a field that tells me what page of that record needs to be printed on perforated stock. I have 2 media types defined - Plain and Perf, both are the same size. I’m having trouble figuring out how to reference what page # is going to be processed next and what script type to use to set the media to from plain to perf.

Something along the lines of
if (current output pagenumber <> value of field 29) {
results.attr(“content”,“Plain”);
} else {
results.attr(“content”,“Perf”);
}

TIA
Jim

Hello @jmdornbos,

Can you let us know please what kind of input data your are using? Is that for example a PDF document whereby each record is spread out over several pages?

In your forum post you mention the following, and I quote: “I have a field that tells me what page of that record needs to be printed on perforated stock”. Can you please explain what you mean by this? Does this mean that each record contains a record field which contains the page number of the input data which you would like to print?

My input data is a csv file that contains the variable name of a multi-page PDF associated with that record. The PDF can be 1-6 sheets, simplex or duplex. In field 29 of the csv, it also tells me which sheet of the PDF should print on perfed stock.

For example, record 1 includes marten_0123.pdf, which I pull in as a dynamic background, and field 29 tells me that sheet 3 should be on perfed stock. Record 2 includes dornbos_2345.pdf and field 29 of that record tells me to print sheet 1 on perfed stock. We’re loading the perf stock into a specific drawer on the printer and counting on the PostScript media call to pull in the right stock.

This means that each record contains at least:

  • A record field which contains the filename (like for example: “example.pdf”) or the absolute path (like for example: “C:\path\to\file\example.pdf”) of the PDF document.
  • A record field which contains the page number of the PDF document which needs to be used as a dynamic background image of a Print Context Section.

Can you please confirm if this is correct?

Yes, I have a field which contains the filename for the PDF to be used. I print all pages of the referenced PDF. I do have a field which tells my how many sheets are in the PDF, but I’m not currently using that field. I also have a field which tells me which variable page needs to print on perf stock instead of plain stock. I’m struggling with figuring out what page I’m processing so I can make the switch to perf media. I think in the script shown below merge.pagination.sheetCount is simply telling me how many sheets I have for this record, rather than telling what sheet I’m processing at this moment.

std_script_media_selection

Here are the Media and Contexts.
media_and_contexts

Thanks for your input.
Jim

Hi @jmdornbos, You would like to use the entire PDF document as a background image of your Print Context Section? If so, please note that in that case you will have to make use of the in PlanetPress Connect available clone functionality because you cannot change the Media type of a specific page of your Print Context Section.

More information about the clone functionality can be found on the following online documentation webpage: ‘Dynamically adding sections (cloning) - PlanetPress Connect 2021.2 User Guide’

So am I understanding correctly that there’s not a method to print some pages from tray 1 and print other pages from tray 2 in the same document using Connect while outputting PostScript direct to a printer? I didn’t see anything in that cloning documentation that addressed setting the media for the clone. If it’s in there, very likely it’s my newness that’s at fault.

It is possible to print some pages via tray 1 and to print other pages from tray 2 but in that case you will have to make use of the clone functionality because then you have the option to assign a specific Media to the cloned Print Section, by using a Control Script like the following one for example:

var printSections = merge.template.contexts.PRINT.sections;
var clone = printSections["Section 1"].clone();

clone.sheetConfig.positions.all.media = "Media 1";

printSections["Section 1"].addAfter(clone);

And you have in this case even the option to use a dynamic background image. By updating the previous Control Script example to something like the following for example:

var printSections = merge.template.contexts.PRINT.sections;
var clone = printSections["Section 1"].clone();

clone.sheetConfig.positions.all.media = "Media 1";

var background = clone.background;

background.source = BackgroundResource.RESOURCE_IMAGE;
background.allPages = false;
background.start = 2;
background.end = 3;
background.url = "file:///C:/path/to/file/example.pdf";

printSections["Section 1"].addAfter(clone);