Ejemplo n.º 1
0
        private static bool SendBytesToPrinter(string printerName, IntPtr intptrBytes, Int32 count)
        {
            Int32   error = 0, written = 0;
            IntPtr  intptrPrinter = new IntPtr(0);
            DocInfo docInfo       = new DocInfo();
            bool    bSuccess      = false;

            docInfo.DocName  = ".NET RAW Document";
            docInfo.DataType = "RAW";

            // Open the printer.
            if (OpenPrinter(printerName.Normalize(), out intptrPrinter, IntPtr.Zero))
            {
                // Start a document.
                if (StartDocPrinter(intptrPrinter, 1, docInfo))
                {
                    // Start a page.
                    if (StartPagePrinter(intptrPrinter))
                    {
                        // Write your bytes.
                        bSuccess = WritePrinter(intptrPrinter, intptrBytes, count, out written);
                        EndPagePrinter(intptrPrinter);
                    }
                    EndDocPrinter(intptrPrinter);
                }
                ClosePrinter(intptrPrinter);
            }
            // If you did not succeed, GetLastError may give more information
            // about why not.
            if (bSuccess == false)
            {
                error = Marshal.GetLastWin32Error();
            }
            return(bSuccess);
        }
Ejemplo n.º 2
0
 public static extern bool StartDocPrinter(IntPtr intptrPrinter, Int32 level, [In, MarshalAs(UnmanagedType.LPStruct)] DocInfo docInfo);