ByteScout Premium Suite - C# - Pdf to image with custom size with pdf renderer sdk - ByteScout
Announcement
Our ByteScout SDK products are sunsetting as we focus on expanding new solutions.
Learn More Open modal
Close modal
Announcement Important Update
ByteScout SDK Sunsetting Notice
Our ByteScout SDK products are sunsetting as we focus on our new & improved solutions. Thank you for being part of our journey, and we look forward to supporting you in this next chapter!

ByteScout Premium Suite – C# – Pdf to image with custom size with pdf renderer sdk

  • Home
  • /
  • Articles
  • /
  • ByteScout Premium Suite – C# – Pdf to image with custom size with pdf renderer sdk

pdf to image with custom size with pdf renderer sdk in C# using ByteScout Premium Suite

How to apply ByteScout Premium Suite for pdf to image with custom size with pdf renderer sdk in C#

This page explains the steps and algorithm of implementing pdf to image with custom size with pdf renderer sdk and how to make it work in your application. ByteScout Premium Suite was made to help with pdf to image with custom size with pdf renderer sdk in C#. ByteScout Premium Suite is the set that includes 12 SDK products from ByteScout including tools and components for PDF, barcodes, spreadsheets, screen video recording.

Save time on writing and testing code by using the code below and use it in your application. If you want to implement this functionality, you should copy and paste code below into your app using code editor. Then compile and run your application. Enjoy writing a code with ready-to-use sample C# codes to implement pdf to image with custom size with pdf renderer sdk using ByteScout Premium Suite.

If you want to try other samples for C# then free trial version of ByteScout Premium Suite is available on our website.

On-demand (REST Web API) version:
 Web API (on-demand version)

On-premise offline SDK for Windows:
 60 Day Free Trial (on-premise)

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 } }

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout Premium Suite Home Page

Explore ByteScout Premium Suite Documentation

Explore Samples

Sign Up for ByteScout Premium Suite Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

VIDEO

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout Premium Suite Home Page

Explore ByteScout Premium Suite Documentation

Explore Samples

Sign Up for ByteScout Premium Suite Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

Tutorials:

prev
next