PRODUCT COMPARISONS

IronPDF vs PDFsharp PDF-to-Image Conversion (Code Example)

Published February 19, 2025
Share:

PDFs are a cornerstone of digital communication, widely used for sharing and preserving documents across various industries. However, there are situations where converting PDF files into image formats becomes essential. By transforming PDFs into images, users can integrate document content seamlessly into presentations, websites, or social media platforms, enhancing visibility and accessibility.

Whether it's for creative purposes, improving compatibility, or enabling easier sharing, the ability to convert PDFs into images opens up a world of possibilities. This article explores the importance of PDF-to-image conversion and compares two popular C# libraries—PDFSharp and IronPDF—to help you achieve this efficiently.

PDFsharp

PDFsharp is a popular, open-source PDF library that allows developers to create, modify, and process PDF documents in C#. With its extensive functionality and support for various PDF operations, PDFsharp offers flexibility for developers.

Although PDFsharp is great for generating PDFs and making basic modifications, it lacks native support for advanced tasks such as converting PDFs to images. Developers often rely on extensions or third-party libraries like System.Drawing to handle rendering tasks.

IronPDF

IronPDF vs PDFsharp PDF-to-Image Conversion (Code Example): Figure 1 - image.png

IronPDF opens the door to powerful PDF manipulation and generation capabilities within the .NET ecosystem. As businesses and developers seek efficient solutions to handle PDF-related tasks programmatically, IronPDF emerges as a reliable and feature-rich library. Whether it's converting HTML content to PDF, merging, splitting, or editing existing PDF documents, IronPDF equips C# developers with a robust set of tools to streamline their workflow.

With its easy integration, extensive documentation for users browsing to look through, and support for modern use cases like image extraction, IronPDF simplifies the process of handling PDF tasks programmatically. Below, we will demonstrate how IronPDF can be used to extract images from PDFs effortlessly.

For today's example, we will be converting this PDF to image:

IronPDF vs PDFsharp PDF-to-Image Conversion (Code Example): Figure 2

Install IronPDF NuGet Package

To integrate IronPDF into your project, follow these steps:

  1. Open the NuGet Package Manager in Visual Studio.

    1. Search for IronPDF and install the package.

IronPDF vs PDFsharp PDF-to-Image Conversion (Code Example): Figure 3

  1. Alternatively, use the following command in the Package Manager Console:

    Install-Package IronPdf
    Install-Package IronPdf
  1. Once installed, you can start using IronPDF to handle PDF-to-image conversions.

Install PDFsharp NuGet Package

To use PDFSharp, install it from NuGet as follows:

  1. Open the NuGet Package Manager in Visual Studio.

    1. Search for PDFSharp and install the package.

IronPDF vs PDFsharp PDF-to-Image Conversion (Code Example): Figure 4

  1. Alternatively, run the following command in the Package Manager Console:

    Install-Package PDFsharp
    Install-Package PDFsharp

While PDFsharp does not include native support for rendering PDFs as images, you can extend its capabilities by integrating libraries like System.Drawing.

Convert PDF Documents to Images Using IronPDF

IronPDF makes extracting images from PDFs straightforward. Here's an example demonstrating how to convert a PDF file into images using IronPDF:

using IronPdf;
using System.Drawing;
class Program
{
    static void Main(string[] args)
    {
        ChromePdfRenderer renderer = new ChromePdfRenderer();
        PdfDocument pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf/#readme-body-tab");
        pdf.RasterizeToImageFiles("IronPdfImage.png");
    }
}
using IronPdf;
using System.Drawing;
class Program
{
    static void Main(string[] args)
    {
        ChromePdfRenderer renderer = new ChromePdfRenderer();
        PdfDocument pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf/#readme-body-tab");
        pdf.RasterizeToImageFiles("IronPdfImage.png");
    }
}

IronPDF vs PDFsharp PDF-to-Image Conversion (Code Example): Figure 5

This example demonstrates how easily the IronPDF library to converts a PDF into a series of images. It first creates a ChromePdfRenderer instance, which uses a Chromium-based engine to render the given URL as the PDF we will be using. The RenderUrlAsPdf method is then called to load and convert the specified URL into a PDF document.

Finally, the RasterizeToImageFiles method converts each page of the PDF into image files, saving them as "IronPdfImage.png" files in the current directory. Each image corresponds to a single page of the PDF, making the process simple and efficient.

Convert PDF Files to Images Using PDFsharp

While PDFsharp doesn’t provide built-in methods for converting PDFs to images, you can use the following code example by combining PDFsharp with System.Drawing:

