PDF printing in java - java

is there a way to print pdf files from a java webapplication on the local printer of the end user (connected via vpn)?
The simple lookup of a printer via Java Printing Service always returns printer which are not able to print pdfs. Are there other libs which can be used for printing in java?
By the way, just opening the pdf in the browser is not an option, though it must be possible to run scheduled batch printing without user interaction.
Thanks in advance

Since the Java web application can't connect to the client (the client connects to it), there is no way to do this.
The only solution is to send the PDF file to the client via a download link or similar, so that the browser on the client can offer the user to save or print it.

I currently have the same problem - having to find a way to print PDF and Word documents.
And the short answer is:
It's not as easy as you'd want it to be.
The problem is that "someone" has to do the interpretation of your document. And that someone is either the printer or you.
Not all printers support DocFlavor.x.PDF. We have four printers at my company (one was bought just last month) and none of them does.
If you find a printer that does accept that DocFlavor you're done.
But since chances are the printer doesn't know what to do with a PDF file, you have to render the document yourself. I can recommend trying PDFRenderer and PDFBox. For me PDFRenderer works great and PDFBox doesn't print text correctly, but other people report the opposite. So, you will have to try for yourself.
All that still doesn't help me with Word docs, but that's not your concern.

Related

Corrupted .rtf file with embeded fonts

I’m working on a program written in Java that uses LibreOffice to convert documents to .pdf format. Clients on their side use Microsoft Word.
The functionality of the program is such that through the program interface, clients upload documents to their server. It turns out that at first, the program reads the format and content of the document, then saves the content in .pdf and saves this document on the server.
I ran into a problem when working with a .rtf document that has the embed fonts option enabled. The problem is that when working with a document in Microsoft Word, everything works well. But if this document is opened in LibreOffice Writer (it doesn’t matter the version, I tried from 6.0.0.1 to 7.3.1), then the document is damaged, even if these are done manually, for example, on the Desktop in Windows. That is, the table inside the document is not displayed correctly. If I open it again in Microsoft Word, the document remains “damaged”. But if BEFORE these manipulations in Microsoft Word turn off the embed fonts option and then open it in LibreOffice or upload it to the server through my program, then everything will work fine. This error occurs both when working through the code and if this is done manually.
I think that the problem is related to this topic for the .doc and .docx format, but here I solved everything by switching from Windows Server 2016 to Windows Server 2019, but even on Windows Server 2019, the problem with .rtf remains. The same problem exists in Windows 10.
Can you tell me how to fix the problem so that the embed fonts function remains active? Because I can’t tell clients not to use embed fonts.
Thanks!
P.S.
Sorry, I can’t provide the actual file. It contains very important customer information. When editing or replacing text and after saving, the file is also saved damaged for the Word program. Therefore, I will leave a link to the image of the “normal” file and the damaged one, to make it clear what “corrupted” is.

Printing RTF/HTML Files with Node.js

I have the following problem:
I've created an electron app which prints out receipt with a thermal printer, however, the print quality really seems to suffer when using any other formats that .txt, .rtf or .html.
The module I've been using so far is node-native-printer and although html is listed as a supported file type, it only prints out the unrendered html text.
I've also tried JTextComponent but I could not get it to work with RTF or HTML.
I am not familiar with C# so I do not know how I could play around with node-native-printer's .cs files to get it to work.
Also ideally there should not be any dialog popping up when printing and most importantly no extra user input required.
I'd appreciate any help!

Create a "print-only" PDF with itext

