4

I have created the pdf for bill using iText. I want to print this bill in POS printer. POS printer Paper size will be 58mm. My PDF is look like A4 size. How to re size this page for POS printer size?

And, If products goes more than 100 mean, I have to use new page. So there will be two pages. For this case how can I print the bill in single paper.

Or else is there any other way to create bill and print using android mobile or tablet?

1 Answers1

1

When you create a document like this:

Document document = new Document();

A document is created of which all the pages have the default size. The default size is A4.

There is a class named PageSize that contains many different standard sizes. For instance, if you want to create a page with the American LETTER size, you can create the Document like this:

Document document = new Document(PageSize.LETTER);

You are confronted with two problems:

  1. Your bills do not have a standard size.
  2. You don't know the size of your bill in advance.

Solving problem 1 is easy: the Document class accepts a Rectangle parameter. You can create your own page size like this:

Rectangle pagesize = new Rectangle(288, 720);
Document document = new Document(pagesize);

In this case, you'll have pages that measure 4 by 10 inch:

288 user units = 288 pt = 4 x 72pt = 4 inch
720 user units = 720 pt = 10 x 72pt = 10 inch

You can solve your first problem by converting 58 mm into pt: 164.409448819 pt

Solving the second problem is more difficult. One way to do it, would be by creating a document that is extremely long. The maximum size of a PDF is 14,400 by 14,400 user units, so you could create your rectangle like this:

 Rectangle pagesize = new Rectangle(164.41f, 14400);

It would be really surprising if you had a bill that was longer than 5.08 meter. If that PDF is too long for your printer, you could store the y position at the end of the content and then reduce the page size in a second go.

Another approach would be to add all the content to a ColumnText object, then ask the column for its height and create a new ColumnText object for a newly created document with the height calculated before. How to do this? That's explained in my answer to this question: How to adjust the page height to the content height?

Community
  • 1
  • 1
Bruno Lowagie
  • 75,994
  • 9
  • 109
  • 165
  • Thank You Sir.. I will use your solution in my project. Sir, I am going to use iText in my project. Not going to sale my project. But going to use with my and my friend's hotel. Is there any amount I have to pay for this sir? I already read some answers related this question. But still I am afraid in my case. Please remove my fear by your answer sir.. – Vijayadhas Chandrasekaran Apr 03 '15 at 10:39
  • The decisive answer can only be provided by looking at the specific situation. Please contact iText Group at one of the following addresses: http://itextpdf.com/contact – Bruno Lowagie Apr 03 '15 at 11:04
  • what a bout using PageSize.A6 instead of using Rectange ? – Menna-Allah Sami May 19 '15 at 10:25
  • 1
    @Menna-AllahSami `PageSize.A6` is a predefined `Rectangle` object, so yes, you can use it instead of defining your own custom `Rectangle` object. – Bruno Lowagie May 19 '15 at 11:55
  • @NewDeveloper Does this solution solve your problem ? – Menna-Allah Sami May 20 '15 at 09:41
  • Yes.. POS printer Page size problem is solved. But still we did not test printing. So Printing issue is not solved.. – Vijayadhas Chandrasekaran May 21 '15 at 06:11