Skip to main content
Skip table of contents

How do I use pdfRender in a .NET environment?


Introduction

While iText does not currently offer a native C# version of pdfRender as it does for Java, we do provide a command-line version meaning it is fully possible to integrate pdfRender into any .NET project using pdfRender's CLI functionality. Below is a table which shows all of the potential parameters when utilizing pdfRender's CLI infrastructure. 

Note that --license is required, and is used to specify the location of your pdfRender license file.

The following is a list of the image file types which a PDF can be rendered as (determined by the "type" variable above):

  • BMP
  • HEIC
  • JPEG
  • PNG
  • TIFF
  • WEBP

Example

Below is a C# code snippet which converts an input PDF into a TIFF file on a Windows machine. In order for this code to function correctly, you'll need to download the executable version of pdfRender. That download can be found here.

C#
using System;
using System.Diagnostics;

namespace Example
{
    public class RenderthePDF
    {

        public const String SRC = "input_file_path/input.pdf";
        public const String license_file = "license_file_path/license_key.xml";
        public const String DEST_DIR = "output_file_path/";

        public static void Main(String[] args)
        {
            new RenderthePDF().RenderPDF(SRC, DEST_DIR);
        }

        public virtual void RenderPDF(string src, string outDirectory)
        {
            // The path to the executable pdfRender Application (which by this point you have hopefully downloaded).
            var pdfRenderPath = @"C:/Users/pdfRender.exe";

            Process process = new Process();
            ProcessStartInfo startInfo = new ProcessStartInfo();
            startInfo.WindowStyle = ProcessWindowStyle.Hidden;

            // Instantiates the Windows Command Shell.
            startInfo.FileName = "cmd.exe";

            // The command line arguments for pdfRender.
            //    Type modifies the output file type (Important).
            startInfo.Arguments = "/c " + pdfRenderPath +
            " --pdf " + src +
            " --out-dir " + outDirectory +
            " --type tiff" +
            " --scaling 0.7" +
            " --license " + license_file;

            startInfo.RedirectStandardOutput = true;
            startInfo.UseShellExecute = false;
            process.StartInfo = startInfo;
            process.Start();

            var output = process.StandardOutput.ReadToEnd();

            // Notifies via Command Line whether the PDF rendered successfully.
            Console.WriteLine(output);
            process.WaitForExit();
        }
    }
}

In fact, pdfRender CLI has the potential to function with any language which can access the command line. So, one can apply the same fundamentals of accessing and interacting with the CLI via a language like Python, to achieve the same outcome.


JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.