Compress PDF C#

Reduce PDF file size up to 90% by optimizing images, fonts, and removing unused objects while preserving visual quality.

Optimize Tools

Compress PDF C# Overview

The Compress PDF C# library by ConvertAPI is a tool that allows for the compression and reduction of PDF file sizes by up to 90%. This C# library optimizes PDF quality by compressing text, graphics, images, subsetting fonts, and optimizing document structure. It offers various parameters for customization, including compression presets, color and grayscale image compression, and options to remove elements like bookmarks, annotations, forms, and embedded files from the PDF. The C# library also provides options for optimizing the PDF for web viewing and preserving the PDF/A standard.

Lightning-Fast Compression

Shrink your PDFs in just a few seconds without compromising quality.

Advanced Image Recompression

Force image recompression to ensure even pre‑compressed images get smaller.

Compression without losing quality

Maintain visual quality of the original file while dramatically reducing file size.

Preserve Fonts & Vectors

Compression keeps text, fonts, and vector graphics sharp.

Multiple Compression Levels

Choose from predefined compression presets or set up your own settings.

Secure by Design

File compression is encrypted and compliant with ISO, GDPR, and HIPAA.

Customizable Parameters

Fine-tune your automation with these powerful conversion options

File

File Supported formats: .pdf

File to be converted. Value can be URL or file content.

Password

String

Sets the password to open protected PDF.

Preset

Collection Default: none

Choose a compression level from the available presets. If a preset is selected, all other compression options will be ignored. These presets are optimized for various use cases, such as balancing file size and quality.

Values:   none lossless text archive web ebook printer

ImageResolution

Integer Default: 150

Set the maximum image resolution in DPI.

Range:   10 .. 800

ImageQuality

Integer Default: 80

Set image quality in percentage.

Range:   10 .. 100

UnembedBaseFonts

Bool Default: False

Specifies whether to remove the base fonts from the PDF file.

SubsetEmbeddedFonts

Bool Default: False

Output PDF should only contain font characters utilized in the original document, and any unused glyphs from all fonts in the document should be removed.

Optimize

Bool Default: True

Optimize page content streams in the PDF file.

Linearize

Bool Default: False

Linearize PDF file and optimize for fast Web View.

PreservePdfa

Bool Default: False

Preserve the PDF/A standard in the PDF file.

RemoveForms

Bool Default: False

Remove PDF forms from the PDF file.

RemoveDuplicates

Bool Default: True

Remove duplicate fonts and color profiles from the PDF file.

RemovePieceInformation

Bool Default: True

Remove piece information dictionaries like Adobe Illustrator or Photoshop private data.

RemoveEmbeddedFiles

Bool Default: True

Remove embedded/attachments files from the PDF file.

RemoveStructureInformation

Bool Default: True

Remove all structure information from the PDF document.

RemoveMetadata

Bool Default: True

Detach the XMP metadata embedded in the document from its catalog, clear all properties in all schemas, and remove metadata from marked content.

RemoveUnusedResources

Bool Default: True

Remove references to resources such as fonts, images, patterns.

StoreFile

Bool Default: False

When the StoreFile parameter is set to True, your converted file is written to ConvertAPI’s encrypted, temporary storage and made available via a time-limited secure download URL, valid for up to 3 hours. After this period, the file is permanently deleted.

When StoreFile is set to False, conversion happens entirely in-memory. The raw file bytes are streamed back in the API response without touching disk or external storage, ensuring maximum security and zero persistence so that only you can access the content.

Integrate using C#

Ready-to-run code samples for quick conversion and automation.

A detailed guide to PDF compression using C#

ConvertAPI provides a GDPR-compliant and ISO/IEC 27001-certified document processing and conversion REST API service. One of our popular conversions is Compress PDF API. It is incredibly efficient - it can reduce the PDF size up to 99% of the original size. The compressed PDF document will be ready to download in a blink of an eye.

