For the past month or two, I have been tearing my hair out with this. I need to print multiple copies of a PDF file in Java. I have tried multiple libraries, including Apache PDFBox, IcePDF and others, I have tried many codes I have been able to find, but the result is always the same, both on Windows and Linux, only one copy of PDF is printed, be it to PDF or to a regular printer. I have also tried a number of printers, even one that was enterprise grade, so that I was able to rule out the incompatibility of my printers. Has anyone ever encountered this problem? I would like to use system calls to programs like Adobe Reader/Foxit Reader as a last resort. Thank you for all your help :)
// What I need is a way to print multiple copies in one print job, not in a loop creating multiple print jobs, sorry that it was unclear from the original post.
Have you tried Gnostice PDFOne (for Java)? You can use its setCopies() method.
http://www.gnostice.com/nl_article.asp?id=160&t=How_to_Print_a_PDF_Document_in_Java
Related
I wrote a java program, which manipulates Word documents (docx) with Apache POI. It runs fine within Eclipse, and it runs fine as a runnable JAR on my computer (Windows 10).
I copied that JAR to another computer, and it is starting up normally. The GUI behaves like expected.
The problem is the Word document I write out (docx).
I am performing two types of changes. The first one is the addition of new paragraphs or concatenation of content to the runs. If I stay with this, the document gets written into the file system correctly. The second type is the simple replacement of content within the runs (changes of words and some grammatical changes). I would see that part as the "simpler" one, but if I stay with this or if I combine both change types, no document is written out at all. It does look like there is a bug, but there isn't one because it worked fine on my system.
I wrote myself a function to write out an error log (txt) to get information about that issue. This one worked on both systems. But the log didn't get any information, why the document was not written out.
I suppose there are some Windows security settings which interfer with my program or something like that. The computer that does not like to run my program has Win 7 installed on it, and there are some security domain settings, which affect all other computers in the local network.
Does anyone experienced something similar yet? Any suggestions what to check? Suggestions how to find out if an error happened are appreciated as well.
OK, the problem got solved by simply updating the Java version. I saw that update icon in the system tray, which didn't open update the update dialog. So I wanted to update the Java-version at least.
When I wanted to de-install the current Java version first, I noticed that the Win7-machine hadn't a Java-update for three years now. It was just installed in 2014. As soon as the recent version was installed, everything worked like expected again.
The strange behavior that some parts of my program worked and some not, confused me. I hoped that the Java update would fix this, but I doubted that. I didn't knew that old versions make programs run unpredictably.
I'm currently attempting to write a program that needs to read /dev/input/mice in order to gain mouse input. My only problem is that when I read from /dev/input/mice all I get is gibberish. Online (Google), I found very few helpful webpages. I've attempted to use OD's output, but thats even worse than just trying to read from the file. I've attempted to use third-party libraries, but as I am working with an ARM architecture, many libraries will not run or compile. Does anyone know what format this data is in, and how to parse this data into understandable data.
Libraries I've tried to Use:
https://code.google.com/p/jnativehook/ (Won't recompile on ARM)
http://sdljava.sourceforge.net/ (Can't even get this one to compile x86!)
EDIT: I'm using a raspberry pi, with no X server installed. (NO AWT)
Thanks to #JustinB for his answer in the comments, just thought I should put it here for others to see:
JustinB: "/dev/input/mice outputs 3 bytes, The first byte is the button data, the next two are x and y. Its not java code, but you might find this or this helpful "
After adding <item>170,000</items> to string.xml. It becomes so slow in building workspace, I increase my heap space and jvm memory, but is still slow I had to wait 4 hours after every edit to save on eclipse before i think of running the program.
Any solution please? (Am using gnome 3.0 on ubuntu 11.10).
Instead of placing strings in string.xml, why don't you try placing a file inside /res/raw and when the app starts for the first time you insert it into a db?
It's not clear to me exactly what you are doing. How are you building this XML file? Perhaps you are using Java string concatenation? That will certainly be extremely slow. I would do it using something like an XMLStreamWriter. But you need to describe your scenario in more detail, for example I don't see where Eclipse comes into it.
I have a need to be able to programmatically convert a PNG file that has been optimized for an iOS application and remove the optimizations. A number of posts reveal the mechanism for doing this, but I was hoping there was some Java code already out there for doing this before I go do this on my own.
Does anyone know of a Java converter for CgBI images to RGBA?
I got interested on the topic and made some research on the area. On one related page on PNG conversions I ended up to a jar package type of converter which may be something that you'd be pleased of. I suppose it to be some sort of Open Source solution, because the source was announced to be found from the same place.
I wrote a command line C program that does the same. In addition to the other converters (I have yet to test the online one), mine can handle multiple IDAT chunks, Adam7 interlacing, and all row filter types -- the latter is necessary to de-multiply color pixels with their alpha. All of this leads to, AFAIK, the very same image that got fried.
See my website for the full C source code.
Okay, so here's my problem:
We use FOP for creating "pretty" report output. We use the pdf option if the user wants a file, AWT for previewing, and the -print option for printing them. We are using FOP 0.25.x, which I fully recognize is not the newest version, but upgrading to 0.95 appears to be a non-trivial task that I don't necessarily want to undertake.
Anyway, it was noticed by one of our users that when printing ID cards (generated via FOP -print option) to the id card printer, the images on the cards (pictures of the employees) had some corruption in them...sort of like like green and reds dots and lines. We also discovered that if we sent the exact same print request to one of our HP color laserjets, it printed fine. To add to the strangeness, if we use FOP to create a PDF of the ID card and then print it via acrobat reader on the card printer, it prints fine.
I eventually discovered that it had something to do with the scaling of the images...we were scaling 600px high images down to something like 120px. If I presized the images down, even just halfing them, the corruption went down noticeably. Similarly, when I upsized the images, the corruption went up.
So my question: anybody have ANY idea what is going on here? Or has ever run into such a thing?
Since I don't know why this is happening, I don't know how to fix the root cause, but I've been working through some various workarounds:
1) Use FOP to create a pdf of the image and then print that via Java. This seems like an obvious answer, but some Googling around showed that printing a PDF via Java is not trivial. I've seen the PDF Renderer project on java.net, but seems pretty bulky for a single very specific application.
2) Try to resize the images before giving it to FOP. This also seemed pretty straightforward, however our various users can setup stylesheets for these id cards however they want and using "pt" and "in" sizing in them seems to be pretty common...I don't know of any good way to map that to a pixel resizing.
If anybody has any insight into the root cause, ways to make these work arounds work, and/or another idea, you'd be in my debt.
Most certain explanation:
image corruption? it's a bug.
Why not use 0.95? Sooner or later you have to upgrade, Apache consortium won't
fix bugs in 0.25.x versions.
You can't hope to find workarounds for every bugs which might occur in future.
I ended up doing the second thing I mention in the original question...i.e. resizing it before giving it to FOP. I found that I could retrieve the dpi of the printer I was printing to and do some math on it to get pixel sizing. Seems to work perfectly in all my testing...not a real solution but an adequate workaround.