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#
- Install Aspose.PUB for .NET and Aspose.PDF for .NET packages from NuGet.org
- Reference four required namespaces to make the code work
- Set license for both APIs separately by using SetLicense method
- Create a parser for PUB file using PubFactory class
- Load parsed PUB file into a Document object
- Save intermediate PDF file using IPdfConverter interface
- Create a new PDF Document object
- Loop through all pages of the PDF file
- 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.