• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

Java program as a printer  RSS feed

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to create a program that looks like a printer. My idea is based upon CutePDF Writer where it looks like a printer but it's actually a program that creates a PDF. The problem is that I need to print multi page reports from Sage and it can't do it. So what I want to do is create something that looks like a printer so I can print to it and then the program creates the 3 reports required and sends them on to the real printer(s). I'm not sure where to start to create something that I can then install as a printer. Is it possible? My next problem will be to create the reports but that sounds easier :-)
I have tried creating a generic printer which can print to a file. I then used redmon to redirect the output to my java program (after translating it from a .jar to a .exe using launch4j) but when I try to set that in the printer using configure port it says invalid file handle. Even if I point it at redrun.exe to tell it to save it as a temporary file and call the program it still won't let me save it, invalid handle still occurs. So I can't make redmon work. Is there an alternative?
 
Sheriff
Posts: 24374
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, if I read the advertising for CutePDF and squint my eyes just the right way I could almost believe that CutePDF installs itself in Windows so that it appears in the Print dialogs which Windows produces. I use PDFCreator and that's how it works, so that's probably how CutePDF works as well.

So no, it isn't practical to write such a thing in Java. I won't say it's impossible but you would have to use JNI to connect with the necessary Windows interfaces.
 
Ranch Hand
Posts: 380
2
Fedora IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
seems a little bit overkill since the only part you are skipping is saving whatever data you want to print and then opening it with your program to actually create a report and print it.  But if you really want to make a fake printer you can probably do it.  Don't see why not.
 
Neil Barton
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your responses. I have found a way to generate the printer to write to a file so that Sage can output the data there (in a CSV format). I then have a powershell filewatcher to rename it so it doesn't get overwritten. That bit works.
I now want to open that file (the CSV with the data in it), format the contents into a file and print that to a printer (it will be the same printer every time). What's the best way to do that? I've thought about generating the report as a PDF or an HTML file. The HTML is easier but how do I send that to a printer? Is there a better way to formulate output into a specific layout and send it to a known printer (I don't need the user to choose it, it's always the same). What I normally do is format the reports in Excel using JXL abd then the suer can print them as they wish but on this occasion I they don't want to see them. If I use JSL again then it will open Excel (albeit only for a flash) as it prints so I want to avoid that.
 
Saloon Keeper
Posts: 20655
122
Android Eclipse IDE Java Linux Redhat Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's common practice in Windows to create PDF's via a custom printer driver. So that part isn't really all that hard any more.

Getting HTML to print automatically is a bigger problem. For security reasons, web browsers generally have only limited ability to print web pages without someone pushing a button to approve the print, but different browsers have different options. Using a non-browser "print HTML" app may be a possibility, but I don't know what options are presently available there. Stuff like that is standard on Linux, but Linux comes with a whole raft of standard text utilities thanks, in part, to the fact that Unix was used a lot for text formatting in its early years. In Windows, you have to track down external apps. And often pay and get a license. And all too often, tolerate the app sending back details of what you're doing to its owners.
 
Neil Barton
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Tim for that well thought out response. Especially thank you for that link which looks to be all I require to get on with it. I have learnt a lot doing this little task and I'm about to learn a whole lot more!
 
Tim Holloway
Saloon Keeper
Posts: 20655
122
Android Eclipse IDE Java Linux Redhat Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, it's ironic. The Ranch software automatically added the link. I know nothing about the product myself. But if if proves useful, so be it!
 
Neil Barton
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What a shame, it's just a scam. Not sure how well the ranch site is protected but this link goes to an email capture page which takes your details and then doesn't deliver the download. It looked really useful! If you can point me in the direction of any really straight forward PDF creation software that would be really helpful. I've had a look at Jasper Reports but it's all Maven and Eclipse and I don't do that sort of thing, it also seems really complex! All I want to do is print a report!
 
Sheriff
Posts: 6269
1049
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Neil Barton wrote:What a shame, it's just a scam. Not sure how well the ranch site is protected but this link goes to an email capture page which takes your details and then doesn't deliver the download. It looked really useful! If you can point me in the direction of any really straight forward PDF creation software that would be really helpful.


I tried to download it from the site. Like you mentioned, it asked me to sign up. I signed up and logged in. Then I went back to the download page. This time I was able to download the file.
What happened in your case?
 
Neil Barton
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried it again after your response. I can't remember which browser I ended up using (I think it may have been Opera it was about the 5th one I tried). It finally reacted and I managed to download something that actually looks quite useful. I'll work through it over the weekend but early impressions look good, although the state of their website is a bit discouraging :-(
 
Well don't expect me to do the dishes! This ad has been cleaned for your convenience:
Create Edit Print & Convert PDF Using Free API with Java
https://coderanch.com/wiki/703735/Create-Convert-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!