Document Conversion SDK for .NET C#

Discover ConvertAPI's C# .NET SDK for seamless document conversion and management. Integrate powerful tools to convert, merge, compress, and redact PDFs and other file formats effortlessly in your .NET applications.

NuGet GitHub

Integrate within minutes

The ConvertAPI C# Client offers a simple and efficient way to integrate powerful file conversion capabilities into your .NET Framework, .NET Core, and .NET projects. With support for a wide range of formats, it allows you to seamlessly convert documents, images, spreadsheets, and more. Additionally, the library provides advanced PDF manipulations such as redacting, merging, encrypting, splitting, repairing, and decrypting files.

It is easy to start converting documents using C# in a few simple steps:

1

Sign up for a free account

Sign up for free and receive 250 conversions to try and evaluate our service. You will receive a free trial with no credit card required upon registration!

2

Set up the conversion online

On your account dashboard you will access an intuitive UI tool that allows you to set up the conversion, adjust the parameters, and try the conversion online with zero code.

3

Copy auto-generated code snippet

Once you have set up the conversion parameters and are happy with the conversion results, you will receive an auto-generated C# code snippet with your custom parameters!

Get started now

Enterprise-Grade Document Processing

Document management toolkit for C#

With a simple integration in C#, you can convert documents not only to PDF, but also to images, text files, spreadsheets, ZIP archives, HTML, and many other destination formats, making it easy to automate file processing within your applications.

Select from 300+ converters and tools!

File Converter Suite

High-performance and unbeatable accuracy document converter suite with support for over 300+ conversion.

Document Builder using C#

Generate dynamic DOCX and PDF documents like invoices, contracts, reports, on the fly.

Document Management tools

Protect, redact, compare, watermark, flatten, compress and modify your documents using ConvertAPI .NET SDK.

Security and Decryption

Protect and unprotect PDFs, MS Office Powerpoint and MS Office Word documents.

AI Data Extractor

Built to scale with your business, whether you're handling a few conversions or thousands.

Archiving & Optimization

Reduce file sizes without losing quality. Archive converters are designed to handle over 100 different file formats.

Configure it online - we will generate the C# code for you!

Configure your file conversion directly online using our intuitive interface. Select the desired parameters and see the results in real-time. Once you're satisfied, we’ll automatically generate the C# code for you, making integration into your project effortless. No need to start from scratch - just copy the code and implement it seamlessly into your .NET application!

Get started now

File conversion example using C#

Converting documents using our .NET SDK has never been easier. Whether converting or manipulating documents, the ConvertAPI library simplifies the process with minimal code and maximum efficiency. First, you want to install the ConvertAPI NuGet library by run this line from Package Manager Console:

Install-Package ConvertApi

After installing the library and obtaining your authentication token, you can access all our converters and tools!

DOCX to PDF conversion example

In just a few lines of code, you can specify your source file and fine-tune the conversion by enabling or disabling various features such as markups, tags, metadata, headings, bookmarks, and table-of-contents updates. The library handles all the complexity under the hood, allowing you to focus on seamlessly integrating document conversion into your application’s workflow.

// Code snippet is using the ConvertAPI JavaScript Client: https://github.com/ConvertAPI/convertapi-library-js

// Code snippet is using the ConvertAPI Node.js Client: https://github.com/ConvertAPI/convertapi-nodejs

// Code snippet is using the ConvertAPI PHP Client: https://github.com/ConvertAPI/convertapi-php

// Code snippet is using the ConvertAPI Java Client: https://github.com/ConvertAPI/convertapi-java

// Code snippet is using the ConvertAPI C# Client: https://github.com/ConvertAPI/convertapi-dotnet

# Code snippet is using the ConvertAPI Ruby Client: https://github.com/ConvertAPI/convertapi-ruby

# Code snippet is using the ConvertAPI Python Client: https://github.com/ConvertAPI/convertapi-python

// Code snippet is using the ConvertAPI Go Client: https://github.com/ConvertAPI/convertapi-go

