C # Printers

Source: Internet
Author: User

Program Control printer Printing There is a problem, that is, do not print by default parameters.

Start with the following code to print, will pop-up Click Confirm dialog box, in order to not pop the window, the PrintDocument class printing

 // processstartinfo info = new Processstartin            Fo (@ "D:\Demo\picWorldCup\Test01.png");  /// /info. Arguments = string. Format ("-noquery-landscape-printer \" {0}\ "\" {1}\ ",  /// /"Canon MG3600 series Printer", @ "D:\Demo\picWorldCup\Test01.png");  // info.            Verb = "Print";  // info.            CreateNoWindow = true;  // info.            WindowStyle = Processwindowstyle.hidden;  // process.start (info);  

PrintDocument Print code as follows

    classProgram {Static voidMain (string[] args) {            //bool B = true; //ProcessStartInfo info = new ProcessStartInfo (@ "D:\Demo\picWorldCup\Test01.png");            ////info. Arguments = string. Format ("-noquery-landscape-printer \" {0}\ "\" {1}\ "",////"Canon MG3600 series Printer", @ "D:\Demo\picWorldCup\Test01.png");            //info.            Verb = "Print"; //info.            CreateNoWindow = true; //info.            WindowStyle = Processwindowstyle.hidden; //Process.Start (info); //string printwin = "Print picture"; //string printbtn = "Cancel"; //Stopwatch sw = new Stopwatch (); //SW.            Start (); //While (b)//{            //if (SW. ELAPSEDMILLISECONDS>200)//    {            //SW.            Stop (); //B = false; //    }            //}            //Apiutility.onrunclick (Printwin, printbtn);            stringPrintfile = args[0]; //string printername = args[1];            intwidth; intheight; if(!int. TryParse (args[1], outwidth)) {Width=355; }            if(!int. TryParse (args[2], outheight)) {Height= -; }            //Console.WriteLine ("Print Size:" + width + "" + height);PrintDocument PD =NewPrintDocument (); Pd. Printcontroller=NewStandardprintcontroller (); //Margins margin = new Margins (0, 0, 0, 0); //PD.            Defaultpagesettings.margins = margin; //PD.            Defaultpagesettings.color = false; //PD.            Defaultpagesettings.papersize = new PaperSize ("L", 44, 63); //PD.            Defaultpagesettings.margins = margin; //PD. Printersettings.printername = printername;PD. PrintPage+ = (o, e) = ={Image img=Image.FromFile (Printfile); intImgWidth = (int) (IMG. Height *0.7f); E.graphics.drawimage (IMG,NewRectangle (0,0, width, height),NewRectangle (0,0, ImgWidth, IMG. Height), GraphicsUnit.Pixel);//General//Console.WriteLine ("Image size:" + imgwidth + "" + img.)                Height); //e.graphics.drawimage (IMG, new Rectangle (0, 0, width, height), new Rectangle (0, 0, IMG. Width, IMG.                Height), GraphicsUnit.Pixel); //Console.WriteLine ("W:{0} H:{1}", IMG. Width, IMG. Height);            }; Try{PD.                Print (); Console.WriteLine ("Success"); }            Catch(Exception ex) {Console.WriteLine ("failed:"+Ex.            Message); }            //Btnprint_click ();Console.readkey (); }         Public Static voidBtnprint_click () {PrintDocument PD=NewPrintDocument (); Pd. Printcontroller=NewStandardprintcontroller (); //PD.            Originatmargins = true; //Margins margin = new Margins (0, 0, 0, 0); //PD.            Defaultpagesettings.color = false; //PD.            Defaultpagesettings.papersize = new PaperSize ("L", 89, 127); //PD.            Printersettings.printername = "Canon MG3600 series Printer"; //PD.            Printersettings.printername = "Microsoft Print to PDF"; //PD. Defaultpagesettings.margins = margin;Console.WriteLine ("Margin:"+PD.            Defaultpagesettings.margins); Console.WriteLine ("Bound:"+PD.            Defaultpagesettings.bounds); Console.WriteLine ("Xhardmargin:"+PD.            Defaultpagesettings.hardmarginx); Console.WriteLine ("Yhardmargin:"+PD.            Defaultpagesettings.hardmarginy); Pd. PrintPage+=PrintPage; Try{PD.            Print (); }            Catch(Exception ex) {Console.WriteLine ("Print Exception:"+Ex.            Message); }        }        Private Static voidPrintPage (Objecto, PrintPageEventArgs e) {Image img= Image.FromFile (@"D:\Demo\picWorldCup\005.png"); //int width = Int. Parse (IMG. Height * 0.7f). ToString ());            intwidth = (int) (IMG. Height *0.7f); //e.graphics.drawimage (IMG, new Rectangle (0, 0, +), new Rectangle (0, 0, Width, img.            Height), GraphicsUnit.Pixel); //e.graphics.drawimage (IMG, New Rectangle (0,0, +), new Rectangle (0,0, Width, img).            Height), GraphicsUnit.Pixel); //e.graphics.drawimage (IMG, new Rectangle (0, 0,,), new Rectangle (0, 0, Width, img. Height), graphicsunit.pixel);//Mobile Photos//e.graphics.drawimage (IMG, new Rectangle (0, 0, 355, $), new Rectangle (0, 0, IMG). Width, IMG. Height), graphicsunit.pixel);//ar photoE.graphics.drawimage (IMG,NewRectangle (0,0,355, -),NewRectangle (0,0, Width, img. Height), GraphicsUnit.Pixel);//General//e.graphics.drawimage (IMG, New Rectangle (0,0, 127), New Rectangle (0,0, Width, img).            Height), graphicsunit.millimeter); //e.graphics.drawimage (IMG, 0,0,width,img. Height);Console.WriteLine ("w:{0} h:{1}", IMG. Width, IMG.        Height); }    }

Where:defaultpagesettings parameter without code settings, some such as the page margin cannot be set (read-only), at this time as long as the settings-printer-set the printer's preferences parameters can be

C # Printers

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.