diff --git a/Printing/BatchPrinting/BatchPrinting.slnx b/Printing/BatchPrinting/BatchPrinting.slnx new file mode 100644 index 0000000..ed8bf09 --- /dev/null +++ b/Printing/BatchPrinting/BatchPrinting.slnx @@ -0,0 +1,3 @@ + + + diff --git a/Printing/BatchPrinting/BatchPrinting/BatchPrinting.csproj b/Printing/BatchPrinting/BatchPrinting/BatchPrinting.csproj new file mode 100644 index 0000000..cb7b48a --- /dev/null +++ b/Printing/BatchPrinting/BatchPrinting/BatchPrinting.csproj @@ -0,0 +1,19 @@ + + + + WinExe + net10.0-windows + enable + true + enable + + + + + + + + + + + \ No newline at end of file diff --git a/Printing/BatchPrinting/BatchPrinting/BatchPrinting.csproj.user b/Printing/BatchPrinting/BatchPrinting/BatchPrinting.csproj.user new file mode 100644 index 0000000..7814ea2 --- /dev/null +++ b/Printing/BatchPrinting/BatchPrinting/BatchPrinting.csproj.user @@ -0,0 +1,8 @@ + + + + + Form + + + diff --git a/Printing/BatchPrinting/BatchPrinting/Data/GIS Succinctly.pdf b/Printing/BatchPrinting/BatchPrinting/Data/GIS Succinctly.pdf new file mode 100644 index 0000000..86d5eba Binary files /dev/null and b/Printing/BatchPrinting/BatchPrinting/Data/GIS Succinctly.pdf differ diff --git a/Printing/BatchPrinting/BatchPrinting/Data/LightSwitch_Succinctly.pdf b/Printing/BatchPrinting/BatchPrinting/Data/LightSwitch_Succinctly.pdf new file mode 100644 index 0000000..474b83f Binary files /dev/null and b/Printing/BatchPrinting/BatchPrinting/Data/LightSwitch_Succinctly.pdf differ diff --git a/Printing/BatchPrinting/BatchPrinting/Form1.Designer.cs b/Printing/BatchPrinting/BatchPrinting/Form1.Designer.cs new file mode 100644 index 0000000..d323116 --- /dev/null +++ b/Printing/BatchPrinting/BatchPrinting/Form1.Designer.cs @@ -0,0 +1,39 @@ +namespace BatchPrinting +{ + partial class Form1 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Text = "Form1"; + } + + #endregion + } +} diff --git a/Printing/BatchPrinting/BatchPrinting/Form1.cs b/Printing/BatchPrinting/BatchPrinting/Form1.cs new file mode 100644 index 0000000..6781096 --- /dev/null +++ b/Printing/BatchPrinting/BatchPrinting/Form1.cs @@ -0,0 +1,94 @@ +using Syncfusion.Windows.Forms.PdfViewer; + +namespace BatchPrinting +{ + public partial class Form1 : Form + { + private string pdfFolder = @"../../../Data"; + PdfViewerControl viewer; + + private string[] files = []; + private int currentIndex = 0; + + public Form1() + { + InitializeComponent(); + + viewer = new PdfViewerControl(); + viewer.EndPrint += Viewer_EndPrint; + + this.Shown += Form1_Shown; + } + private void Form1_Shown(object? sender, EventArgs e) + { + LoadFilesAndStartPrinting(); + } + private void LoadFilesAndStartPrinting() + { + try + { + if (!Directory.Exists(pdfFolder)) + { + return; + } + + files = Directory + .GetFiles(pdfFolder, "*.pdf") + .ToArray(); + + if (files.Length == 0) + { + return; + } + + currentIndex = 0; + PrintCurrentFile(); + } + catch (Exception ex) + { + MessageBox.Show( + $"Failed to load PDF files.\n\n{ex.Message}", + "Error", + MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + private void PrintCurrentFile() + { + if (currentIndex >= files.Length) + { + MessageBox.Show( + "Batch printing completed.", + "Completed", + MessageBoxButtons.OK, + MessageBoxIcon.Information); + + return; + } + + try + { + string file = files[currentIndex]; + + viewer.Load(file); + viewer.Print(false); + } + catch (Exception ex) + { + // Log error and continue with next file + MessageBox.Show( + $"Failed to print:\n{files[currentIndex]}\n\n{ex.Message}", + "Print Error", + MessageBoxButtons.OK, + MessageBoxIcon.Warning); + } + } + + private void Viewer_EndPrint(object? sender, EndPrintEventArgs e) + { + currentIndex++; + BeginInvoke(PrintCurrentFile); + } + } +} diff --git a/Printing/BatchPrinting/BatchPrinting/Form1.resx b/Printing/BatchPrinting/BatchPrinting/Form1.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Printing/BatchPrinting/BatchPrinting/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Printing/BatchPrinting/BatchPrinting/Program.cs b/Printing/BatchPrinting/BatchPrinting/Program.cs new file mode 100644 index 0000000..39eb89f --- /dev/null +++ b/Printing/BatchPrinting/BatchPrinting/Program.cs @@ -0,0 +1,17 @@ +namespace BatchPrinting +{ + internal static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + // To customize application configuration such as set high DPI settings or default font, + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + Application.Run(new Form1()); + } + } +} \ No newline at end of file