REM Code snippet is using the command line utility program: https://github.com/ConvertAPI/convertapi-cli

<!-- For conversions with the multiple file result please refer to this example: https://repl.it/@ConvertAPI/HTML-Form-with-multiple-file-result -->

From Stream to Stream

This example demonstrates how to convert a file using in-memory streams without saving to disk. This is ideal for scenarios where files are received from or sent to external systems via streams, such as web APIs or cloud storage.

Key Features:

  • Reads the source file into a MemoryStream.
  • Performs the conversion entirely in memory.
  • Writes the converted file to another MemoryStream.

It is super efficient for applications that handle files dynamically without intermediate storage.

var convertApi = new ConvertApi("api_key");
const string htmlString = "<!DOCTYPE html><html><body><h1>My First Heading</h1><p>My first paragraph.</p></body></html>";
var stream = new MemoryStream(Encoding.UTF8.GetBytes(htmlString));

var convertToPdf = await convertApi.ConvertAsync("html", "pdf",
    new ConvertApiFileParam(stream, "test.html")
);

var outputStream = await convertToPdf.Files.First().FileStreamAsync();

Console.Write(new StreamReader(outputStream).ReadToEnd());
Console.WriteLine("End of file stream.");

Convert a Remote File

The following example illustrates how to convert a file directly from a remote URL. This approach is useful when the source file is hosted online and doesn't need to be downloaded manually.

Key Features:

  • Reads the source file from a remote URL.
  • Converts the remote file to the desired format.
  • Saves the converted file locally.

It is useful for automating conversions of files available on public URLs.

var convertApi = new ConvertApi("api_key");
var sourceFile = new Uri("https://cdn.convertapi.com/public/files/demo.pptx");

Console.WriteLine($"Converting online PowerPoint file {sourceFile} to PDF...");

var convertToPdf = await convertApi.ConvertAsync("pptx", "pdf", new ConvertApiFileParam(sourceFile));
var outputFileName = convertToPdf.Files[0];
var fileInfo = await outputFileName.SaveFileAsync(Path.Combine(Path.GetTempPath(), outputFileName.FileName));

Console.WriteLine("The PDF saved to " + fileInfo);

Convert URL To PDF

The following example illustrates how to convert a file from a remote URL to PDF. This approach is useful when the source file is hosted online and doesn't need to be downloaded manually.

Key Features:

  • Inputs the web page URL.
  • Converts the web page content into a PDF document.
  • Saves the resulting PDF file.

It is ideal for creating PDF snapshots of web pages for record-keeping or offline access.

var convertApi = new ConvertApi("api_key");

Console.WriteLine("Converting web page https://en.wikipedia.org/wiki/Data_conversion to PDF...");

var response = await convertApi.ConvertAsync("web", "pdf", 
    new ConvertApiParam("Url", "https://en.wikipedia.org/wiki/Data_conversion"), 
    new ConvertApiParam("FileName", "web-example"));

var fileSaved = await response.Files.SaveFilesAsync(Path.GetTempPath());

Console.WriteLine("The web page PDF saved to " + fileSaved.First());

Conversion Workflow

Let's demonstrate a multi-step conversion process, such as converting a PDF file to JPG and then compressing multiple JPG files to a ZIP archive. This example showcases how to chain multiple conversions seamlessly.

Key Features:

  • Performs sequential conversions.
  • Handles intermediate files between steps.
  • Saves the final output after all conversions.

This use case is beneficial for complex workflows requiring multiple file transformations.

var convertApi = new ConvertApi("api_key");

Console.WriteLine("Converting PDF to JPG and compressing result files with ZIP");
var fileName = Path.Combine(Path.GetTempPath(), "test.pdf");

var firstTask = await convertApi.ConvertAsync("pdf", "jpg", new ConvertApiFileParam(fileName));
Console.WriteLine($"Conversions done. Cost: {firstTask.ConversionCost}. Total files created: {firstTask.FileCount()}");

