• 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
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

Page x of Y Java ItextPDF ver 5.5.9

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys,

It's my first time posting here and this code is bugging me for a while now. I'm not quite sure where am I getting it wrong but I'm getting a null pointer exception whenever I run it. Everything works just fine except the part where I want to print "page x of y" in my generated PDF. I've seen different approaches all over the internet although I think the best approach would be the 2nd passing as what they call it. (although I'm not quite sure if it is really the best part). anyways here's my code, any help, criticism and code improvements are very welcome. Thank you!

 
Saloon Keeper
Posts: 6888
163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In which line of code does the exception happen? Which object or object reference is null?

You can find an example of how to add headers/footers with iText5 at https://coderanch.com/wiki/660110/iText-OpenPDF

List Values = new ArrayList();


Field names should always be lowercase in Java. Only class names are uppercase.

As an aside, be ware that iText 5 requires you to obtain a license, unless you use in conformance with the AGPL - which would mean that you must make the source code available to everyone who uses it over the network.
 
Armand Betan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Moores wrote:In which line of code does the exception happen? Which object or object reference is null?

You can find an example of how to add headers/footers with iText5 at https://coderanch.com/wiki/660110/iText-OpenPDF

List Values = new ArrayList();


Field names should always be lowercase in Java. Only class names are uppercase.

As an aside, be ware that iText 5 requires you to obtain a license, unless you use in conformance with the AGPL - which would mean that you must make the source code available to everyone who uses it over the network.



Hi Tim,

Thanks for replying, I though iText5 is for free (The person who provided the jar file told me so), and this is only for a school activity, not for production or operation actually.

Regarding the null pointer exception, I'm getting it at this part of the code.



I'm getting a nullpointer whenever the program executes this line;



 
Tim Moores
Saloon Keeper
Posts: 6888
163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I though iText5 is for free (The person who provided the jar file told me so), and this is only for a school activity, not for production or operation actually.


It matters not - whoever gets PDFs created by iText5 under the AGPL must be provided access to the source code if he asks. You should always check the license of software you use. As you have seen, what other people tell you can be wrong.

I'm getting a nullpointer whenever the program executes this line


We can't tell from that where the error happens - post the full stack trace of the exception. You can debug the issue by checking all object for null before using them.
 
Armand Betan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Moores wrote:

I though iText5 is for free (The person who provided the jar file told me so), and this is only for a school activity, not for production or operation actually.


It matters not - whoever gets PDFs created by iText5 under the AGPL must be provided access to the source code if he asks. You should always check the license of software you use. As you have seen, what other people tell you can be wrong.

I'm getting a nullpointer whenever the program executes this line


We can't tell from that where the error happens - post the full stack trace of the exception. You can debug the issue by checking all object for null before using them.



Thank you Tim for your reply.

I'll keep that in mind with the AGPL license for Itext PDF, I fairly new with the technicalities of Software Engineering so I'm not much used to discussion licenses.

With regards to my program, I was able to find a solution by creating another function doing a second pass method to the generated PDF. I would happy to share my source code if someone needs it in the future.

 
You can't expect to wield supreme executive power just because
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic