Changing paper size when printing label on Brother printer in C#

938 Views Asked by At

I have a Brother PT9800PCN which uses tapes (6 mm to 36 mm) to print labels.

In an Windows Form App I have various buttons that when clicked should print a certain file (pdf) to the printer. Depending on the file, different tapes are required. Sizes are take using values from text boxes where I specify the size I need.

My issue is, that when I specify the page size, it prints on what ever is set in the printers preferences as default.

I've set printer preferences to 18 mm size tape and 50 mm length.

I've fitted a 24 mm tape in the printer and in the code I'm setting the page size to 24x50 mm.

When I click to print, the printer flashes red that I have the wrong size tape fitted.

In the printers settings, I've also saved some custom size under different names.

Tried setting RawKind to 0 and to something higher than 119, no luck.

        PdfiumViewer.PdfDocument pdfiumDoc = PdfiumViewer.PdfDocument.Load(file);
        PrintDocument pd = pdfiumDoc.CreatePrintDocument(PdfiumViewer.PdfPrintMode.CutMargin);
        pd.PrinterSettings.PrinterName = comboPrinters.SelectedItem.ToString();
        pd.PrinterSettings.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);
        pd.PrinterSettings.DefaultPageSettings.Landscape = true;
        pd.PrinterSettings.DefaultPageSettings.PaperSize.RawKind = 0;
        //pd.PrinterSettings.DefaultPageSettings.PaperSize.PaperName = "customSize";
        pd.PrinterSettings.DefaultPageSettings.PaperSize = new PaperSize("customSize", (int)Math.Round((double)Convert.ToInt32(textBox1.Text) * 500 / 127), (int)Math.Round((double)Convert.ToInt32(textBox2.Text) * 500 / 127));
        pd.Print();
0

There are 0 best solutions below