using PdfSharp.Pdf;
using PdfSharp.Pdf.IO;
using System.Drawing;
using System.Drawing.Imaging;
class Program
{
    static void Main(string[] args)
    {
        // Load PDF document
        var document = PdfReader.Open("example.pdf", PdfDocumentOpenMode.Import);
        var page = document.Pages[0];
        // Convert to image (requires additional rendering logic)
        Bitmap bitmap = new Bitmap(800, 1200); // Example dimensions
        using (Graphics graphics = Graphics.FromImage(bitmap))
        {
            int height = bitmap.Height;
            int width = bitmap.Width;
            // Simulate rendering (requires GDI+ or a rendering library)
            graphics.FillRectangle(Brushes.White, 0, 0, width, height);
            graphics.DrawString("Rendering is not native to PDFSharp",
                new Font("Arial", 16), Brushes.Black, new PointF(10, 10));
        }
        // Save as image
        bitmap.Save("output.png", ImageFormat.Png);
    }
}
using PdfSharp.Pdf;
using PdfSharp.Pdf.IO;
using System.Drawing;
using System.Drawing.Imaging;
class Program
{
    static void Main(string[] args)
    {
        // Load PDF document
        var document = PdfReader.Open("example.pdf", PdfDocumentOpenMode.Import);
        var page = document.Pages[0];
        // Convert to image (requires additional rendering logic)
        Bitmap bitmap = new Bitmap(800, 1200); // Example dimensions
        using (Graphics graphics = Graphics.FromImage(bitmap))
        {
            int height = bitmap.Height;
            int width = bitmap.Width;
            // Simulate rendering (requires GDI+ or a rendering library)
            graphics.FillRectangle(Brushes.White, 0, 0, width, height);
            graphics.DrawString("Rendering is not native to PDFSharp",
                new Font("Arial", 16), Brushes.Black, new PointF(10, 10));
        }
        // Save as image
        bitmap.Save("output.png", ImageFormat.Png);
    }
}

Explanation of Key Steps

  1. Load the PDF Document:

    The PdfReader.Open method from PDFsharp is used to load an existing PDF file in import mode, allowing us to read its content.

  2. Simulate Rendering:

    Since PDFsharp does not natively support rendering PDF pages into images, in this example we have used a Graphics object to draw text ("Rendering is not native to PDFSharp") on a blank Bitmap. However, this does not actually render the content of the PDF page.

  3. Save the Image:

    The Bitmap object is saved as a PNG file using ImageFormat.Png.

As you can see, while this has saved the PDF to Image format, it also demonstrates PDFSharp's lack of any real built-in PDF to Image features. In order to convert your PDF documents to image while maintaining the original PDF pages content, you would need to implement external libraries such as PdfiumViewer or GDI+.

IronPDF vs PDFsharp PDF-to-Image Conversion (Code Example): Figure 6

Conclusion

In today's digitized world, the ability to convert PDFs to images offers diverse possibilities for seamless integration of documents into presentations, web pages, or social media platforms, enhancing accessibility and creativity.

PDFSharp provides a powerful, open-source solution for generating and modifying PDFs. However, when it comes to advanced features like rendering PDFs as images, it requires additional libraries or workarounds, which may impact performance and ease of use.

In contrast, IronPDF offers a feature-rich, modern library with built-in support for image extraction, making it a more efficient choice for developers handling PDF-to-image conversions, whether you're a freelance software developer, or a company looking for the next best PDF solution. IronPDF offers flexible licensing options, starting with a free trial with various tiers to suit individual developers and businesses.

When comparing IronPDF vs. PDFsharp for PDF-to-image conversion, IronPDF emerges as the winner with its superior feature set, ease of use, and comprehensive licensing options.

Kannaopat Udonpant

Kannapat Udonpant

Software Engineer

 LinkedIn

Before becoming a Software Engineer, Kannapat completed a Environmental Resources PhD from Hokkaido University in Japan. While pursuing his degree, Kannapat also became a member of the Vehicle Robotics Laboratory, which is part of the Department of Bioproduction Engineering. In 2022, he leveraged his C# skills to join Iron Software's engineering team, where he focuses on IronPDF. Kannapat values his job because he learns directly from the developer who writes most of the code used in IronPDF. In addition to peer learning, Kannapat enjoys the social aspect of working at Iron Software. When he's not writing code or documentation, Kannapat can usually be found gaming on his PS5 or rewatching The Last of Us.
< PREVIOUS
PDFsharp Add Page Numbers to PDF VS IronPDF (Example)
NEXT >
PDFsharp Sign PDF documents Digitally vs IronPDF (Code Example)