用的是EPSON LQ-1600KIII,
代码是参照
http://www.cnblogs.com/zhanghl/archive/2005/09/08/232798.html
c#逐行打印的代码
打印中文正常,但中文无法识别。请高手赐教

解决方案 »

  1.   

    你可以使用这个 函数读取出 字符串后给
    打印调用试
    /// <summary>
            /// 得到文件内容
            /// </summary>
            /// <param name="TextFilePath">文件路径</param>
            /// <returns>文件内容字符串</returns>
            public static string IO_GetFileContent(string TextFilePath)
            {
                FileStream stream1 = new FileStream(TextFilePath, FileMode.Open, FileAccess.Read);
                byte[] buffer1 = new byte[(int)stream1.Length];
                stream1.Read(buffer1, 0, buffer1.Length);
                stream1.Close();
                return Encoding.Default.GetString(buffer1);
            }
    这个读取中文没问题.
      

  2.   

    我没有将之写到文件中,直接写成字符串,传至打印机。
    可能我没说清楚
    具体代码如下
    public class RawPrinterHelper
    {
    public RawPrinterHelper()
    {
    //
    // TODO: 在此处添加构造函数逻辑
    //
    }
    [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);
     
    [DllImport("winspool.Drv", CallingConvention=CallingConvention.StdCall, CharSet=CharSet.Unicode, SetLastError=true, ExactSpelling=true)]
    public static extern bool ClosePrinter(IntPtr hPrinter);
     
    [DllImport("winspool.Drv", EntryPoint="StartDocPrinterW", CallingConvention=CallingConvention.StdCall, CharSet=CharSet.Unicode, SetLastError=true, ExactSpelling=true)]
    public static extern bool StartDocPrinter(IntPtr hPrinter, int level, ref RawPrinterHelper.DOCINFOW pDI);
     
    [DllImport("winspool.Drv", EntryPoint="EndDocPrinter", SetLastError=true, CharSet=CharSet.Unicode, ExactSpelling=true, CallingConvention=CallingConvention.StdCall)] 
    public static extern bool EndDocPrinter(IntPtr hPrinter); 
         [DllImport("winspool.Drv", EntryPoint="StartPagePrinter", SetLastError=true, CharSet=CharSet.Unicode, ExactSpelling=true, CallingConvention=CallingConvention.StdCall)] 
    public static extern bool StartPagePrinter(IntPtr hPrinter) ;
         [DllImport("winspool.Drv", EntryPoint="EndPagePrinter", SetLastError=true, CharSet=CharSet.Unicode, ExactSpelling=true, CallingConvention=CallingConvention.StdCall)] 
    public static extern bool EndPagePrinter(IntPtr hPrinter) ;
         [DllImport("winspool.Drv", CallingConvention=CallingConvention.StdCall, CharSet=CharSet.Unicode, SetLastError=true, ExactSpelling=true)]
    public static extern bool WritePrinter(IntPtr hPrinter, IntPtr pBytes, int dwCount, ref int dwWritten);
     
    public static bool SendBytesToPrinter(string szPrinterName, IntPtr pBytes, Int32 dwCount) 

    IntPtr hPrinter =  System.IntPtr.Zero; 
    Int32 dwError; 
    DOCINFOW di = new DOCINFOW(); 
    Int32 dwWritten = 0; 
    bool bSuccess; 
    di.pDocName = "My Document"; 
    di.pDataType = "RAW"; 
    bSuccess = false; 
    if (OpenPrinter(szPrinterName,ref hPrinter, 0)) 

    if (StartDocPrinter(hPrinter, 1,ref di)) 

    if (StartPagePrinter(hPrinter)) 

    bSuccess = WritePrinter(hPrinter, pBytes, dwCount, ref dwWritten); 
    EndPagePrinter(hPrinter); 

    EndDocPrinter(hPrinter); 

    ClosePrinter(hPrinter); 

    if (bSuccess == false) 

    dwError = Marshal.GetLastWin32Error(); 

    return bSuccess;  } 

    public static void SendStringToPrinter(string szPrinterName, string szString) 

    IntPtr pBytes; 
    Int32 dwCount; 
    dwCount = szString.Length; 
    pBytes = Marshal.StringToCoTaskMemAnsi(szString); 
    SendBytesToPrinter(szPrinterName, pBytes, dwCount); 
    Marshal.FreeCoTaskMem(pBytes); 
    }  }然后调用
    private void button2_Click(object sender, System.EventArgs e)
    {
    string sPrintStr   = "测试"+"\u000A"; PrintDialog pd = new PrintDialog(); 
    pd.PrinterSettings = new PrinterSettings(); RawPrinterHelper.SendStringToPrinter(pd.PrinterSettings.PrinterName,"\u000A"+"测试"+"测试"); }
      

  3.   

    我所使用的开发环境是XP+VS2005(C#),在激光打印机上调试出现如下现象:
    1.下面非注释部分的DllImport导入的结果会令打印机一直在重复打印一行(非中文,中文则乱码)字符串,直到关掉打印机才停止。
            //[DllImport("winspool.Drv", EntryPoint = "OpenPrinterW", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = false)]
            //public static extern int OpenPrinter(string pPrinterName, out IntPtr phPrinter, IntPtr pDefault);        [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, Int32 pd);2.不能打印中文字符串曾参考过:      http://chenlong828.spaces.live.com/blog/cns!40CBBB8883708523!587.trak3.针式打印机曾测试过,但连OpenPrinter都是失败的,不明其因。但结果未能如愿,渴望得到您的帮助,头痛了N久,先谢谢了!