windows打印以page方式驱动打印机,行方式驱动需调用API或用种变通的方式。
方法一
简单的写到一个文件里然后
System.Diagnostics.Process.Start("cmd"," /c copy d:\1.txt prn")
输出重定向简单易行打个receipt啥的足够用,就是感觉很业余,呵呵。
方法二
这个就要用几个API 了
Class RawPrinterHelper
using
System;
using System.IO;
using System.Drawing.Printing;
using System.Runtime.InteropServices;
public class RawPrinterHelper
{
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
public struct DOCINFOW
{
[MarshalAs(UnmanagedType.LPWStr)]
public string pDocName;
[MarshalAs(UnmanagedType.LPWStr)]
public string pOutputFile;
[MarshalAs(UnmanagedType.LPWStr)]
public string pDataType;
}
[DllImport("winspool.Drv", EntryPoint="OpenPrinterW", CallingConvention=CallingConvention.StdCall, CharSet=CharSet.Unicode, SetLastError=true, ExactSpelling=true)]
public static extern bool OpenPrinter(string src, ref IntPtr hPrinter, long pd);
using System.IO;
using System.Drawing.Printing;
using System.Runtime.InteropServices;
public class RawPrinterHelper
{
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
public struct DOCINFOW
{
[MarshalAs(UnmanagedType.LPWStr)]
public string pDocName;
[MarshalAs(UnmanagedType.LPWStr)]
public string pOutputFile;
[MarshalAs(UnmanagedType.LPWStr)]
public string pDataType;
}
[DllImport("winspool.Drv", EntryPoint="OpenPrinterW", CallingConvention=CallingConvention.StdCall, CharSet=CharSet.Unicode, SetLastError=true, ExactSpelling=true)]
public static extern bool OpenPrinter(string src, ref IntPtr hPrinter, long pd);