0
下面的代碼是用於條形碼(斑馬條碼打印機)打印的web應用程序。如果我在應用程序服務器中打印,我可以打印。c#web應用程序中的條碼打印
[DllImport("winspool.Drv", EntryPoint = "WritePrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern bool WritePrinter(IntPtr hPrinter, IntPtr pBytes, Int32 dwCount, out Int32 dwWritten);
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;
}
這裏szPrinterName
是從應用程序下拉框中打印機名稱。 這裏我能夠僅將應用服務器中安裝的打印機名稱打印出來並打印到服務器。
我如何在客戶機打印機客戶機的打印機名稱和打印?
編輯使問題更突出。 – Alex
這就是ASP.NET?您無法從服務器訪問客戶端硬件。 –
@PabloRomeo:如何才能使它在客戶端機器上可行?是否有任何JavaScript代碼的打印(使用打印機dialoge盒出) – bharath