vb.net 如何使我的 PDF 完全适合 4x6 英寸?目前正在以普通 A4 文档打印
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14076570/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How Can I make my PDF exactly fit within 4x6 inches? currently It is printing in regular A4 document
提问by highwingers
I am creating Shipping Label using iTextSharp.
我正在使用 iTextSharp 创建运输标签。
What I am doing is Creating a Label in PDF so I can format it in any way I want and then send it to my THERMAL PRINTER.
我正在做的是在 PDF 中创建一个标签,这样我就可以按照我想要的任何方式对其进行格式化,然后将其发送到我的热敏打印机。
My problem is, My labels are of size 4x6 (standard shipping label). These are the labels which we see on UPS & Fedex Packages. How Can i make my PDF exactly fit within 4x6 inches? currently It is printing in regular A4 document.
我的问题是,我的标签尺寸为 4x6(标准运输标签)。这些是我们在 UPS 和 Fedex 包裹上看到的标签。如何使我的 PDF 完全适合 4x6 英寸?目前正在以普通 A4 文档打印。
I am using following:
我正在使用以下内容:
Dim document As New Document()
document.SetPageSize(PageSize.A4_LANDSCAPE)
回答by Robert Harvey
Set a Custom Page Size:
设置自定义页面大小:
Dim pgSize As New iTextSharp.text.Rectangle(myWidth, myHeight)
Dim doc As New iTextSharp.text.Document(pgSize, leftMargin, rightMargin, topMargin, bottomMargin)
iTextSharp uses 72 pixels per inch, so if you know the height and width of your desired page size in inches, just multiply those numbers by 72 to get myWidth and myHeight.
iTextSharp 每英寸使用 72 像素,因此如果您知道所需页面大小的高度和宽度(以英寸为单位),只需将这些数字乘以 72 即可获得 myWidth 和 myHeight。
回答by yazheirx
I would recommend producing raw printer language. Thermal bar code printers all have a native language. Languages such as ZPLII (Zebra Printer Language 2) or DPL (Datamax Printer Language). You can build them as a string and pass them directly to the printer. Searching the printer manufactures website you can quickly find the printer language manual for the printer you are using.
我建议制作原始打印机语言。热敏条码打印机都有母语。ZPLII(Zebra 打印机语言 2)或 DPL(Datamax 打印机语言)等语言。您可以将它们构建为字符串并将它们直接传递给打印机。搜索打印机制造商网站,您可以快速找到您正在使用的打印机的打印机语言手册。
The great advantage to this method is control and speed. As Zebras and Datamax printers do not actually care about a page size you can focus on rendering the data you want in the size and orientation you want.
这种方法的最大优点是控制和速度。由于 Zebras 和 Datamax 打印机实际上并不关心页面大小,因此您可以专注于以所需的大小和方向呈现所需的数据。
You may also be able to take advantage of some of the extra logic that the printers have. This is especially useful for serialized tags with sequential numbering. A single string sent to the printer can produce dozens to hundreds of labels. If you are going to do a lot of thermal bar code printing I strongly recommend understanding the power these printers contain in their native languages.
您还可以利用打印机具有的一些额外逻辑。这对于具有顺序编号的序列化标签特别有用。发送到打印机的单个字符串可以生成数十到数百个标签。如果您要进行大量热敏条码打印,我强烈建议您了解这些打印机以其母语所包含的功能。
回答by sharad
To Set document size use like this:-
要设置文档大小,请使用以下方法:-
Document doc = new Document(new iTextSharp.text.Rectangle(295f, 420f), 0f, 0f, 0f, 0f);
PdfWriter.GetInstance(doc, Response.OutputStream);
doc.Open();
-----------
-----
---------
For font here is code:-
对于字体,这里是代码:-
iTextSharp.text.Font myFont1 = new iTextSharp.text.Font() { Size = 4.5f };
PdfPTable header1 = new PdfPTable(2);
header1.AddCell(new PdfPCell(new Phrase("", myFont1 )) { UseAscender = true, PaddingTop = 0, Border = 0, HorizontalAlignment = 0 });
i have just added other property's for you information future use.
我刚刚添加了其他属性供您将来使用。
happy coding!!
快乐编码!!

