Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Sat May 20, 2023 10:18 am

I'm start to learn Spire PDF from simple task... I have sticker printer with 100mm x 50mm landscape labels and i try to print text on center of label. There is code:
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?

sLogistics
 
Posts: 1
Joined: Sat May 20, 2023 10:04 am

Mon May 22, 2023 2:44 am

Hi,

Thank you for reaching out to us regarding the printer settings.
You can use the following code to control the orientation of the printer.
Code: Select all
pdf.PrintSettings.Landscape = true;

Regarding your another question, did you mean the number of copies is incorrect? If not, could you please explain it more clearly or share us with some screenshots for our reference? In addition, if you are not using the latest Spire.PDF_9.4.12, we recommend that you download it and have a test.

Best regards,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Return to Spire.PDF

cron