Mporeis na xrisimopoiseis kai tin pio kato clasi.
Prepei omos an theleis na olokliroseis tin function
ConvertWindowsToOEM437Greek(string sWindows) an theleis na tiponeis apo elinika 851 se elinika dot matrix 437
sing System;
using System.IO;
using System.Runtime.InteropServices;
namespace Framework
{
///
/// Using Win32 Functions To Send Raw Data To Printer.
///
public class PrintRawData
{
public PrintRawData()
{
}
#region Win32
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
private 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", SetLastError=true, CharSet=CharSet.Unicode, ExactSpelling=true, CallingConvention=CallingConvention.StdCall)]
private static extern bool OpenPrinter(string src, ref IntPtr hPrinter , long pd);
[DllImport("winspool.drv", EntryPoint="ClosePrinter", SetLastError=true, CharSet=CharSet.Unicode, ExactSpelling=true, CallingConvention=CallingConvention.StdCall)]
private static extern bool ClosePrinter(IntPtr hPrinter);
[DllImport("winspool.drv", EntryPoint="StartDocPrinterW", SetLastError=true, CharSet=CharSet.Unicode, ExactSpelling=true, CallingConvention=CallingConvention.StdCall)]
private static extern bool StartDocPrinter(IntPtr hPrinter, Int32 level, ref DOCINFOW pDI);
[DllImport("winspool.drv", EntryPoint="EndDocPrinter", SetLastError=true, CharSet=CharSet.Unicode, ExactSpelling=true, CallingConvention=CallingConvention.StdCall)]
private static extern bool EndDocPrinter(IntPtr hPrinter);
[DllImport("winspool.drv", EntryPoint="StartPagePrinter", SetLastError=true, CharSet=CharSet.Unicode, ExactSpelling=true, CallingConvention=CallingConvention.StdCall)]
private static extern bool StartPagePrinter(IntPtr hPrinter);
[DllImport("winspool.drv", EntryPoint="EndPagePrinter", SetLastError=true, CharSet=CharSet.Unicode, ExactSpelling=true, CallingConvention=CallingConvention.StdCall)]
private static extern bool EndPagePrinter(IntPtr hPrinter);
[DllImport("winspool.drv", EntryPoint="WritePrinter", SetLastError=true, CharSet=CharSet.Unicode, ExactSpelling=true, CallingConvention=CallingConvention.StdCall)]
private static extern bool WritePrinter(IntPtr hPrinter, IntPtr pBytes, Int32 dwCount, ref Int32 dwWritten);
#endregion //Win32
// SendBytesToPrinter()
// When the function is given a printer name and an unmanaged array of
// bytes, the function sends those bytes to the print queue.
// Returns True on success or False on failure.
public bool SendBytesToPrinter(string szPrinterName, IntPtr pBytes, Int32 dwCount)
{
IntPtr hPrinter; // The printer handle.
Int32 dwError; // Last error - in case there was trouble.
DOCINFOW di; // Describes your document (name, port, data type).
Int32 dwWritten; // The number of bytes written by WritePrinter().
bool bSuccess; // Your success code.
di = new DOCINFOW();
di.pDocName = "Report Document";
di.pDataType = "RAW";
bSuccess = false;
hPrinter = new IntPtr(0);
dwWritten = 0;
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)
{
dwError = Marshal.GetLastWin32Error();
}
return bSuccess;
}
// When the function is given a string and a printer name,
// the function sends the string to the printer as raw bytes.
public void SendStringToPrinter(string szPrinterName, string szString)
{
IntPtr pBytes;
Int32 dwCount;
//How many characters are in the string?
dwCount = szString.Length;
//Assume that the printer is expecting ANSI text, and then convert
//the string to ANSI text.
pBytes = Marshal.StringToCoTaskMemAnsi(szString);
//Send the converted ANSI string to the printer.
SendBytesToPrinter(szPrinterName, pBytes, dwCount);
Marshal.FreeCoTaskMem(pBytes);
}
// SendFileToPrinter()
// When the function is given a file name and a printer name,
// the function reads the contents of the file and sends the
// contents to the printer.
// Presumes that the file contains printer-ready data.
// Shows how to use the SendBytesToPrinter function.
// Returns True on success or False on failure.
public bool SendFileToPrinter(string szPrinterName, string szFileName)
{
// Open the file.
FileStream fs;
fs = new FileStream(szFileName, FileMode.Open);
// Create a BinaryReader on the file.
BinaryReader br;
br = new BinaryReader(fs);
//Dim an array of bytes large enough to hold the file's contents.
byte[] bytes;
bytes = new byte[fs.Length];
bool bSuccess;
//Your unmanaged pointer.
IntPtr pUnmanagedBytes;
//Read the contents of the file into the array.
bytes = br.ReadBytes((int)fs.Length);
// Allocate some unmanaged memory for those bytes.
pUnmanagedBytes = Marshal.AllocCoTaskMem((int)fs.Length);
// Copy the managed byte array into the unmanaged array.
Marshal.Copy(bytes, 0, pUnmanagedBytes, (int)fs.Length);
// Send the unmanaged bytes to the printer.
bSuccess = SendBytesToPrinter(szPrinterName, pUnmanagedBytes, (int)fs.Length);
// Free the unmanaged memory that you allocated earlier.
Marshal.FreeCoTaskMem(pUnmanagedBytes);
return bSuccess;
}
public string ConvertWindowsToOEM437Greek(string sWindows)
{
string sOEM437Greek="";
if(sWindows != "")
{
for(int i = 0; i {
switch(sWindows
![Idea [I]](/cs/emoticons/emotion-55.gif)
)
{
case 'Ε':
sOEM437Greek+="i";
break;
case 'Ρ':
sOEM437Greek+="i";
break;
case 'Τ':
sOEM437Greek+="i";
break;
case 'Υ':
sOEM437Greek+="i";
break;
case 'Θ':
sOEM437Greek+="i";
break;
case 'Ι':
sOEM437Greek+="i";
break;
case 'Ο':
sOEM437Greek+="i";
break;
case 'Π':
sOEM437Greek+="i";
break;
case 'Α':
sOEM437Greek+="i";
break;
case 'Σ':
sOEM437Greek+="i";
break;
case 'Δ':
sOEM437Greek+="i";
break;
case 'Φ':
sOEM437Greek+="i";
break;
case 'Γ':
sOEM437Greek+="i";
break;
case 'Η':
sOEM437Greek+="i";
break;
case 'Ξ':
sOEM437Greek+="i";
break;
case 'Κ':
sOEM437Greek+="i";
break;
case 'Λ':
sOEM437Greek+="i";
break;
case 'Ζ':
sOEM437Greek+="i";
break;
case 'Χ':
sOEM437Greek+="i";
break;
case 'Ψ':
sOEM437Greek+="i";
break;
case 'Ω':
sOEM437Greek+="i";
break;
case 'Β':
sOEM437Greek+="i";
break;
case 'Ν':
sOEM437Greek+="i";
break;
case 'Μ':
sOEM437Greek+="i";
break;
default:
sOEM437Greek+=sWindows
![Idea [I]](/cs/emoticons/emotion-55.gif)
;
break;
}
}
}
return sOEM437Greek;
}
}
}