尝试在热敏打印机中打印泰米尔字符。得到' ????'或任何其他垃圾字符。 我正在使用的代码如下。
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;
}
答案 0 :(得分:1)
原始打印机助手类不会通过sensstringtoprinter()类打印泰米尔语字符。 设计水晶报告选择您的字段并将字体设置为任何泰米尔字体(例如bamini字体),并在按钮点击事件中调用此报告从您的应用程序打印。
答案 1 :(得分:0)
我知道这已经很老了,但是对于其他遇到此问题的人来说,我可以提出可能的解决方案作为参考。
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;
}