Publisher is a desktop publishing software application from Microsoft that is used to create a variety of publications, such as newsletters, brochures, flyers, and more. However, the PUB files are not widely supported, so in certain cases, we may need to convert PUB files to JPG images programmatically. In this blog post, we will show you how to convert Publisher to JPG in C#. We will provide a step-by-step guide and code snippets to help you get started.
This article covers the following topics:
- C# API to Convert Publisher to JPG
- Steps to Convert a Publisher File to JPG
- Convert Publisher to JPG in C#
- Convert PUB to JPG File Online
- Learning Resources
C# API to Convert Publisher to JPG
Publisher to JPG conversion comprises two steps. Firstly, we will use the Aspose.PUB for .NET API to load and render the PUB file into PDF format, and then the pages of the PDF file will be converted into JPG images using the Aspose.PDF for .NET API.
The Aspose.PUB for .NET allows developers to seamlessly work with Microsoft Publisher files (PUB) within their .NET applications. It provides a comprehensive set of features for reading, writing, converting, and manipulating PUB files. Whereas, Aspose.PDF for .NET is a versatile tool that can be used to perform a wide range of tasks related to PDF files.
PM> Install-Package Aspose.PUB PM> Install-Package Aspose.PDF
How to Convert Publisher PUB File to JPG
We can easily convert a PUB file to a JPG image by following the steps below:
- Create a PUB parser and parse the PUB file.
- Convert a PUB to a PDF file stream.
- Loop through all the pages of the PDF document.
- Create a Jpeg device and process pages to save as JPG images.
Now, let’s see how to perform these steps in C# to convert a Publisher PUB file to a JPG.
Convert Publisher to JPG Image in C#
Please follow the steps below to convert the Publisher file to a JPG image programmatically in C#:
- Create a PUB parser using the CreateParser() method of the PubFactory class.
- Parse the loaded Publisher file using the Parse() method.
- Initialize the MemoryStream object to hold the PDF file.
- Convert PUB to PDF using the ConvertToPdf() method.
- Create an instance of the Document class with the PDF stream.
- Get file information using the PdfFileInfo class object.
- Loop through pages of the PDF document and get height, width, and set resolution.
- After that, create an instance of the JpegDevice with height, width, and resolution for the page.
- Finally, call the Process() method to save as JPG. It takes the page and output image file path as arguments.
The following code sample shows how to convert Publisher to JPG in C#.
Get a Free License
You can get a free temporary license to try the libraries without evaluation limitations.
PUB to JPG Converter - Free Online
You can try this free online PUB to JPG Converter app to convert publisher files to JPG images without installing any software or plugin.
Convert PUB to JPG File Online – Learning Resources
Besides converting Publisher PUB files into JPG format, you may also explore various other features of the library using the following resources:
In this blog post, we have shown you how to convert Publisher to JPG in C#. We have provided a step-by-step guide and code snippets to help you get started. Converting Publisher files to JPG is a relatively simple task, and the code snippets provided in this blog post can be used as a starting point for developing your own Publisher to JPG converter application. In case of any ambiguity, please feel free to contact us on our free support forum.