Results 1 to 15 of 15
Like Tree1Likes
  • 1 Post By angstrem

Thread: printing to a laser printer

  1. #1
    alan2 is offline Member
    Join Date
    Mar 2013
    Posts
    42
    Rep Power
    0

    Default printing to a laser printer

    Printing to a printer is fundamental to financial applications, where p&l account and balance sheets are amongt the items that must be printed.

    I can not obtain any meanigful information on this. If anyone can supply *simple* code examples I will be grateful, but tell me where to plug them in please! (using Netbeans and a complete and utter beginner).

    **Also, how can I trun off irritating sound (adverts?)?
    Last edited by alan2; 03-17-2013 at 01:58 AM.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: printing to a laser printer

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    alan2 is offline Member
    Join Date
    Mar 2013
    Posts
    42
    Rep Power
    0

    Default Re: printing to a laser printer

    Quote Originally Posted by DarrylBurke View Post
    Many thanks db, but I've already Googled this and tried it. The problem I have is fitting it into a new project. As I indicated, I am a complete beginner. Have you actually tried it?

  4. #4
    angstrem is offline Member
    Join Date
    Mar 2013
    Posts
    11
    Rep Power
    0

    Default Re: printing to a laser printer

    If you're a completely beginner, than, first of all, you should get familiar with core Java classes and Java program structure and only than try writing programs for your needs. I've never dealt with printing on Java, but I've understood how to do it from the official tutorial, posted previously. Everything's simple, you just have to know the basics.
    DarrylBurke likes this.

  5. #5
    alan2 is offline Member
    Join Date
    Mar 2013
    Posts
    42
    Rep Power
    0

    Default Re: printing to a laser printer

    Yes, undoubtedly you are right. Funny though, how no-one worldwide seems to have actually done printing! If Java is used for serious business programming, you would expect it to be common. Printing out financial reports is just about the most universal action in financial software!

    This is chicken and egg stuff! The reason why I wanted to check whether printing formatted mixed text and formatted (aligned) figures was possible is that I wanted to see whether I should dive in and learn Java. I have written a couple of Java programs to verify that certain other things were possible. Print was one of the two things unverified.
    Last edited by alan2; 03-17-2013 at 07:23 PM.

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,344
    Blog Entries
    7
    Rep Power
    20

    Default Re: printing to a laser printer

    It is Sunday so that's why it's quiet at the moment; basically printing is painting to a Graphics object that is printed by the printing framework. Read the API documentation.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    alan2 is offline Member
    Join Date
    Mar 2013
    Posts
    42
    Rep Power
    0

    Default Re: printing to a laser printer

    Thanks Jos

    Will that API allow me to print rows and columns of text and figures, aligned by the decimal point?

    I am very willing to get deeply into this but not if the answer at the end (after hours of work) is that 'it can't be done!' All I'm trying to do at this stage is decide whether to embark on proper study of Java. I can do the reports with vb6 (though even the vb6 documentation is silent on the matter) but only with dot.net because there was an outcry followed by Micro$oft bringing back printing compatability. Again, seemingly very few in that community had come across the need to print. Amazing! I'm really puzzled about this. Has anyone here actually succeeded at first hand with printing financial reports to a printer using Java?

  8. #8
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    757
    Rep Power
    8

    Default Re: printing to a laser printer

    I am not sure if this related to what you are doing. When you are creating a report / financial report used in the enterprise application you'll usually use a reporting tools. For instance in Java you can use something like Jasper Reports which will help you to produce reports in a PDF format. Which later can be printed out using program such as Acrobat Reader. In this case you wouldn't need to interact with the low level printing API.

  9. #9
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,344
    Blog Entries
    7
    Rep Power
    20

    Default Re: printing to a laser printer

    Quote Originally Posted by alan2 View Post
    Thanks Jos

    Will that API allow me to print rows and columns of text and figures, aligned by the decimal point?

    I am very willing to get deeply into this but not if the answer at the end (after hours of work) is that 'it can't be done!' All I'm trying to do at this stage is decide whether to embark on proper study of Java. I can do the reports with vb6 (though even the vb6 documentation is silent on the matter) but only with dot.net because there was an outcry followed by Micro$oft bringing back printing compatability. Again, seemingly very few in that community had come across the need to print. Amazing! I'm really puzzled about this. Has anyone here actually succeeded at first hand with printing financial reports to a printer using Java?
    If you can paint your report or whatever, you can print it, it's as simple as that. The JTextComponents can do the printing themselves but they use the same mechanism; the printing framework may seem intimidating at first but it offers a lot of hoopla around the basics (number of pages, landscape printing, print quality, page headers and footers etc. etc.)

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  10. #10
    alan2 is offline Member
    Join Date
    Mar 2013
    Posts
    42
    Rep Power
    0

    Default Re: printing to a laser printer

    Again, many thanks Jos. That gives me a good indication. But the question remains open: Has anyone here actually printed financial reports with formatted decimal aligned figures? This is what astounds me. This must be the most common function of business software. Presumably this forum is read by thousands (hundreds of thousands? millions?) of Java devlopers around the world? Does the total lack of 'I've done it!' type replies mean that most business software is not written in Java?

  11. #11
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,344
    Blog Entries
    7
    Rep Power
    20

    Default Re: printing to a laser printer

    Quote Originally Posted by alan2 View Post
    Again, many thanks Jos. That gives me a good indication. But the question remains open: Has anyone here actually printed financial reports with formatted decimal aligned figures? This is what astounds me. This must be the most common function of business software. Presumably this forum is read by thousands (hundreds of thousands? millions?) of Java devlopers around the world? Does the total lack of 'I've done it!' type replies mean that most business software is not written in Java?
    I never did any substantial financial stuff but using a fixed width font and the DecimalFormat class can solve what you're after.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  12. #12
    alan2 is offline Member
    Join Date
    Mar 2013
    Posts
    42
    Rep Power
    0

    Default Re: printing to a laser printer

    Hi Jos

    I went through this with Visual Basic 6. The vb6 community insisted that I must use a fixed width font in order to get decimal alignment. They were wrong. In the end (as a very green beginner) I was able to do it using Arial perfectly satisfactorily. Here for interest is a fragment of vb6 code. You'll see how simple it is.

    Aligned = Format(FBU5.OuputTaxYTD,"#.###.00")
    Printer.CurrentX=160-Printer.TextWidth(Aligned):Printer.Print Aligned

    Aligned is a an arbitrary variable name for passing the contents of a file record and field in formatted state; FBU5.OutputTaxYTD is a UDT arbitrary variable field name for the random access file; 160 is a horizontal tab setting (hence CurrentX) for the decimal point on the report.

    I would love to be able to do something like this in Java!

  13. #13
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,344
    Blog Entries
    7
    Rep Power
    20

    Default Re: printing to a laser printer

    Quote Originally Posted by alan2 View Post
    Aligned = Format(FBU5.OuputTaxYTD,"#.###.00")
    Printer.CurrentX=160-Printer.TextWidth(Aligned):Printer.Print Aligned
    I don't speak vb (and I like to keep it that way thank you) but if that piece of code does what I think it does, it doesn't align on the decimal point; try the numbers 1.88 and 8.11

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  14. #14
    alan2 is offline Member
    Join Date
    Mar 2013
    Posts
    42
    Rep Power
    0

    Default Re: printing to a laser printer

    That's just what the vb6 community said BUT I'm looking right now at a live financial report produced using that code and I can assure you that the decimal points line up right down the page and including for example 8.16 and 240.00!

  15. #15
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,344
    Blog Entries
    7
    Rep Power
    20

    Default Re: printing to a laser printer

    Quote Originally Posted by alan2 View Post
    That's just what the vb6 community said BUT I'm looking right now at a live financial report produced using that code and I can assure you that the decimal points line up right down the page and including for example 8.16 and 240.00!
    To me that snippet of code prints a string right aligned but I don't speak vb so it might as well do something mysterious again. If it prints the way you want it to print, keep it that way.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. printing to printer
    By ak88 in forum Advanced Java
    Replies: 3
    Last Post: 01-13-2013, 03:32 PM
  2. Printer loop the same printing
    By kiki2009 in forum Advanced Java
    Replies: 2
    Last Post: 04-29-2011, 05:43 PM
  3. Printing in a printer
    By UJJAL DHAR in forum Advanced Java
    Replies: 5
    Last Post: 01-29-2011, 12:03 PM
  4. Printing Text using printer
    By UJJAL DHAR in forum New To Java
    Replies: 1
    Last Post: 12-06-2010, 04:26 PM
  5. Replies: 4
    Last Post: 09-10-2009, 01:40 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •