private void ExecuteChangePaper(object obj) { try { var ptc = new PrintTicketConverter(CurrentPrinter.FullName, CurrentPrinter.ClientPrintSchemaVersion); var mainWindowPtr = new WindowInteropHelper(FullScreenPrintWindow).Handle; var myDevMode = ptc.ConvertPrintTicketToDevMode(CurrentPrinter.UserPrintTicket, BaseDevModeType.UserDefault); var pinnedDevMode = GCHandle.Alloc(myDevMode, GCHandleType.Pinned); var pDevMode = pinnedDevMode.AddrOfPinnedObject(); var result = DocumentProperties(mainWindowPtr, IntPtr.Zero, CurrentPrinter.FullName, pDevMode, pDevMode, 14); if (result == 1) { CurrentPrinter.UserPrintTicket = ptc.ConvertDevModeToPrintTicket(myDevMode); pinnedDevMode.Free(); PrintCopyCount = CurrentPrinter.UserPrintTicket.CopyCount.Value; SetPageOrientation(CurrentPrinter.UserPrintTicket.PageOrientation); SetCurrentPaper(CurrentPrinter.UserPrintTicket.PageMediaSize); ExecuteSetPrintingOptions(null); } } catch (Exception) { } }
AllocateAndInitializeDevMode( string printerName, PrintTicket printTicket ) { byte[] devModeData = null; // // Convert the PrintTicket object to a DEVMODE // using (PrintTicketConverter ptConverter = new PrintTicketConverter( printerName, PrintTicketConverter.MaxPrintSchemaVersion)) { devModeData = ptConverter.ConvertPrintTicketToDevMode( printTicket, BaseDevModeType.UserDefault); } // // Make the dev mode data a DEVMODE structure in global memory // IntPtr hDevMode = Marshal.AllocHGlobal(devModeData.Length); Marshal.Copy(devModeData, 0, hDevMode, devModeData.Length); return(hDevMode); }
private byte[] ConvertPrintTicketToDevMode(PrintTicket ticket) { if (m_Converter == null) { m_Converter = new PrintTicketConverter(m_PrintQueue.FullName, m_PrintQueue.ClientPrintSchemaVersion); } return(m_Converter.ConvertPrintTicketToDevMode(ticket, BaseDevModeType.UserDefault)); }
public GDIPrinterDeviceContext(string printername, PrintTicket ticket) : base(true) { PrintTicketConverter ptc = new PrintTicketConverter(printername, PrintTicketConverter.MaxPrintSchemaVersion); byte[] dmdata = ptc.ConvertPrintTicketToDevMode(ticket, BaseDevModeType.PrinterDefault); this.PrintTicket = ptc.ConvertDevModeToPrintTicket(dmdata); IntPtr dmptr = Marshal.AllocHGlobal(dmdata.Length); Marshal.Copy(dmdata, 0, dmptr, dmdata.Length); this.HDC = NativeMethods.CreateDC("WINSPOOL", printername, null, dmptr); Marshal.FreeHGlobal(dmptr); }
private PrintTicket OpenPrinterProperties(Window window, PrintQueue printQueue, PrintTicket printTicket) { var ptc = new PrintTicketConverter(printQueue.FullName, printQueue.ClientPrintSchemaVersion); var mainWindowPtr = new WindowInteropHelper(window).Handle; var devMode = ptc.ConvertPrintTicketToDevMode(printTicket, BaseDevModeType.UserDefault); var pinnedDevMode = GCHandle.Alloc(devMode, GCHandleType.Pinned); var pDevMode = pinnedDevMode.AddrOfPinnedObject(); Win32.DocumentProperties(mainWindowPtr, IntPtr.Zero, printQueue.FullName, pDevMode, pDevMode, 14); var newTicket = ptc.ConvertDevModeToPrintTicket(devMode); pinnedDevMode.Free(); return(newTicket); }
private static unsafe PrintTicket ShowPrintPropertiesDialog(IntPtr hwnd, PrintQueue printQueue, PrintDialogDelegate dlg, PrintTicket printTicket) { using (var printTicketConverter = new PrintTicketConverter(printQueue.Name, PrintTicketConverter.MaxPrintSchemaVersion)) { var bDevModeIn = printTicketConverter.ConvertPrintTicketToDevMode(printTicket, BaseDevModeType.UserDefault, PrintTicketScope.JobScope); var bDevModeOut = new byte[bDevModeIn.Length]; fixed(byte *pDevModeOut = bDevModeOut, pDevModeIn = bDevModeIn) { if (dlg(hwnd, printQueue.Name, new IntPtr(pDevModeIn), new IntPtr(pDevModeOut))) { return(printTicketConverter.ConvertDevModeToPrintTicket(bDevModeOut, PrintTicketScope.JobScope)); } else { return(null); } } } } // func ShowPrintPropertiesDialog
private IntPtr AllocateAndInitializeDevMode(string printerName, PrintTicket printTicket) { byte[] array = null; SystemDrawingHelper.NewDefaultPrintingPermission().Assert(); try { using (PrintTicketConverter printTicketConverter = new PrintTicketConverter(printerName, PrintTicketConverter.MaxPrintSchemaVersion)) { array = printTicketConverter.ConvertPrintTicketToDevMode(printTicket, BaseDevModeType.UserDefault); } } finally { CodeAccessPermission.RevertAssert(); } IntPtr intPtr = Marshal.AllocHGlobal(array.Length); Marshal.Copy(array, 0, intPtr, array.Length); return(intPtr); }
} // proc SetPrintDocument /// <summary>Copy printer settings from System.Printing to System.Drawing</summary> /// <param name="printerSettings"></param> /// <param name="printQueue"></param> /// <param name="printTicket"></param> public static void SetPrintTicket(this PrinterSettings printerSettings, PrintQueue printQueue, PrintTicket printTicket) { using (var printTicketConverter = new PrintTicketConverter(printQueue.Name, PrintTicketConverter.MaxPrintSchemaVersion)) { printerSettings.PrinterName = printQueue.Name; var bDevMode = printTicketConverter.ConvertPrintTicketToDevMode(printTicket, BaseDevModeType.UserDefault, PrintTicketScope.JobScope); var pDevMode = Marshal.AllocHGlobal(bDevMode.Length); try { // copy settings Marshal.Copy(bDevMode, 0, pDevMode, bDevMode.Length); printerSettings.SetHdevmode(pDevMode); printerSettings.DefaultPageSettings.SetHdevmode(pDevMode); } finally { Marshal.FreeHGlobal(pDevMode); } } } // proc SetPrintTicket
/// <summary> /// Creates DevMode structure from Ticket /// </summary> /// <param name="printerName"></param> /// <param name="printTicket"></param> /// <returns></returns> IntPtr InitializeDevMode(string printerName, PrintTicket printTicket) { new PrintingPermission(PrintingPermissionLevel.DefaultPrinting).Assert(); byte[] dMode = null; try { using (PrintTicketConverter converter = new PrintTicketConverter(printerName, PrintTicketConverter.MaxPrintSchemaVersion)) { dMode = converter.ConvertPrintTicketToDevMode(printTicket, BaseDevModeType.UserDefault); } } finally { CodeAccessPermission.RevertAssert(); } IntPtr ptrDevMode = Marshal.AllocHGlobal(dMode.Length); Marshal.Copy(dMode, 0, ptrDevMode, dMode.Length); return(ptrDevMode); }
/// <summary> /// Creates DevMode structure from Ticket /// </summary> /// <param name="printerName"></param> /// <param name="printTicket"></param> /// <returns></returns> IntPtr InitializeDevMode(string printerName, PrintTicket printTicket) { Helpers.SecurityAssert(); byte[] dMode = null; try { using (PrintTicketConverter converter = new PrintTicketConverter(printerName, PrintTicketConverter.MaxPrintSchemaVersion)) { dMode = converter.ConvertPrintTicketToDevMode(printTicket, BaseDevModeType.UserDefault); } } finally { Helpers.SecurityRevert(); } IntPtr ptrDevMode = Marshal.AllocHGlobal(dMode.Length); Marshal.Copy(dMode, 0, ptrDevMode, dMode.Length); return(ptrDevMode); }
AllocateAndInitializeDevMode( string printerName, PrintTicket printTicket ) { byte[] devModeData = null; SystemDrawingHelper.NewDefaultPrintingPermission().Assert(); //BlessedAssert try { // // Convert the PrintTicket object to a DEVMODE // using (PrintTicketConverter ptConverter = new PrintTicketConverter( printerName, PrintTicketConverter.MaxPrintSchemaVersion)) { devModeData = ptConverter.ConvertPrintTicketToDevMode( printTicket, BaseDevModeType.UserDefault); } } finally { CodeAccessPermission.RevertAssert(); } // // Make the dev mode data a DEVMODE structure in global memory // IntPtr hDevMode = Marshal.AllocHGlobal(devModeData.Length); Marshal.Copy(devModeData, 0, hDevMode, devModeData.Length); return(hDevMode); }
// Handles printer properties click private void OnPrinterPropertiesClick(object sender, RoutedEventArgs e) { PrintQueue selectedPrintQueue = (printersComboBox.SelectedItem as PrinterInfo).Queue; selectedPrintQueue.UserPrintTicket.PageOrientation = orientationComboBox.SelectedIndex == 0 ? PageOrientation.Portrait : PageOrientation.Landscape; PrintTicketConverter ptc = new PrintTicketConverter(selectedPrintQueue.FullName, selectedPrintQueue.ClientPrintSchemaVersion); IntPtr mainWindowPtr = new WindowInteropHelper(Window.GetWindow(this)).Handle; byte[] myDevMode = ptc.ConvertPrintTicketToDevMode(selectedPrintQueue.UserPrintTicket, BaseDevModeType.UserDefault); GCHandle pinnedDevMode = GCHandle.Alloc(myDevMode, GCHandleType.Pinned); IntPtr pDevMode = pinnedDevMode.AddrOfPinnedObject(); DocumentProperties(mainWindowPtr, IntPtr.Zero, selectedPrintQueue.FullName, pDevMode, pDevMode, 14); selectedPrintQueue.UserPrintTicket = ptc.ConvertDevModeToPrintTicket(myDevMode); pinnedDevMode.Free(); }
AllocateAndInitializeDevMode( string printerName, PrintTicket printTicket ) { byte[] devModeData = null; (new PrintingPermission(PrintingPermissionLevel.DefaultPrinting)).Assert(); //BlessedAssert try { // // Convert the PrintTicket object to a DEVMODE // using (PrintTicketConverter ptConverter = new PrintTicketConverter( printerName, PrintTicketConverter.MaxPrintSchemaVersion)) { devModeData = ptConverter.ConvertPrintTicketToDevMode( printTicket, BaseDevModeType.UserDefault); } } finally { PrintingPermission.RevertAssert(); } // // Make the dev mode data a DEVMODE structure in global memory // IntPtr hDevMode = Marshal.AllocHGlobal(devModeData.Length); Marshal.Copy(devModeData, 0, hDevMode, devModeData.Length); return hDevMode; }
/// <summary> /// Creates DevMode structure from Ticket /// </summary> /// <param name="printerName"></param> /// <param name="printTicket"></param> /// <returns></returns> IntPtr InitializeDevMode(string printerName, PrintTicket printTicket) { new PrintingPermission(PrintingPermissionLevel.DefaultPrinting).Assert(); byte[] dMode = null; try { using (PrintTicketConverter converter = new PrintTicketConverter(printerName, PrintTicketConverter.MaxPrintSchemaVersion)) { dMode = converter.ConvertPrintTicketToDevMode(printTicket, BaseDevModeType.UserDefault); } } finally { CodeAccessPermission.RevertAssert(); } IntPtr ptrDevMode = Marshal.AllocHGlobal(dMode.Length); Marshal.Copy(dMode, 0, ptrDevMode, dMode.Length); return ptrDevMode; }
public void ShowSettings() { PrintTicketConverter ptc = new PrintTicketConverter(PrinterName, printqueue.ClientPrintSchemaVersion); IntPtr mainWindowPtr = this.Handle; byte[] myDevMode = ptc.ConvertPrintTicketToDevMode(ticket, BaseDevModeType.PrinterDefault); GCHandle pinnedDevMode = GCHandle.Alloc(myDevMode, GCHandleType.Pinned); IntPtr pDevMode = pinnedDevMode.AddrOfPinnedObject(); int res = Helpers.DocumentProperties(mainWindowPtr, IntPtr.Zero, printqueue.FullName, pDevMode, pDevMode, 14); if (res == 1) { ticket = ptc.ConvertDevModeToPrintTicket(myDevMode); pinnedDevMode.Free(); NotifyPropertyChanged("PageOrientation"); NotifyPropertyChanged("NumberOfCopies"); GenerateFixedDocument(false); } }
/// <summary> /// Invoke the printer option window /// </summary> /// <param name="parent"></param> /// <param name="printer"></param> /// <returns></returns> public bool OpenPrintOptions(Window parent, PrintQueue printer) { if (parent == null) throw new ArgumentNullException("Parent window of printer dialog is null."); using (PrintTicketConverter ptc = new PrintTicketConverter(printer.FullName, printer.ClientPrintSchemaVersion)) { IntPtr mainWindowPtr = new WindowInteropHelper(parent).Handle; byte[] myDevMode = ptc.ConvertPrintTicketToDevMode(printer.UserPrintTicket, BaseDevModeType.UserDefault); GCHandle pinnedDevMode = GCHandle.Alloc(myDevMode, GCHandleType.Pinned); IntPtr pDevMode = pinnedDevMode.AddrOfPinnedObject(); int result = DocumentPropertiesFunc(mainWindowPtr, IntPtr.Zero, printer.FullName, pDevMode, pDevMode, 14); if (result == 1) { printer.UserPrintTicket = ptc.ConvertDevModeToPrintTicket(myDevMode); return true; } else { return false; } } }