打印自定义纸张尺寸在WPF击打式打印机 [英] Printing custom paper size to an impact printer in WPF

查看:4222
本文介绍了打印自定义纸张尺寸在WPF击打式打印机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打印到击打式打印机,满载 8.5×8.5 英寸的纸张。当我打印时,打印机弹出11英寸,而不是8.5。

I'm printing to an impact printer, loaded with 8.5 x 8.5 inch 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);

使用如何转换为缇像素.NET? 我已经确定,8.5英寸是816像素,这是我的 element.Width element.Height 。我设置一个新的 PageMediaSize ,但这似乎没有任何效果, dialog.PrintableAreaHeight 在1056当我设置对话框上的队列仍然结束。

Using "How do I convert Twips to Pixels in .NET?" I've determined that 8.5 inches is 816 pixels, which is the size of my element.Width and element.Height. I'm setting a new PageMediaSize, but this seems to have no effect, dialog.PrintableAreaHeight is still ends up at 1056 when I set the queue on the dialog.

如果我 dialog.ShowDialog(),手工挑我的打印机,然后手动查找并更改纸张大小在我的打印机的高级设置,然后 dialog.PrintableAreaHeight 正确反映的变化。

If I do dialog.ShowDialog(), manually pick my printer, and manually find and change Paper Size in my printer's advanced settings, then dialog.PrintableAreaHeight properly reflects the change.

本页面的http:/ /go4answers.webhost4life.com/Example/set-printdialogs-default-page-size-168976.aspx 表明,我只能设置一个 PageMediaSize 以支持我打印机。用 GetPrintCapabilities 函数我的打印队列,我看到10个左右的页面大小,其中没有一个是8.5的列表点¯x8.5。这是相同的列表我看到,当我去我的打印机的高级设置中的窗口。

This page http://go4answers.webhost4life.com/Example/set-printdialogs-default-page-size-168976.aspx suggests that I can only set a PageMediaSize supported by my printer. Using the GetPrintCapabilities function on my 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 I see when I go to my printer's advanced settings in windows.

推荐答案

请找到下面的代码,它按要求设置纸张尺寸

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

        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;
        }

这篇关于打印自定义纸张尺寸在WPF击打式打印机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