HP Direct PDF printing is a great cross platform driverless printing mechanism which I have used for a number of customers with great results.
A common problem with Direct PDF printing is that it is not possible to include any printer control commands such as tray calls within the PDF and lots of people have been asking how to do this – I checked with HP Technical support and was told it is not possible.
It is possible however to setup a print job with PJL commands and include the PDF documents within that job. The key being to set the printer language/personality to PDF and then using the UEL (Universal Exit Language) command to issue more control commands. After a bit of trial and error I found that this is actually quite straightforward, and thought I would post the code as I was not able to find any working examples:
ESC%-12345X@PJL
@PJL JOB NAME = "paultest2.pdf" DISPLAY = "Printing & Stapling paultest2.pdf"
@PJL SET OUTBIN=OPTIONALOUTBIN1
@PJL SET PROCESSINGTYPE="STAPLING"
@PJL SET PROCESSINGOPTION="LEFT_1PT_ANGLED"
@PJL SET MEDIASOURCE = TRAY3
@PJL ENTER LANGUAGE = PDF
After setting up the job with the above, you can then add the PDF code. After the PDF you either need to end the job or specify more further printing control. In my example I am printing another PDF document right away within the same job but from a different tray, like so:
ESC%-12345X@PJL
@PJL SET MEDIASOURCE = TRAY4
@PJL ENTER LANGUAGE = PDF
Then follow this with more PDF data and then end the job like this:
ESC%-12345X@PJL
@PJL RESET
@PJL EOJ NAME = "paultest2.pdf"
ESC%-12345X
In this example the two PDFs are also being stapled together and the status display on the printer is also updated to show what document is being printed.
All of the above was tested using a HP Laserjet P4015N with a 500-Sheet Stapler/Stacker(CB522A). Although it contains no references to PDF printing, the best reference I have found is this document from HP:
http://h20000.www2.hp.com/bc/docs/support/SupportManual/bpl13208/bpl13208.pdf
In production I am doing all of the PJL wrapping via a korn shell script which I’ve tested from IBM AIX, Ubuntu and Sco Openserver 5.0.7.
Steve says
Can you explain how you spool the files, do you monitor a folder? Also do you look at the size of the pdf to decide which tray it should go to via your ksh script?
Paulie says
The original text files to be printed are created in general by legacy applications which typically pipe output to a print queue.
We use a shell script in place of a print queue and consume stdin.
We then grep for certain text within the text of the document to figure out which formatting and tray control to apply and then forward the result to the appropriate printer/e-mail.
Roman says
hi there!
Nice Post indeed!
Can you give me a hint on how to get at the pdf “code” of a certain – existing – pdf file?
this would solve a problem i’m working in my freetime since… well ever…
Thanks!
Roman
Paulie says
I’m not exactly sure what you are trying to ask. Can you clarify?
Roman says
sorry…
well, our company is generating PCL files at the moment.
Within PCL I can easily integrate PJL Commands for e.g. outbin, copies etc.
Those pcl files can be converted to PDF.
A new function in our software makes it possible to print PDF Files directly so we don’t need to “copy” the pcl file to the printer-device anymore.
this has the consequence, that functionality like Tray-selection and tray-switching for the 2nd… page wont work anymore.
Now i try to find a way, to use the following:
1) Start the Print job by nitialisation of PJL Commands for Tray-Selection and e.g. Quantity.
2) “send the existing pdf file to the Job”
3) finish the Print job.
The result should send the PDF to the printer and use the sent pjl sequences.
I’m not sure if this is possible anyhow, but would be VERY usefull.
Thanks for your help Paulie
Paulie says
The code above will do exactly what you need and it is exactly what we are doing. Generating a PDF file first and then encapsulating it within the above code.
We write the code above to a file, and the add the original PDF after the “@PJL ENTER LANGUAGE = PDF” line. After you have added the original PDF code you switch back to the “ESC%-12345X@PJL” to finish the job off.
What Operating system are you using? I am simply using the cat command within a shell script to build up the file and it works beautifully every time.
Roman says
Hey Pauly
that means i simply can open the pdf in a text editor and copy the embeded code into my pcl file?
or does it have to be another format…?
Hemin says
Hi,
I am trying something on similar lines. I am actually trying to embed PJL commands inside a PDF.
By doing this, what extension do I give to the filename? When I give .pdf, the PDF ignores the PJL commands above and just renders the PDF file.
Can you tell me how to embed PJL commands inside a PDF document?
Paulie says
I don’t think that would be possible. What are you actually trying to make the printer do?
Hemin says
I am trying to execute PJL commands through a PDF. Like changing the front panel display, printing test page, etc. Of course I can do this directly from the panel, but I want this to be done via a document. I hope I am clear
Paulie says
You do it exactly as I have done it above and I am doing similar things to you.
You just wrap the commands around the PDF file and send the whole thing as one document.
What system/OS are you using?
Hemin says
I am using Windows 7 to print the document. I tried doing the above thing but I dont know how should I send it to the printer. I edit the pdf file in a hex editor and then when I open it and print it, the PJL doesnt get transferred to the printer.
I am using HP 2055dn Printer. Is it that the printer driver doesnt support the direct printing?
How do you print the document? Which printer driver do you use?
Thanks!
Bryan K. Carter says
Hello Everyone,
Nice post, Paulie.
HP Direct PDF printing is from HP’s Boise, Idaho, division.
The URL to the patent is (lengthy…sorry)
http://patft.uspto.gov/netacgi/nph-Parser?Sect1=PTO2&Sect2=HITOFF&p=1&u=%2Fnetahtml%2FPTO%2Fsearch-bool.html&r=1&f=G&l=50&co1=AND&d=PTXT&s1=7,072,055.PN.&OS=PN/7,072,055&RS=PN/7,072,055
I am the primary inventor, “Carter, Bryan K.”, of the patent. Funny thing is, I was merely writing tests for printer formatter board testing. I showed some test results to another engineer and he’s all “Hey, write up an [internal HP] Invention Disclosure (I.D.) and get a few bucks!” So, wrote the I.D. and got a few bucks; used it for a nice dinner with my wife. I found out years later it became a patent.
The above URL disappointingly munges the PJL code section, thus I reproduced it below.
The objective is to wrap your PJL around the PDF data file then send the resulting text (PJL + PDF data) to the printer.
Candidly, I don’t know if all LaserJets since the 2000 era can print direct pdf print; haven’t been with HP since 2002. I do know that the LJ needs PostScript.
I may be back within a week or so to post an example for use within the .NET framework v3.5 or higher using C# and for Windows XP/Vista/7.
Enjoy,
Bryan Carter
*************************
In all examples below [[PDF DATA]] is a holder for the actual PDF data file content and “” is the actual ESC character ((esc) = decimal: 27; Oct:0033; Hex: 0x1b).
TABLE-US-00001 Example PJL commands
==============================
Two-sided printing
%-12345X@PJL
@PJL JOB NAME = “MyPDF.pdf” DISPLAY = “Printing MyPDF.pdf”
@PJL COMMENT Set PS for PDF printing
@PJL SET PERSONALITY = POSTSCRIPT
@PJL COMMENT Set Duplex for PDF job.
@PJL SET DUPLEX = ON
@PJL ENTER LANGUAGE = PDF
[[PDF DATA]]
%-12345
@PJL
@PJL COMMENT reset to control panel settings
@PJL RESET
@PJL EOJ NAME = “MyPDF.pdf”
%-12345X
Number of copies
%-12345X@PJL
@PJL JOB NAME = “MyPDF.pdf” DISPLAY = “Printing MyPDF.pdf”
@PJL COMMENT Set PS for PDF printing
@PJL SET PERSONALITY = POSTSCRIPT
@PJL COMMENT Set Number of uncollected copies for PDF job.
@PJL SET COPIES = 1 999
@PJL ENTER LANGUAGE = PDF
[[PDF DATA]]
%-12345@PJL
@PJL COMMENT reset to control panel settings
@PJL RESET
@PJL EOJ NAME = “MyPDF.pdf”
%-12345X
Output destination
%-12345X@PJL
@PJL JOB NAME = “MyPDF.pdf” DISPLAY = “Printing MyPDF.pdf”
@PJL COMMENT Set PS for PDF printing
@PJL SET PERSONALITY = POSTSCRIPT
@PJL COMMENT Set Destination for PDF job.
@PJL SET OUTBIN =
@PJL ENTER LANGUAGE = PDF
[[PDF DATA]]
%-12345@PJL
@PJL COMMENT reset to control panel settings
@PJL RESET
@PJL EOJ NAME = “MyPDF.pdf”
%-12345X
Finish staple
%-12345X@PJL
@PJL JOB NAME = “MyPDF.pdf” DISPLAY = “Printing MyPDF.pdf”
@PJL COMMENT Set PS for PDF printing
@PJL SET PERSONALITY = POSTSCRIPT
@PJL COMMENT Set send to staple bin for PDF job
@PJL SET FINISH = STAPLE
@PJL ENTER LANGUAGE = PDF
[[PDF DATA]]
%-12345@PJL
@PJL COMMENT reset to control panel settings
@PJL RESET
@PJL EOJ NAME = “MyPDF.pdf”
%-12345X
Finish collate
%-12345X@PJL
@PJL JOB NAME = “MyPDF.pdf” DISPLAY = “Printing MyPDF.pdf”
@PJL COMMENT Set PS for PDF printing
@PJL SET PERSONALITY = POSTSCRIPT
@PJL COMMENT Set mopy count for PDF job
@PJL SET QTY = x
@PJL ENTER LANGUAGE = PDF
[[PDF DATA]]
%-12345@PJL
@PJL COMMENT reset to control panel settings
@PJL RESET
@PJL EOJ NAME = “MyPDF.pdf”
%-12345X
Paulie says
Hello Bryan,
Thank you for posting that information, it will come in very handy. I have a customer that we use HP Direct PDF printing for extensively and it has been quite revolutionary for them and I have been able to apply the same techniques used for them for other customers. Driverless printing makes so much sense in so many scenarios.
It is an honour to have your input here and very interesting to hear the story of how it came into being. You must have a very innovative streak.
Look forward to seeing what you come up with, if you like, we can make a dedicated post to your input.
Thanks once again for the information, most useful.
Paulie
Angelo Trozzo says
Hi Guys really interesting , but every time I tried all your easy examples , does not work. These are the steps I did :
Open the PDF file with a text editor , add on the top
%-12345X@PJL
@PJL JOB NAME = “MyPDF.pdf” DISPLAY = “Printing MyPDF.pdf”
@PJL COMMENT Set PS for PDF printing
@PJL SET PERSONALITY = POSTSCRIPT
@PJL COMMENT Set send to staple bin for PDF job
@PJL SET FINISH = STAPLE
@PJL ENTER LANGUAGE = PDF
Then all the PDF data structure from
%PDF-1.4 …. to
%%EOF
Then I added
%-12345@PJL
@PJL COMMENT reset to control panel settings
@PJL RESET
@PJL EOJ NAME = “MyPDF.pdf”
%-12345X
I saved the file and opened again in PDF format and print . The PJL command is simply ignored. Can someone tell what noob Am I and what I do wrong please ??
Thanks .
Alex G says
Hi guys .. tried lots of examples over the past few days but with no success …
My printer is 9000 series and I’m running w7 .
Although I embedded the code posted here into the pdf file .. I had no luck.
Anyone had success with w7 ?
Derek P says
For those trying to do this in Windows, don’t open the final file as a PDF, just copy it to the printer port.
ie: copy c:\test.pdf lpt1:
Jos Bormans says
I’m trying to do the same on a HP9050dn laserprinter (Q3723A). PDF printing works but only from tray1 (manual paper input). I’m not able to select another tray with the PJL command:
@PJL SET MEDIASOURCE = TRAY3
According to the ‘printer job language technical reference addendum’ the HP9000 series don’t support this command. Is there another way to use TRAY 2 or 3 as paper source for the pdf to print? Somebody any idea’s?
P De Nolf says
Not all printers with PDF Direct Print feature support the PJL mediasource instruction; e.g. Ricoh aficio printers do not.
After weeks of struggling, I finally managed to get hold of the Ricoh manuals relating to PJL instructions supported by Ricoh.
Ricoh supports the @PJL SET MEDIATYPE=SPECIAL – special is the paper as defined for a specific tray. You can assign a specific paper type for a tray, so requiring a specific paper results in using a specific tray. And provided the printer is properly configured (trays need to be set to “automatically selected”), this finally works.
The Ricoh manuals are not made available to the public. You need a to be a Ricoh developer and sign a formal developer subscription (including a non disclosure agreement!), or do the way I did and just keep begging for the documentation –
as Ricoh technical support was unable to come up with a solution for printing Pdf’s.
So are we all violating this hp’s patent now?
Chirag Bhagat says
Hi,
Very Nice post and nice work by Bryan too. I understand the PJL command language a bit now, but making it work using real C# project is still a challange.
Bryan, as you promised, I still don’t see the code example for use within the .NET using C#. I was able to display a message on the display id of the HP printer but how to print PDF file (looking for c# code) utilizing PJL commands is still not clear and doesn’t work for me.
Can someone please post a c# code to print a PDF file using PJL commands, if you have done so? I have searched online but don’t find real c# code for printing a file.
Please help!
Henk says
Direct printing PDF’s work.
However I do experiance problems when orientation of PDF does not match with paper orientaion in the tray.
Is there some auto-rotate feature?