Print a multi-page PDF file on different printer trays

I am creating a PDF using PHP using FPDF. It works well.

Now what I want:
From multi-page PDF pages, all pages expect the latter to print with paper from tray 1 and the last page from tray2.

Now the question is:
How is this possible? Is this an Acrobat Reader issue? Can this be done using JavaScript in PDF format?

+6
source share
4 answers

This is not possible because the PDF files do not contain any printer tray information or other information. It is actually set in the printer instructions through the client printer driver, which should provide this information to the client program. If you need this functionality for batch processing, you will have to leave PHP and go to the client side, for example. through the Acrobat SDK in which you can provide this information, for example. on a PostScript printer using the SetPageDevice function

+5
source

I use CUPS on an intranet website. I do not specify the tray, and my code is ruby, but the principle definitely works.

Here is 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 main idea is to generate a PDF file, save it to disk, and then call this method for output to CUPS. You may need to play with the media to get it to do what you need. Upper - targeting the tray.

Make sure that the path has passed the cleaning procedure before passing this method, or you risk opening a hole for safety.

+3
source

PHP can send some things to a print server, such as CUPS, but it cannot force something to print on the client machine, storing through JavaScript. JavaScript does not have the ability to control individual printer settings when called from a browser. Although there are bindings for embedded PDF in JS, there is no guarantee that the user will not just open the file in a standalone PDF reader (my computer is set up this way at home).

+1
source

For future readers of this post, if the commercial library is an acceptable choice, you can do this using Amyuni PDF Creator ActiveX (Delphi, C ++, VB, PHP) or Amyuni PDF Creator. Net (C #, VB.net, etc.) by Changing the "PaperBin" property of the object.

Possible values โ€‹โ€‹of this property can be found in the documentation for the DEVMODE structure on MSDN , examples: DMBIN_UPPER - 0x0001, DMBIN_LOWER - 0x0002, DMBIN_AUTO - 0x0007.

The code in C # will look like this:

 Amyuni.PDFCreator.IacDocument pdfDoc = new Amyuni.PDFCreator.IacDocument(); using(FileStream fs = File.Open("MyDocument.pdf", FileMode.Open)) { pdfDoc.Open(fs, ""); } const int DMBIN_MANUAL = 4; for( int pageNumber = 1; i <= pdfDoc.PageCount; i++) { pdfDoc.GetPage(pageNumber).AttributeByName("PaperBin").Value = DMBIN_MANUAL; } pdfDoc.Print("My Laser Printer", False); 

For PHP, you will need to use the ActiveX version and create the document using the ProgID of the ActiveX control:

 $pdfdoc = new COM("PDFCreactiveX.PDFCreactiveX"); 

Please note that this approach applies to printing on a specific tray using the library, as mentioned in other answers, it is not possible to save this information in the PDF file itself so that it can be used by other applications.

Disclaimer: I currently work at Amyuni Technologies.

+1
source

Source: https://habr.com/ru/post/895166/


All Articles