Assemble Jobs Based on Total Page Count

Post Reply
ckuhlmannHP
Newbie
Posts: 14
Joined: Tue Jan 09, 2018 9:19 pm

Assemble Jobs Based on Total Page Count

Post by ckuhlmannHP »

Hello,

Currently, I have a flow that takes incoming pdfs, waits until there are 60 jobs. Once it hits 60 jobs, it merges and sends to press.

But I would prefer to take it a step further. I would prefer to do it based on the incoming pdf page counts. When the total number of pages across all the waiting jobs hits 600 pages. Merge and send to the press.

Is this something can be achieved? Any ideas? I do have a scripting module, I am just a bit rusty.

Thanks
cstevens
Member
Posts: 103
Joined: Tue Feb 12, 2013 8:42 pm

Re: Assemble Jobs Based on Total Page Count

Post by cstevens »

There's probably a more elegant way to handle this with the rename element and the assemble job element using the Stats.NumberOfPages variable, but I can't figure it out.

In scripting you could do something like this:

Code: Select all

//set some scope that makes sense for your application
var scope = s.getElementUniqueID();	
//Get the page count of the incoming job
var pageCount = job.getVariableAsNumber("[Stats.NumberOfPages]", s);
s.log(1, " Number of pages in this job is: " + pageCount);
//Get the total current page count from global data
var totalPages = Number(s.getGlobalData(scope, "pageCount"));
totalPages = totalPages + pageCount;

//update the global data with the new changes
s.lockGlobalData(scope);
s.setGlobalData(scope, "pageCount", totalPages.toString(), true);
s.unlockGlobalData();

//check to see if you've crossed your page threshold (set in a script property named pageLimit)
if (totalPages > s.getPropertyValue("pageLimit")){
   //move your files and reset global variables 
}
There's a few ways you can handle storing the files until your threshold was met. You can move them to a temporary folder and them move that temporary folder to the output connection as an "assembled" job, or you could possibly play with the job states / file name patterns / private job data to assemble them downstream. Depends if you need to preserve upstream job metadata or not on how you would handle that.
ckuhlmannHP
Newbie
Posts: 14
Joined: Tue Jan 09, 2018 9:19 pm

Re: Assemble Jobs Based on Total Page Count

Post by ckuhlmannHP »

Thanks cstevens,

You don't happen to have any code snippets for grouping the files and pushing them forward do you? I did something like this years ago but can not locate my script.

Always can count on you for pointing me in the right direction.

Thanks
jan_suhr
Advanced member
Posts: 586
Joined: Fri Nov 04, 2011 1:12 pm
Location: Nyköping, Sweden

Re: Assemble Jobs Based on Total Page Count

Post by jan_suhr »

One thing you can do with a script is to have pdftk to merge two files and the result is placed in a temp folder.

The script monitors a certain folder and when it has two files it merges to the temp folder. When a new file enters the monitored folder pdftk merges that one to the file in the temp folder. And so it loops on

You also have a page counter that outputs the file when it has reached the number of pages you desire.
Jan Suhr
Color Consult AB
Sweden
=============
Check out my apps
freddyp
Advanced member
Posts: 1008
Joined: Thu Feb 09, 2012 3:53 pm

Re: Assemble Jobs Based on Total Page Count

Post by freddyp »

Do you want the waiting files to continue when there are at least 600? Or do you want to let 600 pages go through and let the other wait until there is again a batch of 600?

More concretely, suppose you receive a PDF of 200 pages, a PDF of 300 pages and then one of 800 pages. What has to happen? The 1,200 pages are sent? Or the 200 + 300 + the first 100 of the 800 pages are sent, the next 600 of the remaining 700 are sent and the final 100 keep waiting until there is another 500 pages that arrive?
ckuhlmannHP
Newbie
Posts: 14
Joined: Tue Jan 09, 2018 9:19 pm

Re: Assemble Jobs Based on Total Page Count

Post by ckuhlmannHP »

Thanks guys for the information.

PDFtk is an interesting approach.

I would rather have fewer pages than more. So if page count of the input file is greater then cutoff then send through, else if page count of input + total is greater the cutoff, send current group of files through and start a new group with input file.

With scripting, what I need to better understand is moving files to a temple location, then grouping them in a folder and sending a through as a new job. I could not find any examples in the forums of this.

Thanks
Post Reply