|
| 1 | +# Create or Generate images from PDF in .NET application |
| 2 | + |
| 3 | +This Syncfusion® PDF to image converter library allows converting PDF documents to images without opening the document.Plaese refer [PdfToImageConverter](https://help.syncfusion.com/document-processing/pdf/conversions/pdf-to-image/net/convert-pdf-to-image) documentation. |
| 4 | + |
| 5 | +## Steps to create images from PDF in .NET application |
| 6 | + |
| 7 | +Step 1: Create a new .NET Console application. |
| 8 | + |
| 9 | +Step 2: Install the [Syncfusion.PdfToImageConverter.Net](https://www.nuget.org/packages/Syncfusion.PdfToImageConverter.Net/) [NuGet package] |
| 10 | + |
| 11 | +Step 3: Add the Data folder and Output folder parallel to the Program.cs file.Data folder will hold the PDF files that you want to convert.Output Folder will store the resulting image files after conversion. |
| 12 | + |
| 13 | +Step 4: Add the following namespaces and code in application Programe.cs file. |
| 14 | + |
| 15 | +``` |
| 16 | +using Syncfusion.PdfToImageConverter; |
| 17 | +using System.IO; |
| 18 | +
|
| 19 | +//Initialize PDF to Image converter. |
| 20 | +PdfToImageConverter imageConverter = new PdfToImageConverter(); |
| 21 | +
|
| 22 | +//Load the PDF document as a stream |
| 23 | +FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.ReadWrite); |
| 24 | +
|
| 25 | +imageConverter.Load(inputStream); |
| 26 | +
|
| 27 | +//Convert PDF to Image. |
| 28 | +Stream outputStream = imageConverter.Convert(0, false, false); |
| 29 | +
|
| 30 | +//Rewind the stream position to the beginning before copying. |
| 31 | +outputStream.Position = 0; |
| 32 | +
|
| 33 | +//Create file stream. |
| 34 | +using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Output.jpeg"), FileMode.Create, FileAccess.ReadWrite)) |
| 35 | +{ |
| 36 | + //Save the image to file stream. |
| 37 | + outputStream.CopyTo(outputFileStream); |
| 38 | +} |
| 39 | +//Dispose the imageConverter |
| 40 | +imageConverter.Dispose(); |
| 41 | +``` |
| 42 | +Step 5 : Run the application, and the images will be saved in the Output folder. |
| 43 | + |
| 44 | +You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/WPF-PDFViewer-Examples/tree/master/PDF-to-image/.NET/PDFPage-to-Image) |
0 commit comments