How to calculate Ratio for multiple numbers in JS?

Post Reply
Zoranj
Member
Posts: 107
Joined: Tue Sep 20, 2016 7:37 pm
Location: Canada

How to calculate Ratio for multiple numbers in JS?

Post by Zoranj »

I have a need to gang impose multiple items on the sheet but no license for Sheet Optimizer.
Javascript can do it from my googling but all examples are for 2 numbers, I might have 5 or more items.
Has anyone done something similar?

Thanks
ThomasDeschamps
Member
Posts: 21
Joined: Wed Jul 20, 2016 12:03 pm

Re: How to calculate Ratio for multiple numbers in JS?

Post by ThomasDeschamps »

The item are all the same size? or do you have different item?

if it's the same item size, it's rather simple, something like this will return an object with your number of column and row.
You can also add a function to test with a rotation, if the grain direction is not a problem.

Code: Select all

function calculateImposition(sheetWidth, fileWidth, sheetHeight, fileHeight) {
	return {
		column : Math.floor(sheetWidth / fileWidth ),
		row : Math.floor(sheetHeight / fileHeight ),
	};
}
If different item size, it's a lot more difficult task (are they all square? do you need to follow specific rule like grain direction? is it possible to rotate PDF? etc etc..)
Zoranj
Member
Posts: 107
Joined: Tue Sep 20, 2016 7:37 pm
Location: Canada

Re: How to calculate Ratio for multiple numbers in JS?

Post by Zoranj »

Thanks Thomas for reply.

Yes, to make it easier they are same size, however it is the ratio that is the problem.
Even with same size, there are multiple different items with different quantities so e.g.:
Item a is 1000
item b is 2000
item c is 3000
item d is 3000
so on 16up sheet I need to impose 2up of a, 4up of b, 5 up of c and 5up of d.

I can do this manually, as in I made excel calculator for ratio, but I wanted to automate it.
There could be different number of times and different quantities all the time.
jan_suhr
Advanced member
Posts: 586
Joined: Fri Nov 04, 2011 1:12 pm
Location: Nyköping, Sweden

Re: How to calculate Ratio for multiple numbers in JS?

Post by jan_suhr »

If all jobs are the same you can use an App for that to combine the files into a factor of the number of prints for each job.
The App in question is Duplicate Pages PRO.

In the example below, the green and magenta jobs are 300 and the yellow is 200 and you print 100 sheets.
In the flow you upload the jobfiles through a submit point, you set the factor, a job indentifyer (to assemble the jobs to one sheet) and how many jobs on one sheet.
Screenshot 2020-07-09 15.04.02.png
Screenshot 2020-07-09 15.04.02.png (54.41 KiB) Viewed 7961 times
Screenshot 2020-07-09 15.07.54 copy.jpg
Screenshot 2020-07-09 15.07.54 copy.jpg (86.01 KiB) Viewed 7961 times
Jan Suhr
Color Consult AB
Sweden
=============
Check out my apps
ThomasDeschamps
Member
Posts: 21
Joined: Wed Jul 20, 2016 12:03 pm

Re: How to calculate Ratio for multiple numbers in JS?

Post by ThomasDeschamps »

Zoranj wrote: Thu Jul 09, 2020 2:29 pm Even with same size, there are multiple different items with different quantities so e.g.:
Item a is 1000
item b is 2000
item c is 3000
item d is 3000
so on 16up sheet I need to impose 2up of a, 4up of b, 5 up of c and 5up of d.

With this exemple, you don't get 3000 ex of C and D, but 2500?
Zoranj
Member
Posts: 107
Joined: Tue Sep 20, 2016 7:37 pm
Location: Canada

Re: How to calculate Ratio for multiple numbers in JS?

Post by Zoranj »

Thanks Jan, I will take a look at the app.
Thomas, you are correct that it is 2500, I just pulled numbers out of blue, maybe not best example but in such case you would print 600 sheets to get 3000 for C and D, while having waste on a and b items.

Proper imposition software calculates ratios much better and some even give you option to use more sheets or less plates, which produces more or less waste, etc...
I used Signa sheet optimizer for this specific task and it is quite powerful, another software that comes to mind is Phoenix and Ultimate from what I read online.
jan_suhr
Advanced member
Posts: 586
Joined: Fri Nov 04, 2011 1:12 pm
Location: Nyköping, Sweden

Re: How to calculate Ratio for multiple numbers in JS?

Post by jan_suhr »

Jan Suhr
Color Consult AB
Sweden
=============
Check out my apps
Post Reply