How to Convert PUB to PNG in C#

In this step by step topic, you’ll learn how to convert PUB to PNG in C#. The need to convert PUB file to PNG format in C# occurs when you need to show the pages of a PUB file as images in your application. The tutorial helps you achieve this with few lines of C# code.

Steps to Convert PUB to PNG in C#

  1. Install Aspose.PUB for .NET and Aspose.PDF for .NET packages from NuGet.org
  2. Reference four required namespaces to make the code work
  3. Set license for both APIs separately by using SetLicense method
  4. Create a parser for PUB file using PubFactory class
  5. Load parsed PUB file into a Document object
  6. Save intermediate PDF file using IPdfConverter interface
  7. Create a new PDF Document object
  8. Loop through all pages of the PDF file
  9. Save each PDF page as PNG image using PngDevice object

In the above steps, we have used Aspose.PUB for .NET, and Aspose.PDF for .NET APIs to first convert a PUB file into an intermediate PDF file format, and then convert that intermediate PDF file to PNG images.

Code to Convert PUB to PNG in C#

The above code helps to convert PUB to PNG in C# code with a few steps. Each individual page of the PDF file is saved as a separate PNG image. Using this code and following the steps, you can create your own PUB to PNG C# converter in your .NET applications including Windows, Web, Desktop, or Services etc. Note that this does not require Microsoft Publisher to be installed on your machine or server.

 English