Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print multipage PDF on different printer-trays

I am generating a PDF by PHP with FPDF. This works well.

Now what I want:
From a multipage PDF all pages expect the last one have to print with paper from tray1 and the last page from tray2.

Now the Question:
How is this possible? Is this a Acrobat Reader issue? Can it be done with JavaScript in PDF?

like image 759
scube Avatar asked Aug 16 '11 15:08

scube


People also ask

How do I print the first page of a different tray?

In the Page Setup window click on the Paper tab. Select the intended tray for the first page and remaining pages. Make sure that the same tray is selected in the Driver Properties. The job will now print to the intended tray.


2 Answers

It is not possible, as PDFs do not contain any information on the printer trays or other information. It is actually set in the printer instructions through the client's printer driver, who has to provide this information to the client program. If you need this functionality for batch processing, you'd have to leave PHP and get on the client side, e.g. through the Acrobat SDK, in which you can give this information, e.g. on a PostScript printer via the SetPageDevice-function

like image 189
Lars Avatar answered Sep 21 '22 16:09

Lars


I use CUPS on an intranet website. I don't specify a tray and my code is ruby, but the principle definitely works.

Here's my code, see if you can adapt it for your scenario

def print(path)
  raise ArgumentError, "'#{path}' does not exist" unless File.file?(path)

  `lp -s -d printer_name -h 127.0.0.1 -o page-ranges=1-4 -o media=A4,Upper #{path}`

  $?.to_i == 0 ? true : false
end

The basic idea is to generate the PDF, save it to disk then call this method to shell out to CUPS. You might need to play with the media option to get it doing what you need. 'Upper' is the tray you're targeting.

Make sure path is sanitised before being passed to this method or you risk opening a security hole.

like image 22
James Healy Avatar answered Sep 19 '22 16:09

James Healy