PDF compression allows you to optimize PDF documents and reduce their size as much as possible without losing the quality. Compressing PDF files is extremely important for file sharing and long-term storage online, as it can help you save space and bandwidth. It works by re-encoding fonts, images and removing repetitive patterns without compromising the overall PDF quality.

You can test our PDF compressor online for free. Sign up for a free account and use our interactive demo tool to try the conversion using your own documents. Whether you want to share your documents via email or keep them for long-term storage, PDF Compression increases performance significantly!

ConvertAPI PDF compressor

This tutorial will go through the C# PDF compression implementation, all from the file upload to the compressed document result download. Even though ConvertAPI is a REST API service, we created a ConvertAPI DotNet wrapper library for your convenience, so you don't need to make any HTTP calls explicitly. Simply install the ConvertApi package from NuGet into your ASP.NET C# project and you are good to go.

To gain complete control over the compression, you can set up a custom compression level with a bunch of useful parameters. These parameters include image compression and resampling, an option to keep or remove multiple document assets like fonts, bookmarks, annotations, embedded files, etc. In addition, it allows you to optimize page content streams in the PDF file, linearize compressed documents and optimize for fast Web View. You can also compress password-protected files and preserve the PDF/A file format while performing the compression.

How to Compress a PDF using C# and .NET?

  1. Install the ConvertApi NuGet package
  2. Sign up for free and get your API Token
  3. Set up conversion parameters using our interactive demo tool
  4. Copy-paste the auto-generated code snippet into your project

1. ConvertAPI NuGet package installation

Our ConvertAPI C# library works with both .NET Standard and .NET Core. You can install the ConvertApi NuGet package by searching for ConvertApi in the NuGet package manager or by running this command:

PM> Install-Package ConvertApi

2. Get your API Token

Get your API Token and start using our service for free. Simply sign up for a free account and find your API Token in your account dashboard. You can read more about different authentication methods in our docs.

API Token

3. Set the compression parameters

Once you have our library installed into the ASP.NET project and got your ConvertAPI API Token, you can set up the conversion parameters using our interactive demo tool. These parameters include image compression, image resampling, and the ability to remove particular PDF objects like bookmarks, annotations, embedded files, etc. You will find an auto-generated code snippet at the bottom of the page.

4. Compress the PDF files using C# programming language

As soon as you are happy with the conversion result on our website, copy-paste the code snippet into your project. Here is an example code snippet using some custom compression parameters:

