如何创建法案在Android的POS打印机大小?法案、打印机、大小、POS

2023-09-12 10:34:47 作者:False 虚假

我已经创建了一个利用iText的PDF格式的票据。 我想打印这一法案在POS打印机。 POS打印机纸张尺寸将是58毫米。 我的PDF是看起来像A4大小。 如何重新大小此页面POS打印机大小?

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?

和,如果产品进入100多个意思,我一定要使用新的一页。 所以会有两页。 对于这种情况我该怎么在一张纸上打印账单。

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.

否则是有任何其他方式使用Android手机或平板电脑创造票据和打印?

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

推荐答案

当你创建一个文件是这样的:

When you create a document like this:

Document document = new Document();

一个文件被创建,其中所有页面的默认大小。默认大小为A4。

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

每页包含许多不同的标准尺寸命名为一类。举例来说,如果你想与美国Letter尺寸创建一个页面,你可以创建文件是这样的:

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);

正在面临着两个问题:

您的账单没有一个标准尺寸。 您不知道法案的大小提前。

解决问题1很简单:在文件类接受矩形参数。你可以创建自己的页面大小是这样的:

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);

在这种情况下,你必须衡量4×10英寸页:

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

您可以通过转换58毫米到PT解决您的第一个问题:164.409448819 PT

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

解决第二个问题是比较困难的。做到这一点的方法之一,是通过创建一个文件,是非常长的。 PDF文件的最大尺寸是14,400 14,400由用户单位,所以你可以创建你的矩形是这样的:

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);

如果你有一个法案,长于5.08米这将是令人惊讶。如果PDF太长您的打印机,你可以存储在位置内容的末尾,然后减少一来二去的页面大小。

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.

另一种方法是添加所有的内容到 Col​​umnText 对象,然后要求其高度列,并创建一个新的 Col​​umnText 的与之前计算出的高度的新创建的文档对象。如何做到这一点?这是在我的回答解释了这个问题:调整页面高度,以内容的高度

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: Adjust page height to content height