Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active May 31, 2021 20:53
Show Gist options
  • Save aspose-com-gists/c4c0ea9a3cf5466d2982fc037cabe802 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/c4c0ea9a3cf5466d2982fc037cabe802 to your computer and use it in GitHub Desktop.
Convert PUB to Image Programmatically in Java | PUB to JPG | PUB to PNG | PUB to TIFF
// Load input PUB file
IPubParser parser = PubFactory.createParser("Test.pub");
Document doc = parser.parse();
// Convert PUB to PDF file
PubFactory.createPdfConverter().convertToPdf(doc, "Test.pdf");
// Load the PDF file
Document document = new Document("Test.pdf");
facades.PdfFileInfo info = new facades.PdfFileInfo(document);
for (Page page : document.getPages())
{
// Get page dimensions from the PDF document
int width = (int) info.getPageWidth(page.getNumber());
int height = (int) (info.getPageHeight(page.getNumber()));
// Set resolution for the output image
devices.Resolution resolution = new devices.Resolution(300);
// Create JPEG device with specified Width and Height
devices.JpegDevice jpegDevice = new devices.JpegDevice(width, height , resolution);
// Convert PUB to JPG image
jpegDevice.process(page, "Page" + page.getNumber() + ".jpg");
}
// Load input PUB file
IPubParser parser = PubFactory.createParser("Test.pub");
Document doc = parser.parse();
// Convert PUB to PDF file
PubFactory.createPdfConverter().convertToPdf(doc, "Test.pdf");
Document document = new Document("Test.pdf");
facades.PdfFileInfo info = new facades.PdfFileInfo(document);
for (Page page : document.getPages())
{
// Get page dimensions from the PDF document
int width = (int) info.getPageWidth(page.getNumber());
int height = (int) (info.getPageHeight(page.getNumber()));
// Create PNG device with specified Width and Height
devices.PngDevice pngDevice = new devices.PngDevice(width, height);
// Convert PUB to PNG image
pngDevice.process(page, "Page" + page.getNumber() + ".png");
}
// Load input PUB file
IPubParser parser = PubFactory.createParser("Test.pub");
Document doc = parser.parse();
// Convert PUB to PDF file
PubFactory.createPdfConverter().convertToPdf(doc, "Test.pdf");
Document document = new Document("Test.pdf");
facades.PdfFileInfo info = new facades.PdfFileInfo(document);
// Get page dimensions from the PDF document
int width = (int) info.getPageWidth((int)(1));
int height = (int) info.getPageHeight((int)(1));
devices.Resolution resolution = new devices.Resolution(300);
devices.TiffSettings settings = new devices.TiffSettings();
settings.setCompression(devices.CompressionType.None);
settings.setDepth(devices.ColorDepth.Default);
// Create TIFF device with specified Width and Height
devices.TiffDevice tiffDevice = new devices.TiffDevice(width, height , resolution, settings);
// Convert PUB to TIFF image
tiffDevice.process(document, "Output.tiff");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment