Printing custom paper size on a remote printer in WPF

I print to a remote printer loaded with 8.5 x 8.5 paper . When I print, the printer ejects 11 inches instead of 8.5.

PageMediaSize pageSize = new PageMediaSize(PageMediaSizeName.Unknown, element.Width, element.Height);

PrintDialog dialog = new PrintDialog();
dialog.PrintTicket.PageMediaSize = pageSize;
Console.WriteLine(dialog.PrintableAreaHeight); // 816, good!
dialog.PrintQueue = myQueue;                   // selected from a combobox
Console.WriteLine(dialog.PrintableAreaHeight); // 1056 :(

dialog.PrintVisual(element, description);

Usage How to convert Twips to Pixels to .NET? “I determined that 8.5 inches is 816 pixels, which is the size of my element.Widthand element.Height. I am setting a new one PageMediaSize, but this does not seem to have an effect, dialog.PrintableAreaHeightit still ends at 1056 when I set the queue in the dialog box.

If I do dialog.ShowDialog(), manually select my printer and manually locate and resize the paper in your advanced printer settings, then dialog.PrintableAreaHeightcorrectly reflect the change.

This page http://go4answers.webhost4life.com/Example/set-printdialogs-default-page-size-168976.aspx suggests that I can only install PageMediaSizesupported by my printer. Using the function GetPrintCapabilitieson mine PrintQueue, I see a list of 10 or so page sizes, none of which are 8.5 x 8.5. This is the same list that I see when I go to my printer settings in Windows.

+5
source share
1 answer

Please find the code below, it sets the paper size as needed

        var printerSettings = new PrinterSettings();
        var labelPaperSize = new PaperSize { RawKind = (int)PaperKind.A6, Height = 148, Width = 105 };
        printerSettings.DefaultPageSettings.PaperSize = labelPaperSize;
        var labelPaperSource = new PaperSource { RawKind = (int)PaperSourceKind.Manual };
        printerSettings.DefaultPageSettings.PaperSource = labelPaperSource;
        if (printerSettings.CanDuplex)
        {
            printerSettings.Duplex = Duplex.Default;
        }
+2
source

All Articles