This question is related to another one I've posted recently: Check printing with Java/JSP
We're looking for alternatives to how we currently print checks in a Java web application via an applet. It seems the consensus is to use PDF for printing and that itext offers the ability to do so with Java.
However, it's important in our particular case that the checks are "print-only" - the user should not have any ability in the application to save the check (I know a savvy user could do a PrintScreen but we want to cover our rears and make no native functionality in the app to save checks).
I haven't been successful in browsing the web to find out if it's possible to create a PDF with itext in this manner. I have seen posts on restricting permissions in a PDF but what I'm really looking for is a way to disable the ability to save a PDF locally using itext.
Does this functionality exist? If so, could you point me to documentation/code samples on it?
I'm presuming that you're serving this PDF and wishing to print it from within a web application / web site where no out of the ordinary client side plug-ins are installed.
If printing the PDF using conventional means (e.g. Adobe Reader), the PDF MUST be downloaded to the browser's cache to be opened and printed. There is no way around that.
Now you can probably prevent the average Joe from saving the PDF locally via the following technique, but any savvy user will be able to inspect your HTML's source and download the PDF directly.
Output your PDF in iText such that when the PDF is opened, a print action automatically occurs
Put an invisible IFRAME on your HTML page which loads this PDF, but is not visible in the browser to your user
When the user loads your HTML page, the PDF will be loaded in the IFRAME and sent to the users printer (presuming that Adobe Reader is installed in the browser). Yes, the PDF will end up in the browser cache, but the user would have to be savvy enough to both recognize this and then hunt it down in their browser's cache.
If this is not acceptable, you're going to have to look at converting the PDF to another file type (e.g. pages are rendered to images displayed in the browser or perhaps a Flash / Java object that sends each page in the document to the printer directly)
The printWriter class gives some static variables for certain options: PrintWriter
And here is another SO post that might help: iText disable printing/Copying/Saving

Java document printing in Windows

I am doing a project which will finally print a pdf file or doc file to the printer as "another user". But now I stuck on how to print document in Java.
I know there is a pdf renderer in java, developed by sun, which can convert pdf to pcl file.
After the conversion, I want to print the pcl file to remote printers.
My previous way is "copy /b filename \printserver\printer", however, this approach actually is too lowlevel and cannot even display the document name, and sometime is not working.
I wonder is there a better approach of java to send the PCL file to print server, where the server can actually detect the document name and host name(which I want to specify in the program, not the original one). This one is really driving me crazy...Thanks!
Have you looked into java print service?
You can find some useful code here
http://docs.oracle.com/javase/1.4.2/docs/guide/jps/spec/printing.fm2.html

Need to either convert RAW print data to ps/pdf or print it from Java

Our application is a client/server setup, where the client is a standalone Java application that always runs in Windows, and the server is written in C and can run on either a Windows or a Unix machine. Additionally, we use Perl for doing various reports. Generally, the way the reports work is that we generate either a text file or an xml file on the server in Perl and then send that to the client. The client then uses FOP or similar to convert the xml into a pdf. In either the case of the text file or the eventual pdf, the user select a printer via the java client and then the copied over file prints to the selected printer.
One of our "reports" is used for creating barcodes. This one is different in that it uses Perl to fetch/format some data from the database and then sends that to a C application that creates some Raw print data. This data is then sent directly to the printer (via a simple pipe in Unix or a custom application in Windows.
The problem is that this in no way respects the printer selected by the user in the Java client. Also, we are unable to show a preview in said client. Ideally, I'd like to be able convert the raw print data into a ps/pdf or similar on the server (or even on the client) and then send THAT to the printer from the client. This would allow me to show a preview as well as actually print to the selected printer.
If I can't generate a preview, even just copying over the raw data in a file to the Java client and then sending that to the printer would probably be "good enough." I've been unable to find anything that is quite what I'm trying to accomplish so any help would of course be appreciated.
Edit: The RAW data is in PCL format. I managed to reconcile the source with a PCL language reference guide.
Have you had a look at iText?
You willl need to find some way of interpreting the RAW format, which most likely is some printer language like PCL or HPGL into a format you can use. This is probably best done at serverside.
A java based PCL interpreter can be found at http://openpcl.sourceforge.net/ - I have no experience with it.
I figured out a way to generate the barcodes using XSL-FO directly. This is the "correct" answer based on our architecture and trying to do anything else would have been just a dirty hack.

Categories

Resources