如何打印指定尺寸的文档 [英] How Can I Print A Document With Specified Size

查看:137
本文介绍了如何打印指定尺寸的文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要打印指定尺寸的文档,例如宽度18.5厘米和高度16.5厘米.还有一个问题,我如何打印多个文档.

我的代码在下面给出

I need to print a document with specified size say width 18.5cm and height 16.5cm. and one more question how can i print multiple document.

my code is given below

class PrintClass:BasicClass
{
public void print()
{

    PrintDialog pd = new PrintDialog();
    PrintDocument pdoc = new PrintDocument();
    PrinterSettings ps = new PrinterSettings();
    PaperSize psize = new PaperSize();
    pdoc.DefaultPageSettings.Landscape = true;
    pd.Document = pdoc;
    pd.Document.DefaultPageSettings.PaperSize = psize;
    pdoc.PrintPage += new PrintPageEventHandler(pdoc_PrintPage);

    DialogResult result = pd.ShowDialog();
    if (result == DialogResult.OK)
    {
        PrintPreviewDialog ppd = new PrintPreviewDialog();
        ppd.Document = pdoc;
        ppd.PrintPreviewControl.Zoom = 1.5;
        ((Form)ppd).WindowState = FormWindowState.Maximized;
        DialogResult ppdResult = ppd.ShowDialog();

    }
}
void pdoc_PrintPage(object sender, PrintPageEventArgs e)
{
    Graphics g = e.Graphics;
    //string str1 = "XYZ";
    //Font fnt1 = new Font("Arial", 12.5f);            
    g.DrawString(str, fnt, new SolidBrush(Color.Black), 10, 10);

}
}

推荐答案

好吧,您可以从使用具有纸张大小的重载构造函数开始:
Well, you could start by using the overloaded constructor that takes a paper size: PaperSize Constructor (String, Int32, Int32)[^] instead of the default constructor.

[edit]Typos[/edit]


这篇关于如何打印指定尺寸的文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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