Scanning services, records departments, and fax gateways usually work with TIFF format. The format supports lossless compression, multiple pages in one file, and black-and-white encodings designed for documents. That makes it a frequent requirement when Publisher flyers, forms, and newsletters move into an archive or a document management system.
In this article, you’ll learn how to convert PUB to TIFF in Java. Besides a basic conversion, you’ll see how to pick the resolution, compression, and color depth, create small black-and-white TIFF files, convert only certain pages, and write the image to a stream. The code runs on any operating system with Java and doesn’t need Microsoft Publisher.
Java Libraries to Convert PUB to TIFF
Two libraries share the work:
- Aspose.PUB for Java parses the PUB file and renders it as PDF.
- Aspose.PDF for Java renders the PDF pages to TIFF through its TiffDevice class.
The PDF exists only in memory, so the conversion doesn’t leave temporary files behind.
Declare the Aspose repository and both artifacts in pom.xml:
<repositories>
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>https://releases.aspose.com/java/repo/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-pub</artifactId>
<version>22.8</version>
</dependency>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-pdf</artifactId>
<version>26.10</version>
</dependency>
</dependencies>
Without Maven, download the JARs of Aspose.PUB and Aspose.PDF and add them to the classpath.
Convert PUB to TIFF in Java
A color TIFF at print resolution is the most common target. Here’s the process:
- Parse the publication with PubFactory.createParser() and
parse(). - Render it into a
ByteArrayOutputStreamwithconvertToPdf(). - Load those bytes into a
com.aspose.pdf.Document. - Create TiffSettings with LZW compression.
- Create a
TiffDevicewith a 300 DPIResolutionand the settings. - Call
process()to write the TIFF file.
import com.aspose.pdf.devices.CompressionType;
import com.aspose.pdf.devices.Resolution;
import com.aspose.pdf.devices.TiffDevice;
import com.aspose.pdf.devices.TiffSettings;
import com.aspose.pub.Document;
import com.aspose.pub.PubFactory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
public class ConvertPubToTiff {
public static void main(String[] args) {
// Folder with the PUB file and the output
String dataDir = "C:\\Files\\";
// Parse the publication
Document document = PubFactory.createParser(dataDir + "florist-flyer.pub").parse();
// Render the publication to PDF in memory
ByteArrayOutputStream pdfStream = new ByteArrayOutputStream();
PubFactory.createPdfConverter().convertToPdf(document, pdfStream);
com.aspose.pdf.Document pdf = new com.aspose.pdf.Document(
new ByteArrayInputStream(pdfStream.toByteArray()));
// Use lossless LZW compression
TiffSettings settings = new TiffSettings();
settings.setCompression(CompressionType.LZW);
// Render all pages at 300 DPI into one TIFF file
TiffDevice tiffDevice = new TiffDevice(new Resolution(300), settings);
tiffDevice.process(pdf, dataDir + "florist-flyer.tiff");
pdf.close();
}
}
The result is a full-color TIFF at 300 DPI, which is a typical resolution for print and archiving. When a publication has several pages, process() stores all of them in the same file as a multi-page TIFF.
Both libraries contain a class named Document, so the PDF document is referenced by its full name, com.aspose.pdf.Document.
Choose TIFF Compression and Color Depth
TiffSettings controls how the pages are encoded. The two settings that matter most are compression and color depth:
| Setting | Values | When to use |
|---|---|---|
setCompression() | LZW | Lossless compression for color and grayscale pages |
CCITT4, CCITT3 | Black-and-white documents, archives, and fax | |
RLE, None | Legacy systems that can’t read other compressions | |
setDepth() | Format24bpp | Full color |
Format8bpp, Format4bpp | Fewer colors and smaller files | |
Format1bpp | Pure black and white |
The resolution is set separately with new Resolution(dpi). Higher values mean sharper pages and larger files.
Create a Black-and-White TIFF for Archiving
Records systems and fax servers often require 1-bit TIFF images with CCITT Group 4 compression. This combination produces very small files and is a common standard for document archives. To create one, set the color depth to Format1bpp, the compression to CCITT4, and use 200 or 300 DPI:
import com.aspose.pdf.devices.ColorDepth;
import com.aspose.pdf.devices.CompressionType;
import com.aspose.pdf.devices.Resolution;
import com.aspose.pdf.devices.TiffDevice;
import com.aspose.pdf.devices.TiffSettings;
import com.aspose.pub.Document;
import com.aspose.pub.PubFactory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
public class ConvertPubToBlackAndWhiteTiff {
public static void main(String[] args) {
// Folder with the PUB file and the output
String dataDir = "C:\\Files\\";
// Parse the publication and render it to PDF in memory
Document document = PubFactory.createParser(dataDir + "florist-flyer.pub").parse();
ByteArrayOutputStream pdfStream = new ByteArrayOutputStream();
PubFactory.createPdfConverter().convertToPdf(document, pdfStream);
com.aspose.pdf.Document pdf = new com.aspose.pdf.Document(
new ByteArrayInputStream(pdfStream.toByteArray()));
// 1-bit black and white with CCITT Group 4 compression
TiffSettings settings = new TiffSettings();
settings.setDepth(ColorDepth.Format1bpp);
settings.setCompression(CompressionType.CCITT4);
// Save at 200 DPI, a common fax and archive resolution
TiffDevice tiffDevice = new TiffDevice(new Resolution(200), settings);
tiffDevice.process(pdf, dataDir + "florist-flyer-bw.tiff");
pdf.close();
}
}
In our test with a one-page color flyer, the 300 DPI color TIFF was 2.6 MB, while the 200 DPI black-and-white TIFF was only 150 KB. Check that the result is still readable, because photos and light colors lose detail in pure black and white.
Convert Selected Pages of a PUB File to TIFF
You don’t always need every page. For example, a document system might only want the cover of a newsletter as a preview. The process() method has an overload that takes the first and last page numbers. Page numbers start at 1.
The following code renders only the first page at screen resolution:
import com.aspose.pdf.devices.CompressionType;
import com.aspose.pdf.devices.Resolution;
import com.aspose.pdf.devices.TiffDevice;
import com.aspose.pdf.devices.TiffSettings;
import com.aspose.pub.Document;
import com.aspose.pub.PubFactory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
public class ConvertPubPagesToTiff {
public static void main(String[] args) {
// Folder with the PUB file and the output
String dataDir = "C:\\Files\\";
// Parse the publication and render it to PDF in memory
Document document = PubFactory.createParser(dataDir + "florist-flyer.pub").parse();
ByteArrayOutputStream pdfStream = new ByteArrayOutputStream();
PubFactory.createPdfConverter().convertToPdf(document, pdfStream);
com.aspose.pdf.Document pdf = new com.aspose.pdf.Document(
new ByteArrayInputStream(pdfStream.toByteArray()));
// Render page 1 only, at 96 DPI for a preview
TiffDevice tiffDevice = new TiffDevice(new Resolution(96), new TiffSettings(CompressionType.LZW));
tiffDevice.process(pdf, 1, 1, dataDir + "florist-flyer-cover.tiff");
pdf.close();
}
}
To convert pages 2 to 4, pass 2 and 4 instead. Use pdf.getPages().size() to find out how many pages the publication has.
Write the TIFF to a Stream
In a web service or a message queue consumer, the PUB file often arrives as a stream and the TIFF must go back as one. PubFactory.createParser() accepts an InputStream, and TiffDevice.process() can write to any OutputStream:
import com.aspose.pdf.devices.CompressionType;
import com.aspose.pdf.devices.Resolution;
import com.aspose.pdf.devices.TiffDevice;
import com.aspose.pdf.devices.TiffSettings;
import com.aspose.pub.Document;
import com.aspose.pub.PubFactory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class PubToTiffStream {
// Renders a PUB stream as a multi-page TIFF stream
public static void convertPubToTiff(InputStream pubInput, OutputStream tiffOutput, int dpi) {
Document document = PubFactory.createParser(pubInput).parse();
ByteArrayOutputStream pdfStream = new ByteArrayOutputStream();
PubFactory.createPdfConverter().convertToPdf(document, pdfStream);
com.aspose.pdf.Document pdf = new com.aspose.pdf.Document(
new ByteArrayInputStream(pdfStream.toByteArray()));
TiffDevice tiffDevice = new TiffDevice(new Resolution(dpi), new TiffSettings(CompressionType.LZW));
tiffDevice.process(pdf, tiffOutput);
pdf.close();
}
public static void main(String[] args) throws IOException {
// Folder with the PUB file and the output
String dataDir = "C:\\Files\\";
try (InputStream pubInput = new FileInputStream(dataDir + "florist-flyer.pub");
OutputStream tiffOutput = new FileOutputStream(dataDir + "florist-flyer-stream.tiff")) {
convertPubToTiff(pubInput, tiffOutput, 300);
}
}
}
In a servlet or Spring controller, pass the request’s input stream and the response’s output stream to convertPubToTiff(), and set the content type to image/tiff.
Get a Free Temporary License
Both libraries work in evaluation mode without a license and add evaluation notices to the rendered pages. A free temporary license removes this limitation while you test. Apply it for Aspose.PUB and Aspose.PDF before rendering.
Convert PUB to TIFF Online
To convert a few files without code, try the free online PUB to TIFF converter. Upload a Publisher file in the browser and download the TIFF.
Further Reading
Conclusion
Rendering Publisher files as TIFF in Java takes a short pipeline: Aspose.PUB turns the publication into PDF in memory, and the TiffDevice of Aspose.PDF turns that PDF into TIFF. Use LZW for color pages, CCITT4 with 1-bit depth for compact archive images, a page range for previews, and streams for services. If you need help, our free support forum is open to everyone.
Frequently Asked Questions
How do I convert a PUB file to TIFF in Java?
Parse the PUB file with PubFactory.createParser(), convert it to PDF in memory with convertToPdf(), load the PDF into Aspose.PDF for Java, and render it with a TiffDevice.
Which TIFF compression should I use?
Use LZW for color images because it is lossless and widely supported. Use CCITT4 with 1-bit color depth for compact black-and-white archive and fax images.
What resolution should I use for TIFF output?
300 DPI is the usual choice for print and archiving. Use 200 DPI for fax and lower values, such as 96 DPI, for screen previews.
Does a multi-page publication become one TIFF file?
Yes. TiffDevice.process() writes all pages of the document into a single multi-page TIFF file. Pass a page range to convert only some pages.
Can I convert PUB to TIFF without saving files to disk?
Yes. PubFactory.createParser() accepts an InputStream, and TiffDevice.process() can write to an OutputStream.
Do I need Microsoft Publisher installed to convert PUB to TIFF?
No. Aspose.PUB and Aspose.PDF for Java work on their own, on any operating system with Java.
