Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Can I make my PDF exactly fit within 4x6 inches? currently It is printing in regular A4 document

I am creating Shipping Label using 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.

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.

I am using following:

Dim document As New Document()
document.SetPageSize(PageSize.A4_LANDSCAPE)
like image 471
highwingers Avatar asked Dec 12 '22 19:12

highwingers


2 Answers

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.

https://stackoverflow.com/a/2503476/102937

like image 128
Robert Harvey Avatar answered Jan 22 '23 09:01

Robert Harvey


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.

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.

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.

like image 33
yazheirx Avatar answered Jan 22 '23 10:01

yazheirx