- Code: Select all
PdfDocument pdf = new PdfDocument();
//set label sizes and add new page
PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
float width = unitCvtr.ConvertUnits(100f, PdfGraphicsUnit.Millimeter, PdfGraphicsUnit.Point);
float height = unitCvtr.ConvertUnits(50f, PdfGraphicsUnit.Millimeter, PdfGraphicsUnit.Point);
SizeF size = new SizeF(width, height);
PdfPageBase newPage = pdf.Pages.Add(size, new PdfMargins(0));
//set font and size
PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 64f);
//set color
PdfSolidBrush brush = new PdfSolidBrush(Color.Black);
//add text to center of page
PdfStringFormat centerAlignment = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
newPage.Canvas.DrawString("11P18K6",font, brush, newPage.Canvas.ClientSize.Width / 2, 70, centerAlignment);
//save
pdf.SaveToFile("C:\\Users\\T\\Desktop\\1.pdf");
//print
pdf.PrintSettings.PrinterName = printerName;
pdf.PrintSettings.Copies = copies;
pdf.Print();
I got correct pdf file on desktop (and print it without any problems), but printer print labels from my application with incorect orientation and use 4 labels not 1. Where i make a misstake?