Пример #1
0
        private void DocPrinter(SafePrinter printer, string documentName, string dataType, Stream stream, bool paused, int pagecount, string printerName)
        {
            var di1 = new DOC_INFO_1
            {
                pDataType = dataType,
                pDocName  = documentName,
            };

            var id = printer.StartDocPrinter(di1);

            if (paused)
            {
                NativeMethods.SetJob(printer.DangerousGetHandle(), id, 0, IntPtr.Zero, (int)JobControl.Pause);
            }

            OnJobCreated?.Invoke(this, new JobCreatedEventArgs {
                Id = id, PrinterName = printerName
            });

            try
            {
                PagePrinter(printer, stream, pagecount);
            }
            finally
            {
                printer.EndDocPrinter();
            }
        }
Пример #2
0
 public void StartDocPrinter(DOC_INFO_1 di1)
 {
     if (NativeMethods.StartDocPrinterW(handle, 1, ref di1) == 0)
     {
         if (Marshal.GetLastWin32Error() == 1804)
         {
             throw new Exception("The specified datatype is invalid, try setting 'Enable advanced printing features' in printer properties.", new Win32Exception());
         }
         throw new Win32Exception();
     }
 }
Пример #3
0
        public uint StartDocPrinter(DOC_INFO_1 di1)
        {
            var id = NativeMethods.StartDocPrinterW(handle, 1, ref di1);

            if (id == 0)
            {
                if (Marshal.GetLastWin32Error() == 1804)
                {
                    throw new Exception("The specified datatype is invalid, try setting 'Enable advanced printing features' in printer properties.", new Win32Exception());
                }
                throw new Win32Exception();
            }

            return(id);
        }
Пример #4
0
        private static void DocPrinter(SafePrinter printer, string documentName, string dataType, Stream stream)
        {
            var di1 = new DOC_INFO_1
            {
                pDataType = dataType,
                pDocName = documentName,
            };

            printer.StartDocPrinter(di1);

            try
            {
                PagePrinter(printer, stream);
            }
            finally
            {
                printer.EndDocPrinter();
            }
        }
Пример #5
0
        private static void DocPrinter(SafePrinter printer, string documentName, string dataType, Stream stream, bool paused)
        {
            var di1 = new DOC_INFO_1
            {
                pDataType = dataType,
                pDocName  = documentName,
            };

            var id = printer.StartDocPrinter(di1);

            if (paused)
            {
                NativeMethods.SetJob(printer.DangerousGetHandle(), id, 0, IntPtr.Zero, (int)JobControl.Pause);
            }

            try
            {
                PagePrinter(printer, stream);
            }
            finally
            {
                printer.EndDocPrinter();
            }
        }
Пример #6
0
 public static extern uint StartDocPrinterW(IntPtr hPrinter, uint level, [MarshalAs(UnmanagedType.Struct)] ref DOC_INFO_1 di1);