ByteScout PDF Renderer SDK - C# - PDF to Image With Custom Size - ByteScout

ByteScout PDF Renderer SDK – C# – PDF to Image With Custom Size

  • Home
  • /
  • Articles
  • /
  • ByteScout PDF Renderer SDK – C# – PDF to Image With Custom Size

How to convert PDF to PNG in C# and ByteScout PDF Renderer SDK

The tutorial shows how to convert PDF to PNG in C#

ByteScout tutorials are designed to explain the code for both C# beginners and advanced programmers. ByteScout PDF Renderer SDK can convert PDF to PNG. It can be used from C#. ByteScout PDF Renderer SDK is the library that renders PDF into high quality images and thumbnails. Includes various functions like batch processing, PNG, TIFF output. Can be used from web and desktop applications.

You will save a lot of time on writing and testing code as you may just take the C# code from ByteScout PDF Renderer SDK for convert PDF to PNG below and use it in your application. Just copy and paste the code into your C# application’s code and follow the instruction. Implementing C# application typically includes multiple stages of the software development so even if the functionality works please test it with your data and the production environment.

ByteScout PDF Renderer SDK free trial version is available on our website. C# and other programming languages are supported.

Try ByteScout PDF Renderer SDK today: Get 60 Day Free Trial or sign up for Web API

Program.cs
      
using System; using System.Collections.Generic; using System.Diagnostics; using Bytescout.PDFRenderer; namespace PDF2ImageWithCustomSize { class Program { static void Main(string[] args) { // Specify Image Generation Inputs ImageGenerationInputs imageGenerationInputs = new ImageGenerationInputs(); imageGenerationInputs.AddCustomSize(width: 320, height: 420); imageGenerationInputs.AddCustomSize(width: 600, height: 800); imageGenerationInputs.EnableSaveAsPng = true; imageGenerationInputs.EnableSaveAsJpeg = true; imageGenerationInputs.EnableSaveAsTiff = true; // Create an instance of Bytescout.PDFRenderer.RasterRenderer object and register it RasterRenderer renderer = new RasterRenderer(); renderer.RegistrationName = "demo"; renderer.RegistrationKey = "demo"; // Load PDF document renderer.LoadDocumentFromFile("multipage.pdf"); // Specify Rendering Options to fine tune output generation RenderingOptions renderingOptions = new RenderingOptions(); renderingOptions.TIFFCompression = TIFFCompression.None; renderingOptions.VectorSmoothingMode = GraphicsTransformationQuality.HighQuality; // Loop through each custom size specified foreach (var itmCustomSize in imageGenerationInputs.CustomSizes) { // Loop through all pages for (int pageIndex = 0; pageIndex < renderer.GetPageCount(); pageIndex++) { // Perform save as PNG, if specified if (imageGenerationInputs.EnableSaveAsPng) { var pngImageName = {code}quot;output_{itmCustomSize.Key}x{itmCustomSize.Value}_page{pageIndex + 1}.png"; // Save png image per page, per custom size renderer.Save( destFileName: pngImageName, outputFormat: RasterImageFormat.PNG, pageIndex: pageIndex, width: itmCustomSize.Key, height: itmCustomSize.Value, renderingOptions: renderingOptions ); Console.WriteLine(pngImageName + " - Generated"); } // Perform save as JPG, if specified if (imageGenerationInputs.EnableSaveAsJpeg) { var jpgImageName = {code}quot;output_{itmCustomSize.Key}x{itmCustomSize.Value}_page{pageIndex + 1}.jpg"; // Save jpg image per page, per custom size renderer.Save( destFileName: jpgImageName, outputFormat: RasterImageFormat.JPEG, pageIndex: pageIndex, width: itmCustomSize.Key, height: itmCustomSize.Value, renderingOptions: renderingOptions ); Console.WriteLine(jpgImageName + " - Generated"); } } // Perform save as TIFF, if specified if (imageGenerationInputs.EnableSaveAsTiff) { var tiffImageName = {code}quot;output_{itmCustomSize.Key}x{itmCustomSize.Value}.tiff"; // Save tiff image per page, per custom size renderer.SaveMultipageTiff( destFileName: tiffImageName, startPageIndex: 0, endPageIndex: renderer.GetPageCount() - 1, width: itmCustomSize.Key, height: itmCustomSize.Value, renderingOptions: renderingOptions); Console.WriteLine(tiffImageName + " - Generated"); } } // Cleanup renderer.Dispose(); Console.ReadLine(); } } class ImageGenerationInputs { #region Constructor public ImageGenerationInputs() { CustomSizes = new List<KeyValuePair<int, int>>(); EnableSaveAsPng = true; } #endregion #region Properties public List<KeyValuePair<int, int>> CustomSizes { get; set; } public bool EnableSaveAsPng { get; set; } public bool EnableSaveAsJpeg { get; set; } public bool EnableSaveAsTiff { get; set; } #endregion #region Methods public void AddCustomSize(int width, int height) { this.CustomSizes.Add(new KeyValuePair<int, int>(width, height)); } #endregion } }

Try ByteScout PDF Renderer SDK today: 60 Day Free Trial (on-premise version) or sign up for Web API (on demand version)

VIDEO

ON-PREMISE VERSION

Get 60 Day Free Trial or Visit ByteScout PDF Renderer SDK page

Explore ByteScout PDF Renderer SDK documentation

WEB API

Sign Up for free Web API key

Explore Web API Documentation

Tutorials:

prev
next