Click here to Skip to main content
15,918,676 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,


protected void btnsave_Click(object sender, EventArgs e)
{
//string s = "Hello"; // device-dependent string, need a FormFeed?
string ss = "^XA"+"^FO100"+"100^BY7"+"NFD123456^FS"+"^XZ";

//string command = "N" + (char)Keys.LineFeed + "A280,20,1,2,1,1,N,\"CODE:\"" + (char)Keys.LineFeed +
//"A255,20,1,3,1,1,N,\"" + "1234" + "\"" + (char)Keys.LineFeed +
//"P1" + (char)Keys.LineFeed;

// Create a buffer with the command


StringBuilder sb = new StringBuilder();
sb.AppendLine();
sb.AppendLine("N");
sb.AppendLine("q609");
sb.AppendLine("Q203,26");
sb.AppendLine(string.Format(
CultureInfo.InvariantCulture,
"B26,26,0,UA0,2,2,152,B,\"{0}\"",
this.upc));
sb.AppendLine("P1,1");


//Byte[] buffer = new byte[ss.Length];
//buffer = System.Text.Encoding.ASCII.GetBytes(ss);
//// Allow the user to select a printer.
PrintDialog pd1 = new PrintDialog();
pd1.PrinterSettings = new PrinterSettings();
if (DialogResult.OK == pd1.ShowDialog())
{
// Send a printer-specific to the printer.
PrintRaw.SendStringToPrinter(pd1.PrinterSettings.PrinterName, sb.ToString());

}



}

method call this (PrintRaw.SendStringToPrinter(pd1.PrinterSettings.PrinterName, sb.ToString());)

C#
public static bool 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);
       return true;
   }


but not getting print in printer
Posted
Comments
[no name] 31-Mar-14 7:50am    
*sigh* Are you still trying to print from a web page? Why are you using P/Invoke for printing? Did you look for your print at the web server? Did you debug your code?
antish1 31-Mar-14 8:10am    
already done in debug but not getting output print out like say function already calling
Marc Gabrie 31-Mar-14 13:41pm    
you are sending EPL commands to the printer so.... are you sure that your printer does understand it i.e. is EPL capable? maybe it supports ZPL only? Which is the printer model?
antish1 31-Mar-14 23:13pm    
Only send ZPL do you any idea ZPL Command How to send? please suggest me and example how should it works? please tell me it urgents
antish1 31-Mar-14 23:14pm    
Printer Model (TLP 2844)

1 solution

You have written
C#
SendBytesToPrinter(szPrinterName, pBytes, dwCount);
in your code. what that function does. Please tell us so that we can understand the issue better.
 
Share this answer
 
Comments
antish1 31-Mar-14 8:11am    
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 = "My C#.NET RAW Document";
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;
}
antish1 31-Mar-14 8:12am    
already created method but not getting printout..
Er. Puneet Goel 31-Mar-14 8:12am    
Is it throwing some sort of error or what?
antish1 31-Mar-14 8:20am    
string pass in direct printer do you check?

this line
(PrintRaw.SendStringToPrinter(pd1.PrinterSettings.PrinterName, sb.ToString()))
antish1 31-Mar-14 8:20am    
exactly not getting output in print..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900