ByteScout PDF 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 PDF Suite – C# – Pdf to image with custom size with pdf renderer sdk

  • Home
  • /
  • Articles
  • /
  • ByteScout PDF 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 PDF Suite

Learn to code in C# to make pdf to image with custom size with pdf renderer sdk with this simple How-To tutorial

This page helps you to learn from code samples for programming in C#. ByteScout PDF Suite was created to assist pdf to image with custom size with pdf renderer sdk in C#. ByteScout PDF Suite is the bundle that provides six different SDK libraries to work with PDF from generating rich PDF reports to extracting data from PDF documents and converting them to HTML. This bundle includes PDF (Generator) SDK, PDF Renderer SDK, PDF Extractor SDK, PDF to HTML SDK, PDF Viewer SDK and PDF Generator SDK for Javascript.

If you want to quickly learn then these fast application programming interfaces of ByteScout PDF Suite for C# plus the guideline and the C# code below will help you quickly learn pdf to image with custom size with pdf renderer sdk. If you want to know how it works, then this C# sample code should be copied and pasted into your application’s code editor. Then just compile and run it. Use of ByteScout PDF Suite in C# is also described in the documentation included along with the product.

If you want to try other samples for C# then free trial version of ByteScout PDF 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 PDF Suite Home Page

Explore ByteScout PDF Suite Documentation

Explore Samples

Sign Up for ByteScout PDF 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 PDF Suite Home Page

Explore ByteScout PDF Suite Documentation

Explore Samples

Sign Up for ByteScout PDF Suite Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

Tutorials:

prev
next