RawPrinter Helper:打印机不打印泰米尔语字符
RawPrinter Helper: Printer not printing Tamil characters
正在尝试在热敏打印机中打印泰米尔语字符。并得到'????'或任何其他垃圾字符。
我使用的代码如下。
Print(eInit + 'நன்றி');
public void Print(string Line)
{
prn.SendStringToPrinter(PrinterName, Line);
}
public bool SendStringToPrinter(string szPrinterName, string szString)
{
bool functionReturnValue = false;
if (PrinterOpen)
{
IntPtr pBytes = default(IntPtr);
Int32 dwCount = default(Int32);
Int32 dwWritten = 0;
dwCount = szString.Length;
pBytes = Marshal.StringToCoTaskMemAnsi(szString);
functionReturnValue = WritePrinter(hPrinter, pBytes, dwCount, ref dwWritten);
Marshal.FreeCoTaskMem(pBytes);
}
else
{
functionReturnValue = false;
}
return functionReturnValue;
}
原始打印机助手 class 不会通过 sensstringtoprinter() class 打印泰米尔语字符。
设计一个 crystal 报告 select 您的字段并将字体设置为任何泰米尔语字体(例如 bamini 字体)并调用此报告以在按钮单击事件时从您的应用程序打印。
我知道这已经过时了,但为了让遇到此问题的其他人参考,让我 post 可能的解决方案。
public static bool SendStringToPrinterUTF8(string szPrinterName, string szString)
{
byte[] byteArray = Encoding.UTF8.GetBytes(szString);
MemoryStream stream = new MemoryStream(byteArray);
BinaryReader br = new BinaryReader(stream);
Byte[] bytes = new Byte[stream.Length];
IntPtr pUnmanagedBytes = new IntPtr(0);
int nLength;
nLength = Convert.ToInt32(stream.Length);
bytes = br.ReadBytes(nLength);
pUnmanagedBytes = Marshal.AllocCoTaskMem(nLength);
Marshal.Copy(bytes, 0, pUnmanagedBytes, nLength);
SendBytesToPrinter(szPrinterName, pUnmanagedBytes, nLength);
Marshal.FreeCoTaskMem(pUnmanagedBytes);
return true;
}
public static bool SendBytesToPrinter(string szPrinterName, IntPtr pBytes, Int32 dwCount)
{
Int32 dwError = 0, dwWritten = 0;
IntPtr hPrinter = new IntPtr(0);
DOCINFOA di = new DOCINFOA();
bool bSuccess = false; // Assume failure unless you specifically succeed.
di.pDocName = "Printing UCC Labels";
di.pDataType = "RAW";
// Open the printer.
if (OpenPrinter(szPrinterName.Normalize(), out hPrinter, IntPtr.Zero))
{
// Start a document.
if (StartDocPrinter(hPrinter, 1, di))
{
// Start a page.
if (StartPagePrinter(hPrinter))
{
// Write your bytes.
bSuccess = WritePrinter(hPrinter, pBytes, dwCount, out dwWritten);
EndPagePrinter(hPrinter);
}
EndDocPrinter(hPrinter);
}
ClosePrinter(hPrinter);
}
// If you did not succeed, GetLastError may give more information
// about why not.
if (bSuccess == false)
{
dwError = Marshal.GetLastWin32Error();
}
return bSuccess;
}
正在尝试在热敏打印机中打印泰米尔语字符。并得到'????'或任何其他垃圾字符。 我使用的代码如下。
Print(eInit + 'நன்றி');
public void Print(string Line)
{
prn.SendStringToPrinter(PrinterName, Line);
}
public bool SendStringToPrinter(string szPrinterName, string szString)
{
bool functionReturnValue = false;
if (PrinterOpen)
{
IntPtr pBytes = default(IntPtr);
Int32 dwCount = default(Int32);
Int32 dwWritten = 0;
dwCount = szString.Length;
pBytes = Marshal.StringToCoTaskMemAnsi(szString);
functionReturnValue = WritePrinter(hPrinter, pBytes, dwCount, ref dwWritten);
Marshal.FreeCoTaskMem(pBytes);
}
else
{
functionReturnValue = false;
}
return functionReturnValue;
}
原始打印机助手 class 不会通过 sensstringtoprinter() class 打印泰米尔语字符。 设计一个 crystal 报告 select 您的字段并将字体设置为任何泰米尔语字体(例如 bamini 字体)并调用此报告以在按钮单击事件时从您的应用程序打印。
我知道这已经过时了,但为了让遇到此问题的其他人参考,让我 post 可能的解决方案。
public static bool SendStringToPrinterUTF8(string szPrinterName, string szString)
{
byte[] byteArray = Encoding.UTF8.GetBytes(szString);
MemoryStream stream = new MemoryStream(byteArray);
BinaryReader br = new BinaryReader(stream);
Byte[] bytes = new Byte[stream.Length];
IntPtr pUnmanagedBytes = new IntPtr(0);
int nLength;
nLength = Convert.ToInt32(stream.Length);
bytes = br.ReadBytes(nLength);
pUnmanagedBytes = Marshal.AllocCoTaskMem(nLength);
Marshal.Copy(bytes, 0, pUnmanagedBytes, nLength);
SendBytesToPrinter(szPrinterName, pUnmanagedBytes, nLength);
Marshal.FreeCoTaskMem(pUnmanagedBytes);
return true;
}
public static bool SendBytesToPrinter(string szPrinterName, IntPtr pBytes, Int32 dwCount)
{
Int32 dwError = 0, dwWritten = 0;
IntPtr hPrinter = new IntPtr(0);
DOCINFOA di = new DOCINFOA();
bool bSuccess = false; // Assume failure unless you specifically succeed.
di.pDocName = "Printing UCC Labels";
di.pDataType = "RAW";
// Open the printer.
if (OpenPrinter(szPrinterName.Normalize(), out hPrinter, IntPtr.Zero))
{
// Start a document.
if (StartDocPrinter(hPrinter, 1, di))
{
// Start a page.
if (StartPagePrinter(hPrinter))
{
// Write your bytes.
bSuccess = WritePrinter(hPrinter, pBytes, dwCount, out dwWritten);
EndPagePrinter(hPrinter);
}
EndDocPrinter(hPrinter);
}
ClosePrinter(hPrinter);
}
// If you did not succeed, GetLastError may give more information
// about why not.
if (bSuccess == false)
{
dwError = Marshal.GetLastWin32Error();
}
return bSuccess;
}