From 06c836955cdc8e875f62074d4ddfccd1087e6829 Mon Sep 17 00:00:00 2001 From: Ben Olden-Cooligan Date: Sun, 21 Jun 2015 18:07:44 -0400 Subject: [PATCH 1/3] Printing prototype --- NAPS2.Core/Icons.Designer.cs | 12 +- NAPS2.Core/Icons.resx | 3 + NAPS2.Core/ImportExport/Pdf/IPdfPrinter.cs | 32 ++ .../ImportExport/Pdf/PdfSharpPrinter.cs | 69 ++++ NAPS2.Core/NAPS2.Core.csproj | 3 + NAPS2.Core/Resources/printer.png | Bin 0 -> 1143 bytes NAPS2.Core/WinForms/FDesktop.Designer.cs | 88 +++-- NAPS2.Core/WinForms/FDesktop.cs | 36 +- NAPS2.Core/WinForms/FDesktop.resx | 352 ++++++++++-------- NAPS2/DI/CommonModule.cs | 1 + 10 files changed, 405 insertions(+), 191 deletions(-) create mode 100644 NAPS2.Core/ImportExport/Pdf/IPdfPrinter.cs create mode 100644 NAPS2.Core/ImportExport/Pdf/PdfSharpPrinter.cs create mode 100644 NAPS2.Core/Resources/printer.png diff --git a/NAPS2.Core/Icons.Designer.cs b/NAPS2.Core/Icons.Designer.cs index e68ce6e57..c50f94f1b 100644 --- a/NAPS2.Core/Icons.Designer.cs +++ b/NAPS2.Core/Icons.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.34209 +// Runtime Version:4.0.30319.34014 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -370,6 +370,16 @@ namespace NAPS2 { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap printer { + get { + object obj = ResourceManager.GetObject("printer", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// diff --git a/NAPS2.Core/Icons.resx b/NAPS2.Core/Icons.resx index 6c5b5af11..05b15e4a7 100644 --- a/NAPS2.Core/Icons.resx +++ b/NAPS2.Core/Icons.resx @@ -253,4 +253,7 @@ Resources\control_play_blue-small.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + Resources\printer.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + \ No newline at end of file diff --git a/NAPS2.Core/ImportExport/Pdf/IPdfPrinter.cs b/NAPS2.Core/ImportExport/Pdf/IPdfPrinter.cs new file mode 100644 index 000000000..576190276 --- /dev/null +++ b/NAPS2.Core/ImportExport/Pdf/IPdfPrinter.cs @@ -0,0 +1,32 @@ +/* + NAPS2 (Not Another PDF Scanner 2) + http://sourceforge.net/projects/naps2/ + + Copyright (C) 2009 Pavel Sorejs + Copyright (C) 2012 Michael Adams + Copyright (C) 2013 Peter De Leeuw + Copyright (C) 2012-2014 Ben Olden-Cooligan + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. +*/ + +using System; +using System.Collections.Generic; +using System.Linq; +using NAPS2.Scan.Images; + +namespace NAPS2.ImportExport.Pdf +{ + public interface IPdfPrinter + { + void Print(string pdfFilePath); + } +} diff --git a/NAPS2.Core/ImportExport/Pdf/PdfSharpPrinter.cs b/NAPS2.Core/ImportExport/Pdf/PdfSharpPrinter.cs new file mode 100644 index 000000000..abc5597b5 --- /dev/null +++ b/NAPS2.Core/ImportExport/Pdf/PdfSharpPrinter.cs @@ -0,0 +1,69 @@ +/* + NAPS2 (Not Another PDF Scanner 2) + http://sourceforge.net/projects/naps2/ + + Copyright (C) 2009 Pavel Sorejs + Copyright (C) 2012 Michael Adams + Copyright (C) 2013 Peter De Leeuw + Copyright (C) 2012-2014 Ben Olden-Cooligan + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. +*/ + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Windows.Forms; +using Microsoft.Win32; +using PdfSharp.Pdf.Printing; + +namespace NAPS2.ImportExport.Pdf +{ + public class PdfSharpPrinter : IPdfPrinter + { + public void Print(string pdfFilePath) + { + var p = Process.Start(new ProcessStartInfo + { + CreateNoWindow = false, + Verb = "print", + FileName = pdfFilePath + }); + if (p != null) + { + p.Start(); + p.WaitForExit(); + } + //var adobePath = + // Registry.LocalMachine.OpenSubKey("Software") + // .OpenSubKey("Microsoft") + // .OpenSubKey("Windows") + // .OpenSubKey("CurrentVersion") + // .OpenSubKey("App Paths") + // .OpenSubKey("AcroRd32.exe"); + //if (adobePath == null) + //{ + // MessageBox.Show("Adobe Reader must be installed in order to print."); + // return; + //} + //PdfFilePrinter.AdobeReaderPath = Path.Combine(adobePath.GetValue("Path").ToString(), "AcroRd32.exe"); + //var printDialog = new PrintDialog(); + //printDialog.AllowSelection = true; + //if (printDialog.ShowDialog() == DialogResult.OK) + //{ + // var printer = new PdfFilePrinter(pdfFilePath, printDialog.PrinterSettings.PrinterName); + // printer.Print(); + //} + } + } +} diff --git a/NAPS2.Core/NAPS2.Core.csproj b/NAPS2.Core/NAPS2.Core.csproj index 05a1f03af..d3bef9dd6 100644 --- a/NAPS2.Core/NAPS2.Core.csproj +++ b/NAPS2.Core/NAPS2.Core.csproj @@ -87,6 +87,8 @@ + + MiscResources.resx True @@ -1641,6 +1643,7 @@ + diff --git a/NAPS2.Core/Resources/printer.png b/NAPS2.Core/Resources/printer.png new file mode 100644 index 0000000000000000000000000000000000000000..d094d2b6647f2799116cf94d67f2859f114d6a4b GIT binary patch literal 1143 zcmV--1c>{IP)i6-=GvL#C+JC#Q3Hw}ou5&?3hQ89UA^1{fFH2uB(o2+LwamQlo{nway!=H(|DE@ zfTc{>3pRz*$_5}bYmE*oPXtowa{!SMK(xi0*%E+)lP?8515j3M(zmgB96JEms3RAE z2(jgYL~coRbQ96#xm!K=#ox;K%qj3?w!v%SXjouftTRgl`d3$Lz#fqnVU&@GL=t%- zqtz!ht&>Kx6973iHFZ6TqRGhgy|e{9DX?g}X&dGhK|1#C*@dafxmplL29w}1Lv~Lv zfC3w@R;z6bPoMrAC3y{>e)0`Mc0U&tTPW>%6-z;Y3m3j^dtIqiCX@2=m5R`4HnF&P z7Zz2m@B1ij8-(Y17#!Y#UWC{fjYb1^@7+heUf1(d=>XU!;&Oqen6t`xR}_^L$*r`n^uU%K*UMA3S)9u5k(+$9)k%7>2lY`&S)u&vQ|$)ii*Y zkpc#A`*S zZM6a5ClqvQD9^HM@BFSQrL~ zhy|5lvnb|(=K(NMnm970N(M7KJBvHN|3(oI`Wv-HHndF9FxkBM*4rqT%eoa4s*f+K zJq5gotDeOnAV1B`;m-&6G0@kisd#93xWnJR3kQ>|Q5P{4vyNLo-^7O#6GTKo8^9Dm z?6HS|ex+YJQet`OA^zBV5_4xi=&21SzPgG2r5h;r51>WG$5Bi=A_1V**VpGSUHtB7 z5+X*vZNTT=)bkq;^KHqF?brRSbzQl9G5)C;huJ27#sKQm)6<{Pb?1itfiqF1A|Tn} z<=+!pv?n@KIbWvR)^ne*XDe)*4X)F8MB~W@8{2s?%aEUohf)9}bh5zH4X^8LTN*Ua zIvpH@QM0`e@9(ojAfXPU~6FG4Bu?~0YGug!n_<&Q^`BU*Oj images) + { + if (images.Any()) + { + string path = Paths.AppData + "\\Scan.pdf"; + ExportPDF(path, images); + pdfPrinter.Print(path); + File.Delete(path); + } + } } } diff --git a/NAPS2.Core/WinForms/FDesktop.resx b/NAPS2.Core/WinForms/FDesktop.resx index 9129a9581..e7b897c33 100644 --- a/NAPS2.Core/WinForms/FDesktop.resx +++ b/NAPS2.Core/WinForms/FDesktop.resx @@ -171,6 +171,33 @@ 233, 17 + + Segoe UI, 9pt, style=Bold + + + 164, 22 + + + View + + + Ctrl+A + + + 164, 22 + + + Select All + + + Ctrl+C + + + 164, 22 + + + Copy + 165, 70 @@ -196,7 +223,7 @@ thumbnailList1 - NAPS2.WinForms.ThumbnailList, NAPS2.Core, Version=3.0.1.24397, Culture=neutral, PublicKeyToken=null + NAPS2.WinForms.ThumbnailList, NAPS2.Core, Version=3.3.1.30760, Culture=neutral, PublicKeyToken=null toolStripContainer1.ContentPanel @@ -264,38 +291,38 @@ iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 - YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAckSURBVFhHrVdtTFNZGnYMrh8xu/vDGc382NUdfzhuNMZx - sz9co5tMZjbG+DUGdjTRzY6Z0XUScRNXJmbjB3EERXGEVQYXaFFEoTBsVgTaAYpYoNBCoR/QUkoptqW0 - Ba32m/bZ99x7mTERStndJ3lyeu8953ne855z3567IFls3749JTc393R1dXXjw4cPZffu3ZOKRCKORUVF - 0pKSEvnRo0ezqetP+RH/A27duvVBdnb2p5mZmWnnz59PO3PmzJ6MjIysyclJJEI4HMaRI0fqt2zZ8sne - vXtTd+3albZz585PN27c+DHJLuXV58CxY8f+3NzcHAsGg3id0WhUsEmMWCzG9ff7/T9wbGwMhw8ffkDy - KbzL7PhJRUWFWtDCq1evMD4+DrfbzZEJzUXWz+PxcK3P5xOUgHPnzsWXLVv2B8FnViy8du1aIxvABGh9 - IRaLUVpaOm+ycWy8zWbjAqirq4uR/n7eJgG2bt2aHolEoNVqUVxcjKqqKkgkknmTjWOBtLe3cwHQBtWT - /K94lwRYvHjx2qampucsfbQZ/+sM3L17FwUFBRgZGeGWcfXq1bdJ/i3eZQ6cOnWqhkUtl8tx8+ZNFBYW - zpss+LKyMsTjceTn54dJdi+vngTWr1//p+HhYW796N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Du3LnIypUr88njTd5qdvyKuG/hwoUHiZ/MReqbCA8S2XfBKuIrWLDgB3WGxKbp + 57MVAAAAAElFTkSuQmCC @@ -374,6 +401,18 @@ 6, 54 + + 143, 22 + + + All ({0}) + + + 143, 22 + + + Selected ({0}) + Magenta @@ -386,6 +425,18 @@ ImageAboveText + + 143, 22 + + + All ({0}) + + + 143, 22 + + + Selected ({0}) + Magenta @@ -398,6 +449,18 @@ ImageAboveText + + 143, 22 + + + All ({0}) + + + 143, 22 + + + Selected ({0}) + Magenta @@ -410,6 +473,30 @@ ImageAboveText + + 152, 22 + + + All ({0}) + + + 152, 22 + + + Selected ({0}) + + + Magenta + + + 56, 51 + + + Print + + + ImageAboveText + Magenta @@ -425,6 +512,33 @@ 6, 54 + + None + + + 139, 22 + + + Rotate Left + + + None + + + 139, 22 + + + Rotate Right + + + None + + + 139, 22 + + + Flip + Magenta @@ -462,34 +576,34 @@ ImageAboveText - 152, 22 + 139, 22 Interleave - 152, 22 + 139, 22 Deinterleave - 149, 6 + 136, 6 - 152, 22 + 143, 22 All ({0}) - 152, 22 + 143, 22 Selected ({0}) - 152, 22 + 139, 22 Reverse @@ -604,7 +718,7 @@ 3, 0 - 1155, 54 + 1180, 54 12 @@ -648,96 +762,6 @@ 1 - - Segoe UI, 9pt, style=Bold - - - 164, 22 - - - View - - - Ctrl+A - - - 164, 22 - - - Select All - - - Ctrl+C - - - 164, 22 - - - Copy - - - 152, 22 - - - All ({0}) - - - 152, 22 - - - Selected ({0}) - - - 143, 22 - - - All ({0}) - - - 143, 22 - - - Selected ({0}) - - - 143, 22 - - - All ({0}) - - - 143, 22 - - - Selected ({0}) - - - None - - - 139, 22 - - - Rotate Left - - - None - - - 139, 22 - - - Rotate Right - - - None - - - 139, 22 - - - Flip - True @@ -870,6 +894,24 @@ System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + tsdPrint + + + System.Windows.Forms.ToolStripDropDownButton, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tsPrintAll + + + System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tsPrintSelected + + + System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + tsImport @@ -936,6 +978,30 @@ System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + toolStripSeparator1 + + + System.Windows.Forms.ToolStripSeparator, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tsReverse + + + System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tsReverseAll + + + System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tsReverseSelected + + + System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + toolStripSeparator2 @@ -972,34 +1038,10 @@ System.Windows.Forms.ToolStripButton, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - tsReverse - - - System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - toolStripSeparator1 - - - System.Windows.Forms.ToolStripSeparator, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tsReverseAll - - - System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tsReverseSelected - - - System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - FDesktop - NAPS2.WinForms.FormBase, NAPS2.Core, Version=3.0.1.24397, Culture=neutral, PublicKeyToken=null + NAPS2.WinForms.FormBase, NAPS2.Core, Version=3.3.1.30760, Culture=neutral, PublicKeyToken=null \ No newline at end of file diff --git a/NAPS2/DI/CommonModule.cs b/NAPS2/DI/CommonModule.cs index d35a95b6b..092aedda5 100644 --- a/NAPS2/DI/CommonModule.cs +++ b/NAPS2/DI/CommonModule.cs @@ -31,6 +31,7 @@ namespace NAPS2.DI // Export Bind().To(); + Bind().To(); Bind().To(); Bind().To(); From e3058e32f4fef7666b18e08a05750719fc7ea89d Mon Sep 17 00:00:00 2001 From: Ben Olden-Cooligan Date: Sun, 21 Jun 2015 18:32:13 -0400 Subject: [PATCH 2/3] Printing WIP --- NAPS2.Core/ImportExport/Pdf/IPdfPrinter.cs | 2 +- .../ImportExport/Pdf/PdfSharpPrinter.cs | 44 +++++-------- NAPS2.Core/WinForms/FDesktop.Designer.cs | 20 +----- NAPS2.Core/WinForms/FDesktop.cs | 62 ++++++++++++++----- NAPS2.Core/WinForms/FDesktop.resx | 30 +-------- 5 files changed, 65 insertions(+), 93 deletions(-) diff --git a/NAPS2.Core/ImportExport/Pdf/IPdfPrinter.cs b/NAPS2.Core/ImportExport/Pdf/IPdfPrinter.cs index 576190276..06afe4535 100644 --- a/NAPS2.Core/ImportExport/Pdf/IPdfPrinter.cs +++ b/NAPS2.Core/ImportExport/Pdf/IPdfPrinter.cs @@ -27,6 +27,6 @@ namespace NAPS2.ImportExport.Pdf { public interface IPdfPrinter { - void Print(string pdfFilePath); + void Print(string pdfFilePath, string printerName); } } diff --git a/NAPS2.Core/ImportExport/Pdf/PdfSharpPrinter.cs b/NAPS2.Core/ImportExport/Pdf/PdfSharpPrinter.cs index abc5597b5..1bc45f6c9 100644 --- a/NAPS2.Core/ImportExport/Pdf/PdfSharpPrinter.cs +++ b/NAPS2.Core/ImportExport/Pdf/PdfSharpPrinter.cs @@ -31,39 +31,23 @@ namespace NAPS2.ImportExport.Pdf { public class PdfSharpPrinter : IPdfPrinter { - public void Print(string pdfFilePath) + public void Print(string pdfFilePath, string printerName) { - var p = Process.Start(new ProcessStartInfo + var adobePath = + Registry.LocalMachine.OpenSubKey("Software") + .OpenSubKey("Microsoft") + .OpenSubKey("Windows") + .OpenSubKey("CurrentVersion") + .OpenSubKey("App Paths") + .OpenSubKey("AcroRd32.exe"); + if (adobePath == null) { - CreateNoWindow = false, - Verb = "print", - FileName = pdfFilePath - }); - if (p != null) - { - p.Start(); - p.WaitForExit(); + MessageBox.Show("Adobe Reader must be installed in order to print."); + return; } - //var adobePath = - // Registry.LocalMachine.OpenSubKey("Software") - // .OpenSubKey("Microsoft") - // .OpenSubKey("Windows") - // .OpenSubKey("CurrentVersion") - // .OpenSubKey("App Paths") - // .OpenSubKey("AcroRd32.exe"); - //if (adobePath == null) - //{ - // MessageBox.Show("Adobe Reader must be installed in order to print."); - // return; - //} - //PdfFilePrinter.AdobeReaderPath = Path.Combine(adobePath.GetValue("Path").ToString(), "AcroRd32.exe"); - //var printDialog = new PrintDialog(); - //printDialog.AllowSelection = true; - //if (printDialog.ShowDialog() == DialogResult.OK) - //{ - // var printer = new PdfFilePrinter(pdfFilePath, printDialog.PrinterSettings.PrinterName); - // printer.Print(); - //} + PdfFilePrinter.AdobeReaderPath = Path.Combine(adobePath.GetValue("Path").ToString(), "AcroRd32.exe"); + var printer = new PdfFilePrinter(pdfFilePath, printerName); + printer.Print(); } } } diff --git a/NAPS2.Core/WinForms/FDesktop.Designer.cs b/NAPS2.Core/WinForms/FDesktop.Designer.cs index f7b982505..5a866dde1 100644 --- a/NAPS2.Core/WinForms/FDesktop.Designer.cs +++ b/NAPS2.Core/WinForms/FDesktop.Designer.cs @@ -57,8 +57,6 @@ namespace NAPS2.WinForms this.tsEmailPDFAll = new System.Windows.Forms.ToolStripMenuItem(); this.tsEmailPDFSelected = new System.Windows.Forms.ToolStripMenuItem(); this.tsdPrint = new System.Windows.Forms.ToolStripDropDownButton(); - this.tsPrintAll = new System.Windows.Forms.ToolStripMenuItem(); - this.tsPrintSelected = new System.Windows.Forms.ToolStripMenuItem(); this.tsImport = new System.Windows.Forms.ToolStripButton(); this.toolStripSeparator4 = new System.Windows.Forms.ToolStripSeparator(); this.tsdRotate = new System.Windows.Forms.ToolStripDropDownButton(); @@ -276,26 +274,12 @@ namespace NAPS2.WinForms // // tsdPrint // - this.tsdPrint.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.tsPrintAll, - this.tsPrintSelected}); this.tsdPrint.Image = global::NAPS2.Icons.printer; resources.ApplyResources(this.tsdPrint, "tsdPrint"); this.tsdPrint.Name = "tsdPrint"; this.tsdPrint.Padding = new System.Windows.Forms.Padding(10, 0, 10, 0); this.tsdPrint.ShowDropDownArrow = false; - // - // tsPrintAll - // - this.tsPrintAll.Name = "tsPrintAll"; - resources.ApplyResources(this.tsPrintAll, "tsPrintAll"); - this.tsPrintAll.Click += new System.EventHandler(this.tsPrintAll_Click); - // - // tsPrintSelected - // - this.tsPrintSelected.Name = "tsPrintSelected"; - resources.ApplyResources(this.tsPrintSelected, "tsPrintSelected"); - this.tsPrintSelected.Click += new System.EventHandler(this.tsPrintSelected_Click); + this.tsdPrint.Click += new System.EventHandler(this.tsdPrint_Click); // // tsImport // @@ -516,8 +500,6 @@ namespace NAPS2.WinForms private System.Windows.Forms.ToolStripMenuItem tsReverseAll; private System.Windows.Forms.ToolStripMenuItem tsReverseSelected; private System.Windows.Forms.ToolStripDropDownButton tsdPrint; - private System.Windows.Forms.ToolStripMenuItem tsPrintAll; - private System.Windows.Forms.ToolStripMenuItem tsPrintSelected; } } diff --git a/NAPS2.Core/WinForms/FDesktop.cs b/NAPS2.Core/WinForms/FDesktop.cs index 8f7799b35..a4c74874b 100644 --- a/NAPS2.Core/WinForms/FDesktop.cs +++ b/NAPS2.Core/WinForms/FDesktop.cs @@ -24,6 +24,7 @@ using System.Collections.Generic; using System.Collections.Specialized; using System.Diagnostics; using System.Drawing; +using System.Drawing.Printing; using System.Globalization; using System.IO; using System.Linq; @@ -195,15 +196,15 @@ namespace NAPS2.WinForms private void UpdateToolbar() { // "All" dropdown items - tsSavePDFAll.Text = tsSaveImagesAll.Text = tsEmailPDFAll.Text = tsPrintAll.Text = tsReverseAll.Text = + tsSavePDFAll.Text = tsSaveImagesAll.Text = tsEmailPDFAll.Text = tsReverseAll.Text = string.Format(MiscResources.AllCount, imageList.Images.Count); - tsSavePDFAll.Enabled = tsSaveImagesAll.Enabled = tsEmailPDFAll.Enabled = tsPrintAll.Enabled = tsReverseAll.Enabled = + tsSavePDFAll.Enabled = tsSaveImagesAll.Enabled = tsEmailPDFAll.Enabled = tsReverseAll.Enabled = imageList.Images.Any(); // "Selected" dropdown items - tsSavePDFSelected.Text = tsSaveImagesSelected.Text = tsEmailPDFSelected.Text = tsPrintSelected.Text = tsReverseSelected.Text = + tsSavePDFSelected.Text = tsSaveImagesSelected.Text = tsEmailPDFSelected.Text = tsReverseSelected.Text = string.Format(MiscResources.SelectedCount, SelectedIndices.Count()); - tsSavePDFSelected.Enabled = tsSaveImagesSelected.Enabled = tsEmailPDFSelected.Enabled = tsPrintSelected.Enabled = tsReverseSelected.Enabled = + tsSavePDFSelected.Enabled = tsSaveImagesSelected.Enabled = tsEmailPDFSelected.Enabled = tsReverseSelected.Enabled = SelectedIndices.Any(); // Top-level toolbar actions @@ -701,25 +702,54 @@ namespace NAPS2.WinForms UpdateThumbnails(imageList.Reverse(SelectedIndices)); } - private void tsPrintAll_Click(object sender, EventArgs e) - { - Print(imageList.Images); - } - - private void tsPrintSelected_Click(object sender, EventArgs e) - { - Print(SelectedImages.ToList()); - } - - private void Print(List images) + private void Print(List images, string printerName) { if (images.Any()) { string path = Paths.AppData + "\\Scan.pdf"; ExportPDF(path, images); - pdfPrinter.Print(path); + pdfPrinter.Print(path, printerName); File.Delete(path); } } + + private void tsdPrint_Click(object sender, EventArgs e) + { + if (!imageList.Images.Any()) + { + return; + } + var printDialog = new PrintDialog + { + AllowSelection = SelectedIndices.Any(), + AllowSomePages = true + }; + printDialog.PrinterSettings.MinimumPage = 1; + printDialog.PrinterSettings.MaximumPage = imageList.Images.Count; + printDialog.PrinterSettings.FromPage = 1; + printDialog.PrinterSettings.ToPage = imageList.Images.Count; + if (printDialog.ShowDialog() == DialogResult.OK) + { + List imagesToPrint; + switch (printDialog.PrinterSettings.PrintRange) + { + case PrintRange.AllPages: + imagesToPrint = imageList.Images; + break; + case PrintRange.Selection: + imagesToPrint = SelectedImages.ToList(); + break; + case PrintRange.SomePages: + int start = printDialog.PrinterSettings.FromPage; + int length = printDialog.PrinterSettings.ToPage - start + 1; + imagesToPrint = imageList.Images.Skip(start).Take(length).ToList(); + break; + default: + imagesToPrint = new List(); + break; + } + Print(imagesToPrint, printDialog.PrinterSettings.PrinterName); + } + } } } diff --git a/NAPS2.Core/WinForms/FDesktop.resx b/NAPS2.Core/WinForms/FDesktop.resx index e7b897c33..81ce7ba91 100644 --- a/NAPS2.Core/WinForms/FDesktop.resx +++ b/NAPS2.Core/WinForms/FDesktop.resx @@ -450,13 +450,13 @@ ImageAboveText - 143, 22 + 152, 22 All ({0}) - 143, 22 + 152, 22 Selected ({0}) @@ -473,18 +473,6 @@ ImageAboveText - - 152, 22 - - - All ({0}) - - - 152, 22 - - - Selected ({0}) - Magenta @@ -718,7 +706,7 @@ 3, 0 - 1180, 54 + 1181, 54 12 @@ -900,18 +888,6 @@ System.Windows.Forms.ToolStripDropDownButton, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - tsPrintAll - - - System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tsPrintSelected - - - System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - tsImport From d5cae9b1ce93eb1ee5e36ff56f3fe722b48b3e0f Mon Sep 17 00:00:00 2001 From: Ben Olden-Cooligan Date: Fri, 10 Jul 2015 17:52:55 -0400 Subject: [PATCH 3/3] Handle print copies --- NAPS2.Core/WinForms/FDesktop.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/NAPS2.Core/WinForms/FDesktop.cs b/NAPS2.Core/WinForms/FDesktop.cs index a4c74874b..ed119160e 100644 --- a/NAPS2.Core/WinForms/FDesktop.cs +++ b/NAPS2.Core/WinForms/FDesktop.cs @@ -748,6 +748,23 @@ namespace NAPS2.WinForms imagesToPrint = new List(); break; } + int copies = printDialog.PrinterSettings.Copies; + if (copies > 1) + { + if (printDialog.PrinterSettings.Collate) + { + imagesToPrint = + Enumerable.Range(0, copies) + .Aggregate(Enumerable.Empty(), (x, y) => x.Concat(imagesToPrint)) + .ToList(); + } + else + { + imagesToPrint = + imagesToPrint.SelectMany(x => Enumerable.Repeat(x, copies)) + .ToList(); + } + } Print(imagesToPrint, printDialog.PrinterSettings.PrinterName); } }