You can find all relevant details at: Convert PUB to Image Programmatically in Java
Last active
May 31, 2021 20:53
-
-
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
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
// 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"); | |
} |
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
// 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"); | |
} |
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
// 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