Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active November 8, 2023 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/8e6da8edec616d56815994bc277f389e to your computer and use it in GitHub Desktop.
Save aspose-com-gists/8e6da8edec616d56815994bc277f389e to your computer and use it in GitHub Desktop.
C# Convert PUB to PNG Programmatically in .NET
// 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