下面的代碼可以通過調用WIN
// PrintDirect
// 本文參考了Microsoft Support 文檔號
// 本代碼假定你在file://
// 本代碼示例了如何向打印機發送Hewlett Packard PCL
using System;
using System
using System
[StructLayout( LayoutKind
public struct DOCINFO
{
[MarshalAs(UnmanagedType
[MarshalAs(UnmanagedType
[MarshalAs(UnmanagedType
}
public class PrintDirect
{
[ DllImport(
CallingConvention=CallingConvention
public static extern long OpenPrinter(string pPrinterName
int pDefault);
[ DllImport(
CallingConvention=CallingConvention
public static extern long StartDocPrinter(IntPtr hPrinter
ref DOCINFO pDocInfo);
[ DllImport(
CallingConvention=CallingConvention
public static extern long StartPagePrinter(IntPtr hPrinter);
[ DllImport(
CallingConvention=CallingConvention
public static extern long WritePrinter(IntPtr hPrinter
int buf
[ DllImport(
CallingConvention=CallingConvention
public static extern long EndPagePrinter(IntPtr hPrinter);
[ DllImport(
CallingConvention=CallingConvention
public static extern long EndDocPrinter(IntPtr hPrinter);
[ DllImport(
CallingConvention=CallingConvention
public static extern long ClosePrinter(IntPtr hPrinter);
}
public class App
{
public static void Main ()
{
System
DOCINFO di = new DOCINFO();
int pcWritten=
string st
// text to print with a form feed character
st
di
di
// the \x
st
//lhPrinter contains the handle for the printer opened
//If lhPrinter is
PrintDirect
PrintDirect
PrintDirect
try
{
// Moves the cursor
//
st
PrintDirect
// Using the print model commands for rectangle dimensions
// with a horizontal size or width of
// size or height of
st
PrintDirect
// Specifies a rectangle with width of
// fill pattern of solid black
st
PrintDirect
// Moves the current cursor position to
//
st
PrintDirect
// Specifies a rectangle with a width of
// fill pattern of solid black
st
PrintDirect
// Moves the current cursor position to
//
st
PrintDirect
// Specifies a rectangle with a width of
// fill pattern of solid black
st
PrintDirect
// Send a form feed character to the printer
st
PrintDirect
}
catch (Exception e)
{
Console
}
PrintDirect
PrintDirect
PrintDirect
}
}
From:http://tw.wingwit.com/Article/program/net/201311/12794.html