自己调。我给你一个Api打印的方式的。。没有字的地方打空格 [StructLayout( LayoutKind.Sequential)] public struct DOCINFO { [MarshalAs(UnmanagedType.LPWStr)]public string pDocName; [MarshalAs(UnmanagedType.LPWStr)]public string pOutputFile; [MarshalAs(UnmanagedType.LPWStr)]public string pDataType; } public class PrintDirect { [ DllImport( "winspool.drv",CharSet=CharSet.Unicode,ExactSpelling=false, CallingConvention=CallingConvention.StdCall )] public static extern long OpenPrinter(string pPrinterName,ref IntPtr phPrinter, int pDefault);
[ DllImport( "winspool.drv",CharSet=CharSet.Unicode,ExactSpelling=false, CallingConvention=CallingConvention.StdCall )] public static extern long StartDocPrinter(IntPtr hPrinter, int Level, ref DOCINFO pDocInfo);
[ DllImport( "winspool.drv",CharSet=CharSet.Unicode,ExactSpelling=true, CallingConvention=CallingConvention.StdCall)] public static extern long StartPagePrinter(IntPtr hPrinter);
[ DllImport( "winspool.drv",CharSet=CharSet.Ansi,ExactSpelling=true, CallingConvention=CallingConvention.StdCall)] public static extern long WritePrinter(IntPtr hPrinter,string data, int buf,ref int pcWritten);
[ DllImport( "winspool.drv" ,CharSet=CharSet.Unicode,ExactSpelling=true, CallingConvention=CallingConvention.StdCall)] public static extern long EndPagePrinter(IntPtr hPrinter);
[ DllImport( "winspool.drv" ,CharSet=CharSet.Unicode,ExactSpelling=true, CallingConvention=CallingConvention.StdCall)] public static extern long EndDocPrinter(IntPtr hPrinter);
[ DllImport( "winspool.drv",CharSet=CharSet.Unicode,ExactSpelling=true, CallingConvention=CallingConvention.StdCall )] public static extern long ClosePrinter(IntPtr hPrinter);// [ DllImport( "tty.drv",CharSet=CharSet.Unicode,ExactSpelling=true, // CallingConvention=CallingConvention.StdCall )] // public static extern long Currentx(int x); // // [ DllImport( "tty.drv",CharSet=CharSet.Unicode,ExactSpelling=true, // CallingConvention=CallingConvention.StdCall )] // public static extern long Currenty(int y); }
我的打印机是松下的一款很老的型号,具体型号不清楚.
[StructLayout( LayoutKind.Sequential)]
public struct DOCINFO
{
[MarshalAs(UnmanagedType.LPWStr)]public string pDocName;
[MarshalAs(UnmanagedType.LPWStr)]public string pOutputFile;
[MarshalAs(UnmanagedType.LPWStr)]public string pDataType;
}
public class PrintDirect
{
[ DllImport( "winspool.drv",CharSet=CharSet.Unicode,ExactSpelling=false,
CallingConvention=CallingConvention.StdCall )]
public static extern long OpenPrinter(string pPrinterName,ref IntPtr phPrinter, int pDefault);
[ DllImport( "winspool.drv",CharSet=CharSet.Unicode,ExactSpelling=false,
CallingConvention=CallingConvention.StdCall )]
public static extern long StartDocPrinter(IntPtr hPrinter, int Level, ref DOCINFO pDocInfo);
[ DllImport( "winspool.drv",CharSet=CharSet.Unicode,ExactSpelling=true,
CallingConvention=CallingConvention.StdCall)]
public static extern long StartPagePrinter(IntPtr hPrinter);
[ DllImport( "winspool.drv",CharSet=CharSet.Ansi,ExactSpelling=true,
CallingConvention=CallingConvention.StdCall)]
public static extern long WritePrinter(IntPtr hPrinter,string data, int buf,ref int pcWritten);
[ DllImport( "winspool.drv" ,CharSet=CharSet.Unicode,ExactSpelling=true,
CallingConvention=CallingConvention.StdCall)]
public static extern long EndPagePrinter(IntPtr hPrinter);
[ DllImport( "winspool.drv" ,CharSet=CharSet.Unicode,ExactSpelling=true,
CallingConvention=CallingConvention.StdCall)]
public static extern long EndDocPrinter(IntPtr hPrinter);
[ DllImport( "winspool.drv",CharSet=CharSet.Unicode,ExactSpelling=true,
CallingConvention=CallingConvention.StdCall )]
public static extern long ClosePrinter(IntPtr hPrinter);// [ DllImport( "tty.drv",CharSet=CharSet.Unicode,ExactSpelling=true,
// CallingConvention=CallingConvention.StdCall )]
// public static extern long Currentx(int x);
//
// [ DllImport( "tty.drv",CharSet=CharSet.Unicode,ExactSpelling=true,
// CallingConvention=CallingConvention.StdCall )]
// public static extern long Currenty(int y);
}