我该如何设置纸张类型,同时使用PrinterDialog? [英] how do I set Paper Type while using PrinterDialog?

查看:313
本文介绍了我该如何设置纸张类型,同时使用PrinterDialog?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想静静地打印图片文件,我需要打印特殊纸张类型(光面相纸),并在一定规模的(10厘米的15厘米)。

I'm trying to silently print a picture file and i need to print it on special paper type ("Glossy Photo Paper"), and on certain size (10cm on 15cm).

在正常的Windows 7打印对话框我可以选择:

On normal windows 7 print dialog i can choose:

纸张的尺寸

质量(例如 - 自动,高,标准,自定义)

Paper Quality (for example - "Auto", "High", "Standard", "Custom")

键入(普通纸,光泽照片纸,高级光面照片纸,专业照片纸铂金,明信片,等...)

Paper Type ("Plain paper", "Glossy photo paper", "Photo Paper Plus Glossy", "Photo Paper Pro Platinum", "Hagaki", etc...)

不过,通过C#代码,我已经成功地设置只在 PAPERSIZE (也就是4''6''==10厘米上15厘米)。

But, through c# code, I've managed to set only the PaperSize (which is 4'' on 6'' == 10cm on 15cm).

我的问题是我如何去设置纸张的键入和不可以 PaperSource (纸盘1,盘2等)......

My problem is how do i get the option to set the Paper Type, and not the PaperSource ("Tray 1", "Tray 2", etc)....

我知道每个打印机,它支持它自己的纸张类型,所以我可能需要通过这一切来迭代,但我只是无法弄清楚它是如何

I know that every printer has its own Paper Types which it supports, so i probably need to iterate through it all, but I just couldn't figure it how.

这是我当前的代码:

string strPrinterName = "Canon iP4850";

PrintDocument printDoc = new PrintDocument();

// We set the paper size
printDoc.DefaultPageSettings.PaperSize = new PaperSize("PhotoPaper", 400, 600);

// Inside the event i actually draw the image all over the paper by using e.Graphics.DrawImage(...)
printDoc.PrintPage += PrintDocPrintPage;

// Creating the print dialog
PrintDialog dlgPrint = new PrintDialog
{
    Document = printDoc
};

// We choose the printer
dlgPrint.PrinterSettings.PrinterName = strPrinterName;

// just to be sure - give the new size of our paper
dlgPrint.PrinterSettings.DefaultPageSettings.PaperSize = new PaperSize("PhotoPaper", 400, 600);

// If the printer is invalid
if (!dlgPrint.PrinterSettings.IsValid)
{
    throw new Exception(@"Printer is invalid" + Environment.NewLine + strPrinterName);
}

// Print without showing the dialog
printDoc.Print();



谢谢大家提前。

thank you all in advance.

推荐答案

我并不是说这是不可能的,但它不会是漂亮。理论上可以得到的设备的DEVMODE结构(该结构将具有特定于打印机驱动程序扩展)设置为正确的值,然后将它写回。还有一些辅助功能的PrinterSettings对象来做到这一点。有这样做的这里

I'm not saying that it is impossible, but its not going to be pretty. Theoretically you can get the DEVMODE structure of the device( that structure will have extensions that are specific to the printer driver) set the correct values, and then write it back. There are some helper functions the the PrinterSettings object to do this. There is an example of doing that here

这篇关于我该如何设置纸张类型,同时使用PrinterDialog?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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