You can read all the details at: Convert PUB to PNG using C#
Last active
November 8, 2023 13:56
C# Convert PUB to PNG Programmatically in .NET
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This code example demonstrates how to convert Publisher PUB file to PNG image format. | |
// Load PUB file and create PUB Parser | |
var parser = PubFactory.CreateParser("C:\\Files\\sample.pub"); | |
// Parse the PUB file | |
var doc = parser.Parse(); | |
// Initialize memory stream | |
MemoryStream stream = new MemoryStream(); | |
// Convert PUB to PDF file | |
PubFactory.CreatePdfConverter().ConvertToPdf(doc, stream); | |
// Load PDF document stream | |
Aspose.Pdf.Document document = new Aspose.Pdf.Document(stream); | |
// Loop through all the pages of PDF | |
foreach (Page page in document.Pages) | |
{ | |
// Get PDF file info | |
PdfFileInfo info = new PdfFileInfo(document); | |
// Get Page width and height | |
int width = Convert.ToInt32(info.GetPageWidth(page.Number)); | |
int height = Convert.ToInt32(info.GetPageHeight(page.Number)); | |
// Create Resolution object | |
Resolution resolution = new Resolution(300); | |
// Create Jpeg device with specified Width, Height, and Resolution | |
PngDevice PngDevice = new PngDevice(width, height, resolution); | |
// Process the Page file and save output JPEG image | |
PngDevice.Process(page, "C:\\Files\\Page" + page.Number + ".png"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment