diff --git a/Printing-Examples/How to print a pdf document in .NET Core console application/ConsoleApp.sln b/Printing-Examples/How to print a pdf document in .NET Core console application/ConsoleApp.sln new file mode 100644 index 0000000..884fe8f --- /dev/null +++ b/Printing-Examples/How to print a pdf document in .NET Core console application/ConsoleApp.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.9.34622.214 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp", "ConsoleApp\ConsoleApp.csproj", "{4343B126-0BE7-4A4C-BD14-CEFB86AA8DF2}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {4343B126-0BE7-4A4C-BD14-CEFB86AA8DF2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4343B126-0BE7-4A4C-BD14-CEFB86AA8DF2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4343B126-0BE7-4A4C-BD14-CEFB86AA8DF2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4343B126-0BE7-4A4C-BD14-CEFB86AA8DF2}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {420AD2DD-DF09-4048-9EDC-E17668C6235F} + EndGlobalSection +EndGlobal diff --git a/Printing-Examples/How to print a pdf document in .NET Core console application/ConsoleApp/ConsoleApp.csproj b/Printing-Examples/How to print a pdf document in .NET Core console application/ConsoleApp/ConsoleApp.csproj new file mode 100644 index 0000000..85fef78 --- /dev/null +++ b/Printing-Examples/How to print a pdf document in .NET Core console application/ConsoleApp/ConsoleApp.csproj @@ -0,0 +1,15 @@ + + + + Exe + net8.0 + enable + enable + + + + + + + + diff --git a/Printing-Examples/How to print a pdf document in .NET Core console application/ConsoleApp/Input.pdf b/Printing-Examples/How to print a pdf document in .NET Core console application/ConsoleApp/Input.pdf new file mode 100644 index 0000000..8773442 Binary files /dev/null and b/Printing-Examples/How to print a pdf document in .NET Core console application/ConsoleApp/Input.pdf differ diff --git a/Printing-Examples/How to print a pdf document in .NET Core console application/ConsoleApp/Program.cs b/Printing-Examples/How to print a pdf document in .NET Core console application/ConsoleApp/Program.cs new file mode 100644 index 0000000..e4a99d0 --- /dev/null +++ b/Printing-Examples/How to print a pdf document in .NET Core console application/ConsoleApp/Program.cs @@ -0,0 +1,52 @@ +using SkiaSharp; +using Syncfusion.PdfToImageConverter; +using System.Drawing; +using System.Drawing.Printing; +using System.IO; + +namespace ConsoleApp +{ + internal class Program + { + static int itr = 0; + static Bitmap[] bitmaps; + static void Main(string[] args) + { + //Initialize PDF to Image converter. + PdfToImageConverter imageConverter = new PdfToImageConverter(); + //Load the PDF document as a stream + FileStream inputStream = new FileStream("../../../Input.pdf", FileMode.Open, FileAccess.ReadWrite); + imageConverter.Load(inputStream); + bitmaps = new Bitmap[imageConverter.PageCount - 1]; + //Convert PDF to Image. + Stream[] outputStream = imageConverter.Convert(0, imageConverter.PageCount - 1, false, false); + bitmaps = BitmapConverter.ConvertStreamsToBitmaps(outputStream); + PrintDocument printDocument = new PrintDocument(); + printDocument.PrintPage += PrintDocument_PrintPage; + printDocument.Print(); + } + + private static void PrintDocument_PrintPage(object sender, PrintPageEventArgs e) + { + e.Graphics.DrawImage(bitmaps[itr], 0, 0, e.PageBounds.Width, e.PageBounds.Height); + e.HasMorePages = itr < bitmaps.Length - 1; + itr = itr + 1; + } + } + + public class BitmapConverter + { + public static Bitmap[] ConvertStreamsToBitmaps(Stream[] streams) + { + Bitmap[] bitmaps = new Bitmap[streams.Length]; + + for (int i = 0; i < streams.Length; i++) + { + bitmaps[i] = new Bitmap(streams[i]); + } + + return bitmaps; + } + } + +}