1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
using System.Drawing.Imaging; using System.Diagnostics; namespace PdfToPng { class Program { static void Main(string[] args) { string pdfFile = "result.pdf"; string outputFolder = "pdfimages"; ConvertPdfToPng(pdfFile, outputFolder); // Open the folder once the conversion is done Process.Start(new ProcessStartInfo { FileName = outputFolder, UseShellExecute = true, Verb = "open" }); Console.WriteLine("Done!"); } private static void ConvertPdfToPng(string pdfFile, string outputFolder) { // Create the output folder if it doesn't exist if (!Directory.Exists(outputFolder)) { Directory.CreateDirectory(outputFolder); } using (var document = PdfiumViewer.PdfDocument.Load(pdfFile)) { for (int i = 0; i < document.PageCount; i++) { using (var image = document.Render(i, 300, 300, true)) { // Save the image in the specified output folder string imagePath = Path.Combine(outputFolder, $"page_{i}.png"); image.Save(imagePath, ImageFormat.Png); } } } } } } |