In this part, we provide a fully working example in C# for ASP.NET PDF to PNG conversion. It consists of a web page that displays the output png image rasterized from PDF document page.
using System; using System.Web.UI; using System.IO; using PQScan.PDFToImage; public partial class _Default: System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { // Prepare a PDF file. string pdfFileName = Server.MapPath("sample.pdf"); // Create an instance of PQScan.PDFToImage.PDFDocument object. PDFDocument pdfDoc = new PDFDocument(); // Load the PDF file. pdfDoc.LoadPDF(pdfFileName); // Prepare response. Response.Clear(); Response.ContentType = "image/png"; // Render the first page of PDF file to the output image. System.Drawing.Image pngImage = pdfDoc.ToImage(0); using (MemoryStream ms = new MemoryStream()) { // Save image to png format. pngImage.Save(ms, System.Drawing.Imaging.ImageFormat.Png); // Display png image to the aspx web page. Response.OutputStream.Write(ms.GetBuffer(), 0, (int)ms.Length); } pngImage.Dispose(); Response.End(); } }