来自 C# 的 MITSUBISHI CPD90D 打印机

MITSUBISHI CPD90D printer from C#

我正在尝试通过三菱 CPD90D 打印机使用我的 C# 代码打印一张 4"*6" (10*15 cm) 的图像,使用的纸张类型为 CK-D868。

我已经通过 windows 通过这台打印机打印图像,现在我正在尝试通过代码打印。

我尝试 运行 我的代码时遇到的错误是

'paper size of printer driver and ink ribbon type do not match'

这是我的代码:

  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();
    }

任何帮助将不胜感激!

谢谢, 尼尔

我们利用了 .Net 的 System.Drawing.Printing, 所以我们修改后的(和工作的)代码如下所示:

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]; 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}