领导分配了一个任务,利用c#连接打印机,打印一个html页面,对于一个Java本专业还不太熟练的我,之前从未接触过c#,挑战还是很大的。
但是没办法,做呗!!!
首先找一个写c#的工具呗,所以下载了vs2015,实现方法如下:
1、新建一个form项目
2、form中集成一个webbrower控件去显示html
3、html中js调用c#中的打印方法,实现打印
4、打印的时候,如何设置自定义的页面设置,如页眉页脚、页边距、背景颜色等,找了很多方法,各种尝试,通过修改注册表来实现
5、html中的js就可以调用Print()方法啦
代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing.Printing;
using System.Runtime.InteropServices;
using System.Collections;
using System.IO;
using Microsoft.Win32;
namespace printCar
{
[System.Runtime.In