I need to implement a custom printer driver which does the following in the backgroud:
Create a PDF document of the document to print
Send the created PDF document to a predefined email address OR
call a web service and transmit the document there
The pinterdriver should be available for windows and mac osx. My prefered implementation language is Java.
Is this possible with Java?
Are there frameworks available which reduce the coding effort to a minimum?
Are you sure "driver" is really the word you are looking for here? Usually when one says a print driver they actually mean something that translates document data into commands for a printer. I think you are really looking for something of a pre-processor.
In any case, if you want it to look like a printer to the OS, it will be almost impossible to do purely in Java. Your best bet would be to create drivers for each of the platforms that use JNI(or just invoke a JVM), do your processing, then forward it on to the printer.
Although I do not know if a similar approach will work on Windows, what you want to do is almost trivial to do on OS X. Apple already provides a cups-pdf service that converts any printable document into a pdf, all you have to do is take that output, forward it to where it needs to go, then forward it to a printer, no need to do anything in Java.
For an example of how to do this, check out the following project:
https://bitbucket.org/codepoet/cups-pdf-for-mac-os-x/downloads
Windows can be configured to send printer output to a file. You can create a printer in Windows that uses a PostScript driver, and writes it to c:\myfile.txt
In Windows: Add a Printer, Select Local printer, Select Create a new port, and type the file name (Full path) you want to use. Then pick the driver you want, which your Java program will have to parse. Generic text could be useful in some cases, or Postscript if you need all that formatting, and can handle parsing it.
Unlike the "File:" option under existing ports, it will not ask the user for a filename. It will just automatically save to the specified file every time.
Your Java program can monitor this file for changes, and then process the data it receives.
Related
I have written a java application, it works perfectly, however, it requires printer drivers to be installed. From technical side, how much faster will it be sending tasks directly to a printer ( on slow pc's for example), is there any significant difference in speed or maybe some other disadvantages? Here i'm trying to understand if it is worth investing time into this task or keep the strategy with drivers. And i guess this will eliminate cases where there are no drivers available for certain printers on windows 10 for example (just in theory), wouldn't it?
How do you plan to 'send tasks directly to the printer' ? The whole point of the printer driver is that it takes drawing operations from the operating system API and converts that into 'something else' whcih the printer understands.
In general there are about 6 possibilities:
PCL - An HP Page Description Language but many printers can process it natively.
PostScript - an Adobe Page Description Language, fewer printers support it, but its still common
PDF - another different Adobe PageDescription Language with some similarity to PostScript, again fewer printer support it because of ites resource requirements.
XPS - a Microsoft Page Description Language, not widely adopted for a number of reasons.
Basic bitmap - the host operating system renders to a bitmap at the resolution of the device and sends it. Used to be relatively common on low-end printers because its cheap to implement
something else. Some manufacturers, eg Epson, have their own languages.
On a Mac, PDF is the native format, and on a Windows 8 or better PC XPS is the native format. If your printer supports those then you can send a 'task' directly to it, possibly. If your java application isn't creating the content which needs to be printed but is merely a print server or processor, then you could send the data directly to the printer, because you will be receiving it in the printer native format (eg PostScript).
But in general, you need to convert your 'task' into some other page description language that the printer can understand, and send that to the printer.
Thus its not usually possible to print to a printer if you don't have a printer driver for it, because your operating system doesn't know how to create something the printer understands.
How can I know what is the source of data in clipboard?
For example when I copy something from Firefox to clipboard I want to get that the source is Firefox.
Is there any command to do that in Linux? Or is there a way to do that in Java?
Also, is there any way to track were the user pasted the data.
I want to detect if for example the user try to copy important data from organization's system, then s/he try to paste it some where else.
Thanks in advance for any help (:
It's not a language issue, it's an API issue. In Windows, the GetClipboardOwner() API call usually indicates the application that last updated the clipboard (via a handle). It's not 100% reliable. For example, if the application has terminated, then it will be null.
This function exists in Java but seems to be even less reliable, and may be mostly unused, according to this post:
Java clipboardOwner Purpose?
I think your best solution is to use the presence/absence of various clipboard formats to look for evidence. Simple formats like TEXT won't help, but complex formats like RTF and HTML will reveal clues. On Windows, there is a format for "html fragments" called CF_HTML, which has a header that looks different from one browser to the next. I would imagine that something similar exits with Java/Linux? Looking at the docs, there's something called a DataFlavor, that seems to have a very rich set of properties such as mimetype. It's possible that you could get a "fingerprint" of FireFox by looking at the attributes of each dataflavor present when copying.
There is no way to determine the source of the data in the clipboard in Java (for Linux I'm not sure but I doubt it).
To ensure that sensible Data does not leave your application do not allow the data to be copied or keep the data in an application internal clipboard and do not forward it to the system clipboard. In Java you have the control over your data being copied to the system clipboard or not.
If you use an application internal clipboard then be aware that a user could copy the sensible data first to a target that allows copying the content to the system clipboard and then copy it further out of your application.
I am working on a web application developed in Java with struts running on Tomcat. I have a requirement in the web application as follows:
One JSP page having a list of PDF files each associated with a checkbox. The JSP page has one Button. Once the user selects the PDF documents he wants to print by selecting the associated checkboxes, user clicks on the button.
Then all the selected PDF docs should be sent to a specific local Printer( i.e. printer connected to the client machine where from user is accessing the web application). The selected PDF files should not be opened either in acrobat reader or in browser. The PDF docs should not be visible to the user while being sent to printer.
Could anyone please help me in implementing this requirement?
It is possible with Internet Explorer and ActiveX. Search about "auto print" and "silent printing" with Google. You may have to lower security settings in Internet Explorer for that.
We're using it here for some Intranets from our Customers.
For Firefox you may be able to trigger the print dialog via javascript. (http://stackoverflow.com/questions/975652/silent-print-a-embedded-pdf)
If this is the case you can disable print dialog in FF with setting print.always_print_silent=true in about:config.
Never did it on my own, so I cannot say for sure if it works like the ActiveX thing does.
For Chrome there is an issue requesting same feature like FF has. See https://code.google.com/p/chromium/issues/detail?id=31395.
You will most likely have to use a Java Applet for this. The browser have no inherent capability to print a pdf document. You may be able to access the "standard" adobe plugin, but to my knowledge it is not exposed to the standard scripting environment.
You can look here: Can a Java Applet use the printer?
Note: it is recommended to have the applet signed to prevent security restrictions and/or annoying questions to the user to allow access to printer.
You'll also need some form of PDF renderer in your applet (to render to printer). Something like http://java.net/projects/pdf-renderer/, read more here: http://juixe.com/techknow/index.php/2008/01/17/print-a-pdf-document-in-java/
That is not possible with JavaScript. It is possible with either Flash or a Java applet. In either case, you will need to be able to use both the Printer drivers and a custom PDF reading toolkit. There are adequate plugins for both for PDF reading, and both come with a printing API.
If I may say so, this is a bad requirement -- it is not good to force a user to print a document without reading it -- and should be re-negotiated, especially since it is trivially simple to have those documents print to PDF anyway.
I have a generated post script file and want to print using it. How can it be achieved in java either using javax print API or AWT. Is it possible?
Complicated. Does your printer(s) support PostScript? Is it networked? If so, most networked printers can talk LPR and you can shove the file over as-is. On Windows, you could also stream the file as-is to the lpt1: mapped port via something like NET USE LPT1: \\[Computer Name]\Printer /PERSISTENT:YES.
If you're on a server and you do lots of PostScript handling and your printer infrastructure supports it, I would very much look into the LPR protocol. I've written several LPR/LPD management functions in Java to handle printer jobs, so definetely know it can be done with some relative ease.
http://tools.ietf.org/pdf/rfc1179.pdf
Have done some research into this topic, but found no relevant answers. What I need is to print a number of PDF files on one of three forms, which are loaded into different trays of a particular printer. I need to specify which printer to use and it's not the default printer. Additionally, I need to specify which tray to use based upon an attribute of each PDF file and be able to switch between them at run time. Java PrintService seems to only be interested in the local default printer. I'd appreciate any suggestions on how to accomplish this task. Thanks.
The Printer API does allow for talking to different printers other than the default. That being said it is limited. What we did in our shop is to write a JNI layer that talks directly to the Print Queue of Windows and we use that. If you want finer control than the PrintService API provides you will need to write a JNI layer and access that from Java.
You could configure a different printer for each tray in your OS, Then print to that printer depending on the properties of your file.
Thanks for all the suggestions, but I think I have worked this out now. I'm using LPR for the printing and org.apache.commons.net.ftp.FTPClient for the tray switching commands. The actual tray commands are in text files. My tests (so far) have been successful and I did not have to install the printer on my workstation.