如何设置页面大小

我正在打印文档并尝试更改纸张大小,但它不起作用。


当我添加纸张尺寸时,它会以默认尺寸打印文档。我的纸张尺寸不起作用。


namespace WC_manager

{

    public partial class tagprint : Form

    {

        Zen.Barcode.Code39BarcodeDraw objCode = Zen.Barcode.BarcodeDrawFactory.Code39WithChecksum;

        int tagNo = 0;

        PrinterSettings ps = new PrinterSettings();

        public tagprint()

        {

            InitializeComponent();

        }


        private void label1_Click(object sender, EventArgs e)

        {    

        }


        private void printBtn_Click(object sender, EventArgs e)

        {

            if(tagNo != 0)

            {                    

                pictureBox1.Image = objCode.Draw(Convert.ToString(tagNo), 100);

                var doc = new PrintDocument();


                doc.PrintPage += new PrintPageEventHandler(ProvideContent);

                doc.PrinterSettings.PrinterName = "Adobe PDF";

                doc.DefaultPageSettings.PaperSize = new PaperSize("Custom",10,10);


                doc.Print();

            }

            else

            {

                MessageBox.Show("Enter Valid Tag no");

            }

        }


        private void tagTxtFld_TextChanged(object sender, EventArgs e)

        {

            tagNo = Convert.ToInt32(tagTxtFld.Text);

        }


        public void ProvideContent(object sender, PrintPageEventArgs e)

        {

            Graphics graphics = e.Graphics;

            Font font = new Font("Courier New", 10);

            float fontHeight = font.GetHeight();


            graphics.DrawImage(objCode.Draw(Convert.ToString(tagNo), 20), 0, 2, 30, 30);

        }

    }

}


慕少森
浏览 65回答 2
2回答

慕标琳琳

我之所以遇到这个问题,只是因为我以 pdf 格式输出,所以这就是它设置默认页面大小的原因。当更改打印机名称时。我得到了输出。

守着一只汪

您没有指定合理的纸张尺寸尺寸:doc.DefaultPageSettings.PaperSize = new PaperSize("Custom",10,10);第二个和第三个参数分别是纸张的宽度和高度。但重要的是,这些值的单位始终是百分之一英寸。因此,您已要求打印机驱动程序打印只有 1/10 英寸宽和高的页面。当我使用已安装的 PDF 驱动程序尝试此操作时,它会忽略提供的大小,并打印到标准 Letter 大小(即 8.5 x 11 英寸)的页面。如果这是您的实际意思,那么您需要使用可以接受该尺寸纸张的打印机。你可能会发现这样做很困难。但是,更有可能的是,您打算使用其他尺寸。例如,如果您尝试在 10 英寸见方的页面上打印,则需要传递每个值。或者,如果您尝试在 10 厘米见方的页面上打印,则需要传递每个值(并接受实际上只是略高于 10 厘米的事实)。1000394底线:传递纸张宽度和高度的有效值,它就会起作用。百分之十英寸对于这两个参数中的任何一个都不是有效值。
打开App,查看更多内容
随时随地看视频慕课网APP