ASP.NET PDF to JPG Converter
How to view, convert PDF to multiple JPG image files in web browser in ASP.NET MVC on Azure using C#?
How to read, view an existing PDF online, and convert modified PDF to JPG files using C# in ASP.NET Core MVC web application.
Open, read, view and markup an existing PDF network file, and export to JPG images in ASP.NET using C# is very simple. EdgePDF provides a simple C# demo code to accomplish the job.
- Convert PDF pages to high quality JPG image files
- Converted image with advanced options, such as image resolution, page zooming, colorspace
- Easy to enable PDF to JPG conversion feature in ASP.NET Forms, MVC web applications using C#
How to view, convert PDF to JPG programmatically in asp.net using C#
Preparation
To run the following tutorial successfully, we need the following setup ready.
- For ASP.NET Core web app: Setup EdgePDF
- For ASP.NET Core MVC web app: Setup EdgePDF
- For ASP.NET (.net framework): Setup EdgePDF on IIS
- Several demo PDF files in folder C:\temp\
How to read, view PDF and convert to JPG image files in web browser using ASP.NET C#?
The following steps and C# source code will learn how to view, edit a PDF file in web browser using C# ASP.NET, and export modified PDF to JPG files, one PDF page per JPEG image file in the web server in ASP.NET web application.
After you have completed the following guide, you can open, view, comment a PDF file online through url (a sample url
http://localhost:56643/?yourtarget=pdf-1.pdf)
To convert the modified PDF document to JPEG files in web server
- Go to EdgePDF toolbar in web browser
- Click tab "Customize"
- Click command button "Save Server"
- For ASP.NET Core web app, open file UserCommandProcessMiddleware.cs from /DemoProjects/EdgePDF for ASP.NET Core/
- For ASP.NET (.net framework) project, open file UserCommandProcessHandler.ashx from {EdgePDF demo project}/RasterEdge_Resource_Files/
- Go to method SaveFile_OnServer()
- Create a new PDFDocument object with EdgePDF displayed PDF file loaded
- Create a new ImageOutputOption object to apply converted JPG image settings. View more information about
How to convert PDF page to JPG using C# with advanced image options
- Set output image type as ImageType.JPEG
- Set JPG color as a color image
- Choose progressive image
- Set the JPG image quality to the highest level: 100
- Set PDF page zoom value and JPG image resolution
- Use method PDFDocument.ConvertToImages() save and convert the modified PDF document into JPG image files, one PDF page will produce one JPG image file.
public override void SaveFile_OnServer(String fid, String savePath, String responseMsg)
{
// You can process saved pdf document here, like add watermark, ...
var documentPath = savePath;
if (!String.IsNullOrEmpty(documentPath))
{
Logger.LogFile(fid, "SaveFileOnServer: output file path " + documentPath, LogType.DEBUG);
// To verify the output file.
RasterEdge.Imaging.Basic.BaseDocument document = null;
if (documentPath.EndsWith(".pdf"))
{
// document object includes user modified content
document = new RasterEdge.XDoc.PDF.PDFDocument(documentPath);
}
if (document != null)
{
// Get the upload information of the file
RasterEdge.WDP.DocUploadInfo docinfo = RasterEdge.WDP.Manager.FileManager.getUploadinfoByFid(fid);
// Get your file open url parameters value, if needed.
String paraFilepathValue = docinfo.GetRequestParameters("yourtarget");
if (!String.IsNullOrEmpty(paraFilepathValue))
{
try
{
ImageOutputOption jpgImageOptions = new ImageOutputOption();
jpgImageOptions.Type = ImageType.JPEG;
jpgImageOptions.Color = ColorType.Color;
jpgImageOptions.JpegProgressive = true;
jpgImageOptions.JpegQualityLevel = 100;
jpgImageOptions.Zoom = 2;
jpgImageOptions.Resolution = 300;
int startIdx = documentPath.LastIndexOf("/");
int endIdx = documentPath.LastIndexOf(".");
String docName = documentPath.Substring(startIdx + 1, endIdx - startIdx - 1) + "-";
document.ConvertToImages(jpgImageOptions, @"C:\temp", docName);
}
catch (Exception ex)
{
// Process error code, and return error information here
Logger.LogFile(fid, ex.Message + ". fail to save file to server.", LogType.ERROR);
}
}
else
{
Logger.LogFile(fid, "no 'yourtarget' in the HTTPRequest.", LogType.INFO);
}
}
else
{
Logger.LogFile(fid, "output PDF file is invalid.", LogType.ERROR);
}
}
else
{
Logger.LogFile(fid, "fail to save file to server. output file path is null or empty.", LogType.ERROR);
}
}
After complete the Converting PDF to JPG images on ASP.NET MVC web application, you could easily deploy it to Azure cloud service. View details at
How to deploy ASP.NET MVC PDF viewer web application to Azure?