Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 15 of 15

Thread: Making a invoice template in java

  1. #1
    Member
    Join Date
    Dec 2010
    Posts
    69
    My Mood
    Busy
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Making a invoice template in java

    I was wondering if anyone has any pointers on how to create a billing invoice from a java application? I have a customer database that I can store customer information and soon will add where it can keep track of their orders and I wanna be able to press something like "Print" and it will generate a preset template that looks like a billing invoice and filled in with their personal information/product type/ and total. Just looking to be shown the right direction of how to complete something of this magnitude?


    I'm unsure if Java has any methods that allow you to generate a PDF file and allow you to edit it through your code


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Making a invoice template in java

    if Java has any methods that allow you to generate a PDF file and allow you to edit it through your code
    I think the apache project has packages for working with pdf files.
    It's not part of Java SE.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Making a invoice template in java

    You might wish to look into reporting libraries, for instance Jasper Reports. You can create a template, which can then be populated by the data source

  4. #4
    Member
    Join Date
    Dec 2010
    Posts
    69
    My Mood
    Busy
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Making a invoice template in java

    Quote Originally Posted by copeg View Post
    You might wish to look into reporting libraries, for instance Jasper Reports. You can create a template, which can then be populated by the data source
    Yeah I just looked through some of the Jasper Reports documentation and it seems overly complex. I'm gonna have to read more into it to even figure out how to install it and use it if I can find the right article.

  5. #5
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Making a invoice template in java

    Quote Originally Posted by _lithium_ View Post
    Yeah I just looked through some of the Jasper Reports documentation and it seems overly complex. I'm gonna have to read more into it to even figure out how to install it and use it if I can find the right article.
    Could be overkill. I've only used it in a server setting in which someone else did the dirty work, and it's comprehensive and useful. iReports could useful in creating the templates.

  6. #6
    Member
    Join Date
    Dec 2010
    Posts
    69
    My Mood
    Busy
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Making a invoice template in java

    I'm going to give it a slight attempt (just going to set it up and see if I can generate some sample ones to get the feel for it). You basically load the .jar into your classpath and then from there are able to use the library correct? Sorry I have little experience dealing with this kind of scenario

  7. #7
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Making a invoice template in java

    Quote Originally Posted by _lithium_ View Post
    You basically load the .jar into your classpath and then from there are able to use the library correct?
    Yes. Also make sure the required libraries are also on the classpath (there are some commons libraries, iText, etc...should be outlined in the link above)

  8. #8
    Member
    Join Date
    Dec 2010
    Posts
    69
    My Mood
    Busy
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Making a invoice template in java

    Quote Originally Posted by copeg View Post
    Yes. Also make sure the required libraries are also on the classpath (there are some commons libraries, iText, etc...should be outlined in the link above)
    Yeah I can't seem to even get it started. All the documentation I find is about javascript when I use NetBeans for Java SE6, Can you refer me to an article that oversights how to install these types of packages as well? Seems I need a refresher course seeing as I haven't messed with this stuff in a long time.

  9. #9
    Member
    Join Date
    Dec 2010
    Posts
    69
    My Mood
    Busy
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Making a invoice template in java

    Okay so i followed this guide = Integrating and Using JasperReports in NetBeans Original article by Craig Conover and Marina Sum Java DevZone

    I got it all set up, but the problem is that this select part of the code that goes in the "main" in my project keeps erroring:
    <!-

    ->

    I have a feeling it's due to the file extension part of that guide but it was for an older version and wasn't the same as mine (NetBeans 6.9.1) and it wont allow me to add the three types:
    XML
    application/xml
    text/xml


    to the new .jrxml extension? The netbeans only allows the selection of one??

  10. #10
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Making a invoice template in java

    I don't have time to gather all the requirements right now to test this (again, I've only used this in a server environment in which the deployment already contained the necessary libraries), but it sounds like you are having a hard time editing the xml? Did you try simple a text editor? iReports might be an easier tool to help you visually lay out everything and then writing the jrxml file for compilation

  11. #11
    Member
    Join Date
    Dec 2010
    Posts
    69
    My Mood
    Busy
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Making a invoice template in java

    Yeah I could look into iReports. What do you mean writing the jrxml in compilation? Like filling in the specific fields? Sorry I'm new to this whole reporting thing and trying to pick it up but having some difficulties.


    I just don't understand why Netbeans is erroring on the "<!-" and "->" lines when that guy in the guide used it

  12. #12
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Making a invoice template in java

    Quote Originally Posted by _lithium_ View Post
    I just don't understand why Netbeans is erroring on the "<!-" and "->" lines when that guy in the guide used it
    Disconnect from your IDE for the moment, a jrxml file is just an xml file, eg just like any other text file you can just edit it using a text editor. Jasper than compiles this xml file into a more readily used format to create the report. If you trust the source, than try using Jasper to compile and the population/create the report (regardless of IDE 'errors')

  13. #13
    Junior Member
    Join Date
    Dec 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Making a invoice template in java

    import org.apache.pdfbox.pdmodel.PDDocument;
    import org.apache.pdfbox.util.PDFTextStripper;
    import javax.swing.text.*;


    import java.util.*;
    import java.io.*;

    import org.apache.pdfbox.exceptions.InvalidPasswordExcept ion;

    import org.apache.pdfbox.pdmodel.PDDocument;
    import org.apache.pdfbox.pdmodel.PDPage;
    import org.apache.pdfbox.util.PDFTextStripperByArea;
    [/code

    PDDocument document=null;
    PDFTextStripper stripper=null;
    String result=null;
    int numpages=0;
    try {
    stripper = new PDFTextStripper();
    } catch (IOException e1) {
    // TODO Auto-generated catch block

    result="An error occurs while extracting text for: , Technical error: "+e1.getMessage()+"\n";
    }

    try {
    document = PDDocument.load("E://backup18july24/uni/lecs/os/OS120102011.pdf");

    numpages=document.getPageCount();
    } catch (IOException e0) {
    result="An error occurs while extracting text for:, Technical error: "+e0.getMessage()+"\n";

    }

    try {

    stripper.setStartPage( 2);
    stripper.setEndPage( numpages );

    result=stripper.getText(document);

    } catch (IOException e0) {

    result="An error occurs while extracting text for: Technical error: "+e0.getMessage()+"\n";
    }
    /code]

    Hello...you can use pdfbox api to manipulate pdf files...my code just extracts the text from a pdf file.

    good luck

  14. #14
    Junior Member
    Join Date
    Jul 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Making a invoice template in java

    it's very difficult and a big responsibility to make a invoice template so i get it from *** which are very useful and you can customize them according to your requirement.

  15. #15
    Junior Member
    Join Date
    Mar 2018
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Making a invoice template in java

    I make my own invoice template from my software. Thanks Lina20 for this code.
    Last edited by programmingfan; June 21st, 2019 at 09:07 AM.

Similar Threads

  1. Making a java program into an applet
    By JamesdTurnham in forum Java Applets
    Replies: 4
    Last Post: November 4th, 2012, 10:12 PM
  2. [SOLVED] How to create a Java generic method, similar to a C++ template method?
    By Sharmeen in forum Object Oriented Programming
    Replies: 3
    Last Post: October 18th, 2012, 02:33 AM
  3. Replies: 1
    Last Post: April 6th, 2012, 12:36 PM
  4. How to use VelocityContext to take values from template?
    By noFear in forum Java Theory & Questions
    Replies: 1
    Last Post: October 14th, 2010, 01:45 AM
  5. Help writing a Template Class
    By mamipapi in forum Object Oriented Programming
    Replies: 2
    Last Post: October 5th, 2010, 09:34 PM