我试图打印一个4"*6“(10*15厘米)的图像从我的C#代码通过三菱CPD90D打印机,使用纸类型CK-D868。
我已经通过这台打印机通过窗口打印了图像,现在我正在尝试通过代码打印。
当我试图运行我的代码时,我遇到的错误是
“打印机驱动器的纸张大小与墨带类型不匹配”
这是我的密码:
public void Print(string imagePath, int copies)
{
var doc = new PrintDocument();
PrintController printController = new StandardPrintController();
doc.PrintController = printController;
doc.PrinterSettings.PrinterName = PhotosConfig.PrinterName;
doc.PrinterSettings.Copies = (short)copies;
doc.PrinterSettings.DefaultPageSettings.PaperSize = new PaperSize("10x15x2(4x6\"x2)", 100, 150);
doc.PrinterSettings.DefaultPageSettings.Margins = new Margins(0,0,0,0);
doc.DefaultPageSettings.PaperSize = new PaperSize("10x15x2(4x6\"x2)", 100, 150);
doc.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);
doc.OriginAtMargins = true;
doc.PrintPage += (sender, args) =>
{
Image i = Image.FromFile(imagePath);
//Point p = new Point();
args.Graphics.DrawImage(i, args.MarginBounds);
};
doc.Print();
}任何帮助都将不胜感激!
谢谢你,尼尔
发布于 2019-07-07 08:29:56
我们使用了.NET的System.Drawing.Printing,因此我们修改的(和工作的)代码如下所示:
var doc =新PrintDocument();var printController =新StandardPrintController();
var ps = new PrinterSettings
{
PrinterName = PhotosConfig.PhotosPrinterName,
Copies = (short)copies,
DefaultPageSettings =
{
Landscape = true,
Margins = new Margins()
{
Top = 0,
Bottom = 0,
Left = 0,
Right = 0
}
}
};
doc.OriginAtMargins = false;
doc.PrinterSettings = ps;
doc.PrintController = printController;
doc.DefaultPageSettings.PaperSize = ps.PaperSizes[1]; var doc = new PrintDocument();
var printController = new StandardPrintController();
var ps = new PrinterSettings
{
PrinterName = PhotosConfig.PhotosPrinterName,
Copies = (short)copies,
DefaultPageSettings =
{
Landscape = true,
Margins = new Margins()
{
Top = 0,
Bottom = 0,
Left = 0,
Right = 0
}
}
};
doc.OriginAtMargins = false;
doc.PrinterSettings = ps;
doc.PrintController = printController;
doc.DefaultPageSettings.PaperSize = ps.PaperSizes[1];
doc.PrintPage += (sender, args) =>
{
var i = Image.FromFile(imagePath);
args.Graphics.DrawImage(i, args.MarginBounds);
};
doc.Print();这个问题与适当的纸张大小有关,下面是完整的列表:
// * paper sizes:
// [0] {[PaperSize 9x13(3.5x5") Kind=Custom Height=520 Width=362]} object {System.Drawing.Printing.PaperSize}
//+ [1] {[PaperSize 10x15(4x6") Kind=Custom Height=618 Width=409]} object {System.Drawing.Printing.PaperSize}
//+ [2] {[PaperSize 13x18(5x7") Kind=Custom Height=713 Width=520]} object {System.Drawing.Printing.PaperSize}
//+ [3] {[PaperSize 15x20(6x8") Kind=Custom Height=811 Width=618]} object {System.Drawing.Printing.PaperSize}
//+ [4] {[PaperSize 15x21(6x8.5") Kind=Custom Height=858 Width=618]} object {System.Drawing.Printing.PaperSize}
//+ [5] {[PaperSize 15x23 (6x9") Kind=Custom Height=913 Width=618]} object {System.Drawing.Printing.PaperSize}
//+ [6] {[PaperSize 10x15x2 (4x6"x2) Kind=Custom Height=831 Width=618]} object {System.Drawing.Printing.PaperSize}
//+ [7] {[PaperSize 5x15x2 Type1(2x6"x2) Kind=Custom Height=618 Width=409]} object {System.Drawing.Printing.PaperSize}
//+ [8] {[PaperSize 5x15x2 Type2(2x6"x2) Kind=Custom Height=618 Width=205]} object {System.Drawing.Printing.PaperSize}
//+ [9] {[PaperSize 5x15(2x6") Kind=Custom Height=618 Width=209]} object {System.Drawing.Printing.PaperSize}
//+ [10] {[PaperSize 15x15(6x6") Kind=Custom Height=618 Width=610]} object {System.Drawing.Printing.PaperSize}
//+ [11] {[PaperSize 13x13(5x5") Kind=Custom Height=520 Width=512]} object {System.Drawing.Printing.PaperSize}
//+ [12] {[PaperSize 9x13(3.5x5") white border Kind=Custom Height=520 Width=362]} object {System.Drawing.Printing.PaperSize}
//+ [13] {[PaperSize 10x15(4x6") white border Kind=Custom Height=618 Width=413]} object {System.Drawing.Printing.PaperSize}
//+ [14] {[PaperSize 13x18(5x7") white border Kind=Custom Height=713 Width=520]} object {System.Drawing.Printing.PaperSize}
//+ [15] {[PaperSize 15x20(6x8") white border Kind=Custom Height=811 Width=618]} object {System.Drawing.Printing.PaperSize}
//+ [16] {[PaperSize 15x23(6x9") white border Kind=Custom Height=913 Width=618]} object {System.Drawing.Printing.PaperSize}https://stackoverflow.com/questions/39875534
复制相似问题