ByteScout PDF Renderer SDK - C# - Rendering PDF to image In Background Thread - ByteScout

ByteScout PDF Renderer SDK – C# – Rendering PDF to image In Background Thread

  • Home
  • /
  • Articles
  • /
  • ByteScout PDF Renderer SDK – C# – Rendering PDF to image In Background Thread

rendering PDF to image in background thread in C# using ByteScout PDF Renderer SDK

How to code rendering PDF to image in background thread in C#: How-To tutorial

ByteScout tutorials explain the material for programmers who use C#. ByteScout PDF Renderer SDK was made to help with rendering PDF to image in background thread in C#. ByteScout PDF Renderer SDK is the software development kit for rendering of PDF files into high quality images or thumbnails. Various functions are included as well: batch processing, PNG, TIFF output, selection area to render, layers management to render text or images or vectors only. Designed for use from web, desktop and middleware applications.

You will save a lot of time on writing and testing code as you may just take the code below and use it in your application. This C# sample code should be copied and pasted into your application’s code editor. Then just compile and run it to see how it works. C# application implementation typically includes multiple stages of the software development so even if the functionality works please test it with your data and the production environment.

Our website provides free trial version of ByteScout PDF Renderer SDK. It comes along with all these source code samples with the goal to help you with your C# application implementation.

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.IO; using System.Threading; using Bytescout.PDFRenderer; namespace RenderingInBackgroundThread { class Program { private static ManualResetEvent _doneEvent = new ManualResetEvent(false); // synchronization event private static int _counter; // thread counter static void Main(string[] args) { // Get all PDF files in current directory string[] pdfFiles = Directory.GetFiles(".", "*.pdf"); _counter = pdfFiles.Length; // Render PDF files in separate threads foreach (string pdfFile in pdfFiles) { Thread backgroundThread = new Thread(BackgroundThreadProc); backgroundThread.Start(pdfFile); Console.WriteLine(pdfFile + " - conversion started."); } // Wait until threads finished _doneEvent.WaitOne(); Console.WriteLine("Done."); Console.WriteLine(); Console.WriteLine("Press any key to continue..."); Console.ReadKey(); } // Rendering thread function private static void BackgroundThreadProc(object data) { string fileName = (string) data; try { // Create renderer using (RasterRenderer renderer = new RasterRenderer()) { renderer.LoadDocumentFromFile(fileName); // Setup rendering RenderingOptions renderingOptions = new RenderingOptions(); renderingOptions.JPEGQuality = 90; float renderingResolution = 300; // Render document pages for (int i = 0; i < renderer.GetPageCount(); i++) { renderer.Save(fileName + ".page" + i + ".jpg", RasterImageFormat.JPEG, i, renderingResolution, renderingOptions); } } Console.WriteLine(fileName + " - successfully converted."); } catch (Exception exception) { Console.WriteLine(exception.ToString()); } if (Interlocked.Decrement(ref _counter) == 0) { // Set event if all threads finished _doneEvent.Set(); } } } }

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout PDF Renderer SDK Home Page

Explore ByteScout PDF Renderer SDK Documentation

Explore Samples

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

Explore ByteScout PDF Renderer SDK Documentation

Explore Samples

Sign Up for ByteScout PDF Renderer SDK Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

Tutorials:

prev
next