var convertApi = new ConvertApi("api_token");
var convert = await convertApi.ConvertAsync("pdf", "compress",
    new ConvertApiFileParam("File", @"C:\path\to\my_file.pdf"),
    new ConvertApiParam("ColorImageCompression", "zip"),
    new ConvertApiParam("ColorImageQuality", "70"),
    new ConvertApiParam("ColorImageDownsample", "true"),
    new ConvertApiParam("ColorImageThresholdDpi", "150"),
    new ConvertApiParam("ColorImageResampleDpi", "100"),
    new ConvertApiParam("RemoveBookmarks", "true"),
    new ConvertApiParam("RemoveAnnotations", "true"),
    new ConvertApiParam("RemoveEmbeddedFiles", "false"),
    new ConvertApiParam("UnembedBaseFonts", "true"),
    new ConvertApiParam("SubsetEmbeddedFonts", "true")
);
await convert.SaveFilesAsync(@"C:\converted-files\");

That's all it takes to implement PDF compression into the ASP.NET project. You can find a complete list of parameters on our interactive demo tool page.

Advanced techniques

Using our library, you can compress either a local file or a remote file accessible by a public URL. You can even compress your PDF using the file stream. Let's see some examples below.

Convert a local file

Converting a local file is the most straightforward and reliable approach. Set the source file path and the destination folder, and you will have your document converted in seconds!

var convertApi = new ConvertApi("api_token");
var convert = await convertApi.ConvertAsync("pdf", "compress",
    new ConvertApiFileParam("File", @"C:\path\to\my_file.pdf"),
);
await convert.SaveFilesAsync(@"C:\converted-files\");

Convert a remote file

Compressing a remote is relatively simple too. Just make sure that the file is publicly accessible by a URL and that it has the application/pdf content type set.

var convertApi = new ConvertApi("api_token");
var sourceFile = new Uri("https://cdn.convertapi.com/cara/testfiles/document-large.pdf");
var compressionResult = await convertApi.ConvertAsync("pdf", "compress", new ConvertApiFileParam(sourceFile));
var outputFileName = compressionResult.Files[0];
var fileInfo = await outputFileName.SaveFileAsync(Path.Combine(Path.GetTempPath(), outputFileName.FileName));

Convert file stream

You can also compress the PDF file stream. In this example, we will compress the file stream and receive the compressed document's file stream for further processing. Please note that you have to provide a file name explicitly in the new ConvertApiFileParam(stream, "sample.pdf") parameter:

var convertApi = new ConvertApi("api_token");
using (FileStream stream = File.Open(@"c:\sample.pdf", FileMode.Open))
{
    var convertToPdf = await convertApi.ConvertAsync("pdf", "compress",
        new ConvertApiFileParam(stream, "sample.pdf")
    );
    var outputStream = await convertToPdf.Files.First().FileStreamAsync();
    Console.Write(new StreamReader(outputStream).ReadToEnd());
}

For more advanced techniques, please find our useful code examples on convertapi-dotnet GitHub repository.

Conclusion

Nowadays most of the documents are digitally shared and stored online, which makes it all about performance. By using our service, you can increase the effectiveness significantly. Our PDF compression tool is super simple to integrate into your project. It is fast, reliable, and secure. We provide 99.99% uptime so that you can compress your documents anytime, anywhere. You can find all compression parameters as well as the auto-generated code snippet on our PDF Compress API page. For more advanced techniques, please look at our code examples on GitHub.

Integrate within minutes

Easy Compress PDF automation using our simple C# SDK

Try the Compress PDF conversion online

Try it Free

Compatible With All .NET Frameworks & Tools

Compatible with Microsoft Azure Compatible with .NET Core Available on NuGet C# SDK Available Compatible with VS Code Compatible with JetBrains Rider Compatible with Visual Studio

Frequently Asked Questions

What is ConvertAPI C# SDK?

The ConvertAPI C# SDK is a lightweight, easy-to-use library for .NET developers to integrate document and file conversions into their applications with minimal code. It connects directly to the ConvertAPI REST service, allowing you to automate file conversions, merging, splitting, and more.

What types of conversions are supported?

ConvertAPI offers 300+ converters and tools, including DOCX to PDF, XLSX to PDF, PDF to JPG, HTML to PDF, image processing, metadata extraction, compression, and advanced document workflows. You can automate complex document processing scenarios within your .NET applications using the SDK.

Can I build complex conversion workflows using the SDK?

Yes, the ConvertAPI .NET C# SDK allows you to chain conversions, merge documents, extract pages, and apply advanced parameters to automate end-to-end document workflows within your applications.

Is there a file size limit when using ConvertAPI?

The maximum file size you can convert depends on your ConvertAPI plan type. Higher-tier plans allow larger files and increased concurrency for high-volume document processing needs.

Can I convert files entirely in memory without storing them on your servers?

Yes, ConvertAPI supports in-memory conversions, allowing you to send and receive files as streams without saving them to disk on ConvertAPI servers. This enables secure, diskless workflows for sensitive or temporary files.

Which .NET versions does the ConvertAPI SDK support?

The SDK supports .NET Framework 4.5+, .NET Core, .NET 5, 6, 7, and 8, ensuring compatibility across your existing and new projects.

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!"

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

Ready to Streamline Your File Conversions?