0

i'm trying to print an image of 4"*6" (10*15 cm) from my C# code through a MITSUBISHI CPD90D printer, using paper type CK-D868.

i've already printed images through this printer via windows, and now i'm trying to print via code.

the error i'm getting when attempting to run my code is

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

here's my code:

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

any help would be greatly appreciated!

Thanks, Nir

nir weiner
  • 305
  • 3
  • 10
  • 1
    Can you specify a PaperType? – Sebastian L Oct 05 '16 at 13:43
  • paper type is CK-D868 (edited in comment too) – nir weiner Oct 06 '16 at 06:13
  • Do you find a solution? how ? i have the same problem and i find that: https://social.msdn.microsoft.com/Forums/en-US/6abb54d7-167a-406e-bce5-8b3d00cebd9c/print-document-setting-paper-size-and-printable-area?forum=vbpowerpacks – barpas Jul 03 '19 at 20:44
  • @barpas we did find a solution eventually, but it was a long time ago, and i have no way of locating it. as far as i can recall, it had something to do with some config in the code, but i can't remember more at this time. sorry.. – nir weiner Jul 05 '19 at 07:38

1 Answers1

0

we utilized .Net's System.Drawing.Printing, so our modified (and working) code looks like this:

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

the problem had something to do with the appropriate paper size, so here's the full list:

 //             * 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}
nir weiner
  • 305
  • 3
  • 10