From 6c877f759aa29c8a91a209e2d2dfeba9c1f14c0e Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Tue, 11 Feb 2020 12:39:58 +0100 Subject: [PATCH] Ancora test printing pdf --- LPA/LPA.csproj | 3 ++ LPA/MainForm.Designer.cs | 106 +++++++++++++++++++++++++++++++++------ LPA/MainForm.cs | 58 ++++++++++++++++++++- LPA/MainForm.resx | 3 ++ LPA/packages.config | 1 + 5 files changed, 154 insertions(+), 17 deletions(-) diff --git a/LPA/LPA.csproj b/LPA/LPA.csproj index 490ec37..edceff3 100644 --- a/LPA/LPA.csproj +++ b/LPA/LPA.csproj @@ -82,6 +82,9 @@ ..\packages\Pipelines.Sockets.Unofficial.2.1.1\lib\net461\Pipelines.Sockets.Unofficial.dll + + ..\packages\RawPrint.0.5.0\lib\net40\RawPrint.dll + ..\packages\SharpCompress.0.24.0\lib\net45\SharpCompress.dll diff --git a/LPA/MainForm.Designer.cs b/LPA/MainForm.Designer.cs index c902f53..9883fd7 100644 --- a/LPA/MainForm.Designer.cs +++ b/LPA/MainForm.Designer.cs @@ -28,34 +28,103 @@ /// private void InitializeComponent() { - this.label1 = new System.Windows.Forms.Label(); this.lbPrinters = new System.Windows.Forms.ListBox(); + this.btnReloadPrinters = new System.Windows.Forms.Button(); + this.webBrowserCtrl = new System.Windows.Forms.WebBrowser(); + this.btnOpenFile = new System.Windows.Forms.Button(); + this.txtFileSel = new System.Windows.Forms.TextBox(); + this.statusStrip1 = new System.Windows.Forms.StatusStrip(); + this.btnPrint = new System.Windows.Forms.Button(); + this.btnRawPrint = new System.Windows.Forms.Button(); this.SuspendLayout(); // - // label1 - // - this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(13, 13); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(54, 13); - this.label1.TabIndex = 0; - this.label1.Text = "Stampanti"; - // // lbPrinters // this.lbPrinters.FormattingEnabled = true; - this.lbPrinters.Location = new System.Drawing.Point(103, 13); + this.lbPrinters.Location = new System.Drawing.Point(100, 55); this.lbPrinters.Name = "lbPrinters"; - this.lbPrinters.Size = new System.Drawing.Size(219, 95); + this.lbPrinters.Size = new System.Drawing.Size(219, 160); this.lbPrinters.TabIndex = 1; // + // btnReloadPrinters + // + this.btnReloadPrinters.Location = new System.Drawing.Point(9, 55); + this.btnReloadPrinters.Name = "btnReloadPrinters"; + this.btnReloadPrinters.Size = new System.Drawing.Size(75, 23); + this.btnReloadPrinters.TabIndex = 2; + this.btnReloadPrinters.Text = "Printer List"; + this.btnReloadPrinters.UseVisualStyleBackColor = true; + this.btnReloadPrinters.Click += new System.EventHandler(this.btnReloadPrinters_Click); + // + // webBrowserCtrl + // + this.webBrowserCtrl.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.webBrowserCtrl.Location = new System.Drawing.Point(328, 13); + this.webBrowserCtrl.MinimumSize = new System.Drawing.Size(20, 20); + this.webBrowserCtrl.Name = "webBrowserCtrl"; + this.webBrowserCtrl.Size = new System.Drawing.Size(457, 471); + this.webBrowserCtrl.TabIndex = 3; + // + // btnOpenFile + // + this.btnOpenFile.Location = new System.Drawing.Point(10, 11); + this.btnOpenFile.Name = "btnOpenFile"; + this.btnOpenFile.Size = new System.Drawing.Size(75, 23); + this.btnOpenFile.TabIndex = 4; + this.btnOpenFile.Text = "Open PDF"; + this.btnOpenFile.UseVisualStyleBackColor = true; + this.btnOpenFile.Click += new System.EventHandler(this.btnOpenFile_Click); + // + // txtFileSel + // + this.txtFileSel.Location = new System.Drawing.Point(100, 13); + this.txtFileSel.Name = "txtFileSel"; + this.txtFileSel.Size = new System.Drawing.Size(219, 20); + this.txtFileSel.TabIndex = 5; + // + // statusStrip1 + // + this.statusStrip1.Location = new System.Drawing.Point(0, 487); + this.statusStrip1.Name = "statusStrip1"; + this.statusStrip1.Size = new System.Drawing.Size(785, 22); + this.statusStrip1.TabIndex = 6; + this.statusStrip1.Text = "statusStrip1"; + // + // btnPrint + // + this.btnPrint.Location = new System.Drawing.Point(9, 131); + this.btnPrint.Name = "btnPrint"; + this.btnPrint.Size = new System.Drawing.Size(75, 23); + this.btnPrint.TabIndex = 7; + this.btnPrint.Text = "Print menu"; + this.btnPrint.UseVisualStyleBackColor = true; + this.btnPrint.Click += new System.EventHandler(this.btnPrint_Click); + // + // btnRawPrint + // + this.btnRawPrint.Location = new System.Drawing.Point(9, 192); + this.btnRawPrint.Name = "btnRawPrint"; + this.btnRawPrint.Size = new System.Drawing.Size(75, 23); + this.btnRawPrint.TabIndex = 8; + this.btnRawPrint.Text = "Raw Print"; + this.btnRawPrint.UseVisualStyleBackColor = true; + this.btnRawPrint.Click += new System.EventHandler(this.btnRawPrint_Click); + // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); + this.ClientSize = new System.Drawing.Size(785, 509); + this.Controls.Add(this.btnRawPrint); + this.Controls.Add(this.btnPrint); + this.Controls.Add(this.statusStrip1); + this.Controls.Add(this.txtFileSel); + this.Controls.Add(this.btnOpenFile); + this.Controls.Add(this.webBrowserCtrl); + this.Controls.Add(this.btnReloadPrinters); this.Controls.Add(this.lbPrinters); - this.Controls.Add(this.label1); this.Name = "MainForm"; this.Text = "LPA"; this.ResumeLayout(false); @@ -64,9 +133,14 @@ } #endregion - - private System.Windows.Forms.Label label1; private System.Windows.Forms.ListBox lbPrinters; + private System.Windows.Forms.Button btnReloadPrinters; + private System.Windows.Forms.WebBrowser webBrowserCtrl; + private System.Windows.Forms.Button btnOpenFile; + private System.Windows.Forms.TextBox txtFileSel; + private System.Windows.Forms.StatusStrip statusStrip1; + private System.Windows.Forms.Button btnPrint; + private System.Windows.Forms.Button btnRawPrint; } } diff --git a/LPA/MainForm.cs b/LPA/MainForm.cs index 87f168e..7cec443 100644 --- a/LPA/MainForm.cs +++ b/LPA/MainForm.cs @@ -3,10 +3,12 @@ using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using RawPrint; namespace LPA { @@ -25,11 +27,65 @@ namespace LPA private void setupPrintersList() { + lbPrinters.Items.Clear(); foreach (string printer in System.Drawing.Printing.PrinterSettings.InstalledPrinters) { lbPrinters.Items.Add(printer); - //MessageBox.Show(printer); } } + + private void btnReloadPrinters_Click(object sender, EventArgs e) + { + setupPrintersList(); + } + + private void btnOpenFile_Click(object sender, EventArgs e) + { + OpenFileDialog openFileDialog1 = new OpenFileDialog + { + //InitialDirectory = @"D:\", + Title = "Selezione file", + + CheckFileExists = true, + CheckPathExists = true, + + DefaultExt = "pdf", + Filter = "pdf files (*.pdf)|*.pdf", + FilterIndex = 2, + RestoreDirectory = true, + + ReadOnlyChecked = true, + ShowReadOnly = true + }; + + if (openFileDialog1.ShowDialog() == DialogResult.OK) + { + showFile(openFileDialog1.FileName); + } + openFileDialog1.Dispose(); + } + + private void showFile(string fileName) + { + txtFileSel.Text = fileName; + webBrowserCtrl.Navigate(fileName); + } + + private void btnPrint_Click(object sender, EventArgs e) + { + webBrowserCtrl.ShowPrintDialog(); + //webBrowserCtrl.Print(); + + } + + private void btnRawPrint_Click(object sender, EventArgs e) + { + string printName = lbPrinters.SelectedItem.ToString(); + string filePath = txtFileSel.Text; + + IPrinter printer = new Printer(); + + printer.PrintRawFile(printName, filePath); + } } } diff --git a/LPA/MainForm.resx b/LPA/MainForm.resx index 1af7de1..174ebc7 100644 --- a/LPA/MainForm.resx +++ b/LPA/MainForm.resx @@ -117,4 +117,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + \ No newline at end of file diff --git a/LPA/packages.config b/LPA/packages.config index 32197c6..de9bd58 100644 --- a/LPA/packages.config +++ b/LPA/packages.config @@ -19,6 +19,7 @@ +