【发布时间】:2011-10-05 23:18:33
【问题描述】:
我正在尝试静默打印图片文件,我需要在特殊纸张类型(“光面相纸”)和特定尺寸(15cm 上 10cm)上打印它。
在普通的 Windows 7 打印对话框中,我可以选择:
纸张尺寸,
纸张质量(例如 - “Auto”、“High”、“Standard”、“Custom”)
纸张类型(“普通纸”、“光面照片纸”、“高级光面照片纸”、“专业白金照片纸”、“Hagaki”等)
但是,通过 c# 代码,我设法只设置了 PaperSize(即 4'' on 6'' == 10cm on 15cm)。
我的问题是如何获得设置纸张 Type 和 not PaperSource 的选项(“Tray 1”、“托盘 2" 等)....
我知道每台打印机都有自己支持的纸张类型,所以我可能需要遍历所有这些,但我就是想不通。
这是我当前的代码:
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();
提前谢谢大家。
【问题讨论】:
-
我并不是说这是不可能的,但它不会很漂亮。从理论上讲,您可以获得设备的 DEVMODE 结构(该结构将具有特定于打印机驱动程序的扩展名)设置正确的值,然后将其写回。 PrinterSettings 对象有一些辅助功能可以做到这一点。
-
类似link 的东西?我试试……
-
是的,这正是您需要做的。
-
我试过了,效果很好!谢谢。
标签: c# printing customization