I'm trying to print some PDFs using Java and I've found a few examples on how to do it. Seems pretty straight forward, but I've been running into problems the whole way.
I first tried PDFBox and it prints, but it doesn't print the document how it should look. A lot of the text gets garbled for some reason. So then I tried using the included Java packages this way and with an example from Oracle but nothing happens. I run the program, I check the print queue in the OS and the job is there, but the printer does nothing. My program exits gracefully with no errors and the print job goes away after a little while but there's still no action from the printer itself.
As an alternative, I've also tried running Adobe Acrobat from within my program but there are no command line arguments to enable duplexing which I need.
If anyone can either help me fix this, suggest another package or command line tool, it would be much appreciated. Thanks!
I found this link helpful ...Your mileage may vary...
The basic idea is to use the java.awt.print package and Apache PDFBox (org.apache.pdfbox.pdmodel.PDDocument)
PDFBox also has command line options to print, encrypt, decrypt, etc.
This is the best solution I found for this matter: ICEPDF.
Printing is 99% loyal to PDF seen on screen, allows silent printng and paper size changing. Only drawback, so far, is that I'm unable to show the print dialog, in same cases I need the user to be able to select printer, page size, number of copies, to name a few, this options are now selected prior by the user in an interface of my app.
Anyway, hope it helps!
Related
I am currently making a project for school, where I am going to make a program which teaches children how to read. My basic idea for the program was produce the sentence and then get Windows Anna to say it. My question to you is, how can I access Winodws Anna through Java? and is there a better way of doing this?
Thanks
If having the program access internet is acceptable, then you could use iSpeech.
You can use their API, but the problem with that is that it is limited to 200 uses/day.
iSpeech has decently sounding voices, generally more polished than other TTS engines I've tired like espeak or FreeTTS, because it actually pronounces the words more fluently. Sure, it might pronounce 'Wind', relating with air, as 'Wind', relating to twisting, but other than that, it speaks quite well.
Also, while I haven't had any prior experience with this, I found an article that shows you how to access the MS Speech with command line (which can obviously be commanded through Java[if you do not know how, here is a good article]). It is located here. In command line, all you do is type in 'SayDynamic.exe* the text you want to speak".
*Or SayStatic, the other download available on the page.
This method seems to be better in terms of speed and not relying on internet access, but it definitely does NOT pronounce things as well as iSpeech. I guess the ideal thing for your program to have would be to use iSpeech when online, and use the Say*.exe when offline.
The site also provides the source code of the program. As you might notice, it is NOT Microsoft Anna's voice, but you can specify that in the source and recompile it.
Hope I helped!
You can use command line utiity NirCmd that uses text-to-speech API installed on Windows.
So, supply this utility together with your java application and run it with appropriate command line.
You can try FreeTTS : a speech synthesizer written in java.
You can try to call the Microsoft Speech API (SAPI) but I don't know how to do it in java.
Can you tell us how you invoke NirCmd ?
Altenatively to NirCmd, you can build your own tool in C# that will read the text. The text could be within a txt and your tool invoked with the path to that txt as argument. You can easily adapt a demo project like this one : http://www.codeproject.com/Articles/19334/Text-to-Speech-using-Windows-SAPI
There is the Speech platform of Windows
http://www.microsoft.com/en-us/download/details.aspx?id=27226
The Speech runtime
http://www.microsoft.com/en-us/download/details.aspx?id=27225
You can use JNA (not JNI) to interact with dll from java
https://github.com/twall/jna
I was looking for tool on Java that does the same (similar) functionality of "inspect element" of "Google Chrome". Does anyone has information whether this is available and how it can be implemented?
The question refers to cases when you have the Source code and you don't know the inside of it. Thus, the idea is to inspect elements (objects) on UI while running code!
Since you have access to the code you can use the Java Object Inspector.
Just add one line of code at the right place:
Inspector.inspect(objectToInspect);
Inspect Element in Chrome/Firefox and View Source in Safari are there because the internet is open sourced. The HTML code pushed to a user's machine is viewable by them (obviously not the spreadsheets or other static files held on a server.)
Compiled projects don't have this feature for practical reasons.
In many languages it is impossible to "decompile" an object into its source.
If you could go to Microsoft Word and Inspect any element, you could just copy and paste their application without paying.
So no, you cannot take a compiled Java object and click to see its source code.
I remember hearing about a project that did something like that a few years ago. I can't recall the name, but I ran across this while searching for it. https://github.com/cozycode/Swing-Inspector Based on the description, at least. it looks like it might be useful. If I remember what the original project was i'll post a follow up.
for you to find the java code, in the inspect element go to Sources. Look in the picture below. I inspected google and went to Sources this what i found. press on the files. that say js, and the java code will appear.
if you cant see the pic, tell me. or try to download it, and open it on paint.
enter image description here
Well I have created a web-based POS to take order. My question is how do I create a Java-Applet;
Shows the HTML page & a Print button
Print Order without prompting(no dialogue box)
Additional Information : It works like this. The waiter will key the orders from the computer(POS) , when they hit print, it will detect the I.P address of the printer in the kitchen,then print out the orders immediately without prompt. I am actually looking for reference/guide which can help me start on. Any Advise will be helpful as well. Thank you
You cannot do that for security reasons. If you could, applets would already have become notorious for printing 10+ pages of 'special offers' when you visit unscrupulous web sites.
OTOH, if the client is willing to accept one prompt at applet start-up, you could digitally sign the code.
There is a project that does HTML printing using HTML5 to render the contents to a PNG and Java to print directly, exactly as described in the original post. This project is called "qz-print" (previously called "jzebra") and it offers the digital signature in both self-signed (free) and trusted-signed (at a premium).
It also uses the signed JNLP files as Andrew Thompson has illustrated. (Thanks Andrew, your contributions to Java as a whole have been a great help to Java developers around the world).
https://code.google.com/p/jzebra/
Hey i was wondering if there is a specific api for printing a bunch of common file types(pdf,doc,docx,txt, etc..). I am trying to develop program similar to HP's eprint. eprint annoys me because it prints an email as well as the file attached to it. I just want something i can send files directly to. I have found that java has a printing api, but that seems to focus on printing something from a gui window. any ideas much appreciated!
Thanks
Morpheous
It would be difficult for Java alone to be able to print a variety of different file types, and most of the time I've seen Java programs use other programs to do the printing by using Runtime.exec. If you're going to be trying to use this though, please be sure to read this extremely important article: When Runtime.exec() won't
I am trying to link some user docs to my Java Swing application. The user docs are pdf and I would like to be able to click on a button in my application which opens up some sort of pdf renderer to display my userdoc.pdf.
I do not want to use the runtime exec command
I have tried the following with not much success --
pdfRenderer -- this seems to not work for the current version of pdfs (seems to want older pdfs)
acrobat viewer -- I keep getting font errors (the document is displayed but everytime I go to a new page, I get an error)
JPedal pdfHelp - This sounds cool and if it will work, it would be the best for me. But for some reason, I am unable to open any file here. No pdf file that I have loads in the window (The pdfHelp panel comes up with a list of pdfs as promised, but when I right click one of them and say "OpenPDF", I just get a progress bar and the file does not load, I have tried a few files on this and checked file permissions)
JPedal SimpleViewer -- So far this one seems to be the most promising. I would like to remove some of the functionality of this viewer though and am not able to edit the xml to do this. When I edit the xml, then I seem to get xml parsing errors.
Has anybody done anything similar that worked? Help please
PS. I need this to work on Linux machines (IcePDF seems to works only for Windows). I would very much prefer something that is free!
Would Java's Desktop API meet your requirements? It does launch another process, but it's not through you calling Runtime.exec().
The Desktop API uses your host operating system's file associations to launch applications associated with specific file types.
Update: pdfHelp from IDR solutions (creators of JPedal) works now. The latest version (4.0) has fixed the bug and it reads my pdf files (and I am sure more of the latest pdf files). Just playing around with the product today and it is great! There are few minor bugs but I really appreciate how quickly Mark Stephens(?) responded to the first bug. Good work guys!
I chose pdfbox for a similar use case - it's not perfect with every PDF, but works pretty well and is under active development. From the PDDocument you can get a list of PDPage objects, which have a convertToImage() method that gives you a BufferedImage you can draw on screen. I switched to this from pdf-renderer because I felt it gave better results in general.
PdfHelp has moved to its own domain at http://www.pdfhelp.org and have been updated to fix your issues and add some other improvements...