This module extends iText functionality by adding support for WebP image format, enabling seamless integration of WebP images into PDF documents.
- Loads and embeds WebP images into PDF documents
- Works with modern WebP encodings (lossy & lossless)
- Easy integration with existing iText workflows
Add the following dependency to your Maven project:
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>webp-image-support</artifactId>
<version>{itext.core.version}</version>
</dependency>To add WebP image to your document use ImageDataFactory as with any other image type:
// Create a pdf document with WebP image
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(resultFileLocation));
byte[] imageBytes;
try (InputStream fis = FileUtil.getInputStreamForFile(webpFileLocation)) {
imageBytes = StreamUtil.inputStreamToArray(fis);
}
PdfPage page = pdfDocument.addNewPage();
PdfCanvas canvas = new PdfCanvas(page);
ImageData image = ImageDataFactory.create(imageBytes);
canvas.addImageAt(image, 0, 0, false);
canvas.release();
pdfDocument.close();
// Done!Note that the result may have minor differencies across different java versions and operating systems.