var secondsTask = await convertApi.ConvertAsync("jpg", "zip", new ConvertApiFileParam(firstTask));
var saveFiles = await secondsTask.Files.SaveFilesAsync(Path.GetTempPath());

Console.WriteLine($"Conversions done. Cost: {secondsTask.ConversionCost}. Total files created: {secondsTask.FileCount()}");
Console.WriteLine($"File saved to {saveFiles.First().FullName}");

Exception Handling

Below is an example of how to handle exceptions and errors during the conversion process. This ensures that applications can gracefully handle issues like invalid inputs or network errors. The ConvertApiException class is thrown when an error occurs during the conversion process. You can read the detailed error message from the response body as well as the status code.

Proper exception handling is essential for building robust applications that can manage and log errors effectively.

try
{
    var convertApi = new ConvertApi("api_token");
    const string sourceFile = @"..\..\..\TestFiles\test.docx";

    var convert = await convertApi.ConvertAsync("pdf", "split",
        new ConvertApiFileParam(sourceFile));
}
//Catch exceptions and write details
catch (ConvertApiException e)
{
    Console.WriteLine("Status Code: " + e.StatusCode);
    Console.WriteLine("Response: " + e.Response);
}          

Using our C# library, you can seamlessly access over 300+ converters and document management tools from a single, centralized interface.

Whether you prefer to convert documents by providing a URL, working directly with file streams, or simply supplying file paths from your local machine, our library offers flexible input options that adapt to your workflow.

To explore more advanced techniques and customization strategies, be sure to browse our GitHub examples folder.

Take a look at C# code samples

View on GitHub

Automate Your Document Management using C#

Take control of your documents with our C# document management SDK. From basic conversions to full workflow automation, we provide the expertise and tools you need to manage your documents efficiently.

Enterprise-Grade Security

We ensure that all document processing is handled securely in the cloud, adhering to industry-leading standards like ISO 27001, GDPR, and HIPAA. To enhance security even further, we can ensure that no files or data are stored on our servers and never leave your country.

Learn more about security

Businesses trust us

Highest rated File Conversion API on major B2B software listing platforms: Capterra, G2, and Trustpilot.

"ConvertAPI has been a game-changer for our document automation workflows. Their conversion accuracy and API reliability are unmatched in the industry for over 7 years."

"ConvertAPI is a reliable, cost-effective solution with a proven track record of stability. It has grown significantly in maturity, adopting enterprise-grade practices over the years."

"We've integrated ConvertAPI across our entire document processing platform. The performance is exceptional and the support team is always responsive. Highly recommended!"

Frequently Asked Questions

What is this library used for?

The ConvertAPI .NET C# SDK allows developers to integrate powerful file conversion, manipulation, and management features directly into their .NET applications. From converting PDFs to merging documents and extracting text, it supports hundreds of file formats and operations.

Can I convert large files using this SDK?

Yes. The SDK is designed to handle large documents efficiently. However, performance may vary depending on file size, complexity, and your server’s resources. You can also use asynchronous calls and workflows to optimize performance for large-scale conversions.

How do I install the ConvertAPI .NET C# SDK?

You can easily install the SDK via NuGet. Just run Install-Package ConvertApi in the Package Manager Console, or search for “ConvertApi” in the NuGet Package Manager GUI.

What file formats are supported by the ConvertAPI .NET C# SDK?

The SDK supports over 300+ file formats, including PDF, DOCX, XLSX, PPTX, JPG, PNG, HTML, and many others. This makes it ideal for a wide range of document conversion and processing tasks.

Is it possible to customize conversions using the ConvertAPI .NET C# SDK?

Absolutely. You can fine-tune various parameters, such as resolution, quality, page ranges, and metadata, depending on the file format and conversion type. The SDK’s flexible parameters let you tailor the output to your exact requirements.

Where can I find more detailed examples and documentation?

Visit our GitHub repository for code samples, advanced scenarios, and best practices. The repository is continually updated, ensuring you have the latest guidance for maximizing the SDK’s potential.

Try our C# library for free!