You told me that I would need to know how many lines a page can hold, do you have any suggestions how I can figure this from my Java code?
I doubt it's possible for plain text. If you google for something like printing from Java, you'll find examples on how to get information about available printers. You might be able to ask those printers what their default font is, what page size they have, etc., and then you might be able to look at the metrics for that font and calculate how many lines per page.
In reality, though, that's probably an untenable approach. And you could only do it at the point when you go to print. It's absolutely impossible to do when you generate the text file, unless you know where it will be printed. But seriously, I don't think you'll be able to do all that.
As already suggested, look into something like PDF.
Or, when you go to print your text file, in the page setup, you should have the option to add page numbers, and the printer will figure it out.