4

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)
Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
highwingers
  • 1,649
  • 4
  • 21
  • 39

3 Answers3

10

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

Community
  • 1
  • 1
Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
  • Thanks, I modifed the Size & now font looks too big, is there anyway to globaly set the FONE size? I am using HTMLWorker & it seems like PDF is NOT picking up the CSS font size. – highwingers Dec 28 '12 at 23:18
  • 1
    @highwingers HtmlWorker has been deprecated due to its many shortcomings. You might want to consider updating before finding workarounds for issues in old software. – mkl Dec 29 '12 at 00:54
  • Mkl what should i use instead then? – highwingers Dec 29 '12 at 09:35
  • You should use XML Worker. http://sourceforge.net/projects/itextsharp/files/xmlworker/ – Bruno Lowagie Jan 01 '13 at 14:32
2

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.

yazheirx
  • 21
  • 1
  • 1
  • I agree with you. Can i use printer language with .NET. Do you have online examples for me so i can get the idea. I dont mind exploring zebra samles. Ty – highwingers Dec 29 '12 at 09:36
  • "^XA^FO150,80^A0N,50,50^FDSAsset^FS^FO25,145^BY3,3^BCN,100,N^SNWI12345,1,Y^FS^FO130,270^A0N,40,40^SNWI12345,1,Y^FS^PQ3^XZ" Formatting is not working for me so this will be a single line. the preceding string can be sent directly to the printer and will produce 3 (^PQ3) sequential numbered labels. You can download the entire ZPLII manual from zebra's website, but you have to login first. – yazheirx Jan 02 '13 at 19:02
1

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!!

sp_m
  • 2,647
  • 8
  • 38
  • 62