### Build and Install OpenPDF Source: https://github.com/librepdf/openpdf/blob/master/CONTRIBUTING.md Clone the repository and run the Maven wrapper to build and install the project. Ensure you have Java installed. ```bash mvnw clean install ``` -------------------------------- ### Build and Install OpenPDF Locally Source: https://github.com/librepdf/openpdf/wiki/Using-a-SNAPSHOT-Version Use this command to compile the project and install the artifact into your local .m2 repository, skipping GPG signing. ```shell mvn clean install -Dgpg.skip ``` -------------------------------- ### Build Project with Maven Source: https://github.com/librepdf/openpdf/blob/master/openpdf-renderer/README.md Compiles and installs the OpenPDF project using Maven. This command cleans previous builds and runs the install lifecycle. ```bash mvn clean install ``` -------------------------------- ### Identify SNAPSHOT Version Source: https://github.com/librepdf/openpdf/wiki/Using-a-SNAPSHOT-Version Example of the Maven output indicating the current project version being built. ```text [INFO] Reactor Summary for OpenPDF - Free and Open PDF 1.3.43-SNAPSHOT: ``` -------------------------------- ### Recommended Usage with OpenPdfCoreRenderer Source: https://github.com/librepdf/openpdf/blob/master/openpdf-renderer/README.md Demonstrates how to use OpenPdfCoreRenderer to render a PDF page to an image. This example utilizes the openpdf-core parser for PDF document handling. ```java import org.openpdf.renderer.core.OpenPdfCoreRenderer; import javax.imageio.ImageIO; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import java.io.File; import java.util.Map; try (OpenPdfCoreRenderer renderer = new OpenPdfCoreRenderer(new File("document.pdf"))) { int pages = renderer.getNumPages(); Rectangle2D size = renderer.getPageSize(1); // 1-based int rotation = renderer.getPageRotation(1); Map metadata = renderer.getMetadata(); String title = renderer.getMetadata("Title"); String pageText = renderer.getTextFromPage(1); // openpdf-core text extraction BufferedImage img = renderer.renderPage(1, 150f); // 150 DPI, ARGB ImageIO.write(img, "png", new File("page1.png")); } ``` -------------------------------- ### HTML Rendering with GlyphLayoutManager Source: https://github.com/librepdf/openpdf/wiki/Accents,-DIN-91379,-non-Latin-scripts Example of setting up and using GlyphLayoutManager for rendering HTML content to PDF. Requires loading fonts and registering the GlyphLayoutManager with ITextRenderer. Ensure all font resources are correctly placed. ```java public void test() throws Exception { var htmlFilename = "GlyphLayoutHtmlExample.html"; var inputStream = this.getClass().getResourceAsStream(htmlFilename); var documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); var document = documentBuilder.parse(inputStream); var glyphLayoutManager = new GlyphLayoutManager(); var fontResolver = new ITextFontResolver(); loadFont(glyphLayoutManager, fontResolver, "Arimo-Regular.ttf", 12.0f, "fonts/arimo/Arimo-Regular.ttf"); loadFont(glyphLayoutManager, fontResolver, "Arimo-Bold.ttf", 12.0f, "fonts/arimo/Arimo-Bold.ttf"); var pdfFilename = "GlyphLayoutHtmlExample.pdf"; try (var outputStream = new FileOutputStream(pdfFilename)) { var renderer = new ITextRenderer(fontResolver); renderer.setDocument(document); renderer.setGlyphLayoutManager(glyphLayoutManager); renderer.layout(); renderer.createPDF(outputStream); } System.out.println("PDF created: " + pdfFilename); } private void loadFont(GlyphLayoutManager glyphLayoutManager, ITextFontResolver fontResolver, String fontName, float fontSize, String fontResourcePath) throws IOException, GlyphLayoutFontManager.FontLoadException { var fontUrl = this.getClass().getResource(fontResourcePath); Objects.requireNonNull(fontUrl, "Font not found: " + fontResourcePath); try (var fontStream = fontUrl.openStream()) { var font = glyphLayoutManager.loadFont(fontName, fontStream, fontSize); fontResolver.addFont(font.getBaseFont(), fontUrl.getFile(), null); } } ``` -------------------------------- ### Java: Specify Kerning and Ligatures Per Font Source: https://github.com/librepdf/openpdf/wiki/Accents,-DIN-91379,-non-Latin-scripts This example demonstrates how to control kerning and ligatures on a per-font basis, offering more granular typographic control. ```java package org.openpdf.examples.glyphlayout; import com.lowagie.text.Document; import com.lowagie.text.Paragraph; import com.lowagie.text.pdf.GlyphLayout; import com.lowagie.text.pdf.PdfWriter; import java.io.FileOutputStream; public class GlyphLayoutKernLigaPerFont { public static void main(String[] args) { try { Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("GlyphLayoutKernLigaPerFont.pdf")); document.open(); GlyphLayout glyphLayout = new GlyphLayout(); // Set kerning and ligatures for a specific font glyphLayout.setKern(true); glyphLayout.setLigature(true); Paragraph paragraph = new Paragraph("This text demonstrates per-font kerning and ligatures.", glyphLayout.getFont()); document.add(paragraph); document.close(); System.out.println("Document created successfully: GlyphLayoutKernLigaPerFont.pdf"); } catch (Exception e) { e.printStackTrace(); } } } ``` -------------------------------- ### Enable GlyphLayoutManager and Add Chunk Source: https://github.com/librepdf/openpdf/wiki/Accents,-DIN-91379,-non-Latin-scripts Demonstrates enabling GlyphLayoutManager and adding a Chunk with special characters to a PDF document. Requires PdfWriter setup. ```java import org.openpdf.text.pdf.Chunk; import org.openpdf.text.pdf.Document; import org.openpdf.text.pdf.GlyphLayoutManager; import org.openpdf.text.pdf.PdfWriter; import java.nio.file.Files; import java.nio.file.Paths; String fileName = "output.pdf"; try (Document document = new Document()) { document.setGlyphLayoutManager(glyphLayoutManager); PdfWriter writer = PdfWriter.getInstance(document, Files.newOutputStream(Paths.get(fileName))); document.open(); document.add(new Chunk("A̋ C̀ C̄ C̆ C̈ C̕ C̣ C̦ C̨̆ D̂ F̀ F̄ G̀ H̄ H̦ H̱ J́ J̌ K̀ K̂ K̄ K̇ K̕ K̛ K̦ K͟H K͟h", serif)); // ... } ``` -------------------------------- ### Generate PDF from HTML String Source: https://github.com/librepdf/openpdf/wiki/Openpdf‐html This example demonstrates how to create a PDF document from an HTML string using ITextRenderer. Ensure the HTML content and CSS are correctly formatted for rendering. ```java import org.openpdf.pdf.ITextRenderer; import java.io.FileOutputStream; public class HelloWorldPdf { public static void main(String[] args) throws Exception { String html = """

Hello, World!

This PDF was generated using openpdf-html.

"""; try (FileOutputStream outputStream = new FileOutputStream("openpdf-html-hello.pdf")) { ITextRenderer renderer = new ITextRenderer(); renderer.setDocumentFromString(html); renderer.layout(); renderer.createPDF(outputStream); } System.out.println("PDF created: openpdf-html-hello.pdf"); } } ``` -------------------------------- ### Java: Use GlyphLayoutManager for Unicode Supplementary Multilingual Plane Source: https://github.com/librepdf/openpdf/wiki/Accents,-DIN-91379,-non-Latin-scripts This example shows how to render characters and symbols from the Unicode Supplementary Multilingual Plane (SMP) using GlyphLayoutManager. ```java package org.openpdf.examples.glyphlayout; import com.lowagie.text.Document; import com.lowagie.text.Paragraph; import com.lowagie.text.pdf.GlyphLayout; import com.lowagie.text.pdf.PdfWriter; import java.io.FileOutputStream; public class GlyphLayoutSMP { public static void main(String[] args) { try { Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("GlyphLayoutSMP.pdf")); document.open(); GlyphLayout glyphLayout = new GlyphLayout(); // Example character from Supplementary Multilingual Plane (e.g., musical symbol G clef) String smpChar = "\uD834\uDD1E"; Paragraph paragraph = new Paragraph("Character from SMP: " + smpChar, glyphLayout.getFont()); document.add(paragraph); document.close(); System.out.println("Document created successfully: GlyphLayoutSMP.pdf"); } catch (Exception e) { e.printStackTrace(); } } } ``` -------------------------------- ### Checkstyle Compliance Source: https://github.com/librepdf/openpdf/blob/master/CONTRIBUTING.md Run the Maven checkstyle plugin to identify and fix any style issues before submitting code. This ensures adherence to the Google Java Style Guide with specified exceptions. ```bash mvnw checkstyle:check ``` -------------------------------- ### Troubleshooting Out of Memory Errors Source: https://github.com/librepdf/openpdf/blob/master/openpdf-renderer/README.md Increase the JVM heap size using the -Xmx flag, for example, -Xmx2g, to mitigate out-of-memory errors when processing large PDFs. ```text Solution: Increase JVM heap size with -Xmx flag (e.g., -Xmx2g) ``` -------------------------------- ### Generate PDF with PdfBuilder in Kotlin Source: https://github.com/librepdf/openpdf/wiki/Kotlin Utilize the PdfBuilder for creating PDF files with Kotlin DSL syntax. This example demonstrates adding a title, subtitle, paragraph, and image to the document. The `use` function ensures the output stream is closed. ```kotlin import com.github.librepdf.kotlin.PdfBuilder import java.io.FileOutputStream fun main() { FileOutputStream("example.pdf").use { output -> PdfBuilder(output).build { title("Hello from Kotlin") subtitle("Using OpenPDF Kotlin") paragraph("This is a paragraph in a PDF file.") image("logo.png", scalePercent = 50f) } } } ``` -------------------------------- ### Java Example: Writing Hindi Text with TrueTypeFont Source: https://github.com/librepdf/openpdf/wiki/Multi-byte-character-language-support-with-TTF-fonts This Java code demonstrates how to register a TrueTypeFont supporting Hindi characters and write text using it in a PDF. Ensure the specified font file path is correct for your system. ```java import com.lowagie.text.*; import com.lowagie.text.pdf.PdfWriter; import java.io.FileOutputStream; import java.io.IOException; public class HelloWorld { public static void main(String[] args) { // Register TrueTypeFont which supports Hindi FontFactory.register("C:\\Windows\\Fonts\\NIRMALA.TTF"); Document document = new Document(); try { PdfWriter.getInstance(document, new FileOutputStream("D:\\workspace\\TMP\\out\\HelloWorld.pdf")); document.open(); document.add(new Chunk( "नमस्ते", FontFactory.getFont("nirmala ui", "Identity-H",false,10,0,null))); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } document.close(); } } ``` -------------------------------- ### Enable GlyphLayoutManager with Document Source: https://github.com/librepdf/openpdf/wiki/Accents,-DIN-91379,-non-Latin-scripts Registers the GlyphLayoutManager with the Document to enable advanced glyph layout features. This setup is thread-safe. ```java import org.openpdf.text.pdf.Document; import org.openpdf.text.pdf.GlyphLayoutManager; try (Document document = new Document().setGlyphLayoutManager(glyphLayoutManager)) { // proceed as usual } ``` -------------------------------- ### Manipulate metadata with iText 2 Source: https://github.com/librepdf/openpdf/wiki/Migrating-from-iText-2-and-4 Example of how to manipulate PDF metadata using iText 2's PdfReader and PdfStamper classes. ```java PdfReader reader = new PdfReader(origin); PdfStamper stamper = new PdfStamper(reader, out); reader.getCatalog().remove(PdfName.METADATA); HashMap info = reader.getInfo(); info.put("Title", "new title"); // .... stamper.setMoreInfo(info); ``` -------------------------------- ### Configure Maven Repositories Source: https://github.com/librepdf/openpdf/wiki/Android-support Add the JitPack repository to your Maven configuration. ```xml jitpack.io https://jitpack.io ``` -------------------------------- ### Load Fonts with Specific Options Source: https://github.com/librepdf/openpdf/wiki/Accents,-DIN-91379,-non-Latin-scripts Demonstrates loading the same font file with different option combinations (kerning, ligatures) using GlyphLayoutManager. Ensure the font file exists at the specified path. ```java Font serifKerning = glyphLayoutManager.loadFont(fontDir + "noto/NotoSerif-Regular.ttf", fontSize, new FontOptions().setKerningOn()); Font serifLigatures = glyphLayoutManager.loadFont(fontDir + "noto/NotoSerif-Regular.ttf", fontSize, new FontOptions().setLigaturesOn()); Font serifKerningLigatures = glyphLayoutManager.loadFont(fontDir + "noto/NotoSerif-Regular.ttf", fontSize, new FontOptions().setKerningOn().setLigaturesOn()); ``` -------------------------------- ### Deploy Release to Maven Central Source: https://github.com/librepdf/openpdf/wiki/Release-Process This command performs a clean build and deploys the release artifacts to the staging repository. Ensure you have the `-Prelease` profile configured. ```sh mvn clean deploy -Prelease ``` -------------------------------- ### Java: Load Font from Input Stream Source: https://github.com/librepdf/openpdf/wiki/Accents,-DIN-91379,-non-Latin-scripts Demonstrates how to load a font into the PDF document directly from an input stream, providing flexibility in font management. ```java package org.openpdf.examples.glyphlayout; import com.lowagie.text.Document; import com.lowagie.text.Font; import com.lowagie.text.Paragraph; import com.lowagie.text.pdf.BaseFont; import com.lowagie.text.pdf.PdfWriter; import java.io.FileInputStream; import java.io.FileOutputStream; public class GlyphLayoutInputStream { public static void main(String[] args) { try { Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("GlyphLayoutInputStream.pdf")); document.open(); // Load font from an input stream BaseFont bf = BaseFont.createFont("font.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, true, null, null); Font font = new Font(bf, 12); Paragraph paragraph = new Paragraph("This text uses a font loaded from an input stream.", font); document.add(paragraph); document.close(); System.out.println("Document created successfully: GlyphLayoutInputStream.pdf"); } catch (Exception e) { e.printStackTrace(); } } } ``` -------------------------------- ### Java: Specify Kerning and Ligatures Per Document Source: https://github.com/librepdf/openpdf/wiki/Accents,-DIN-91379,-non-Latin-scripts This example shows how to enable or disable kerning and ligatures for the entire document. These typographic features can affect text appearance. ```java package org.openpdf.examples.glyphlayout; import com.lowagie.text.Document; import com.lowagie.text.Paragraph; import com.lowagie.text.pdf.GlyphLayout; import com.lowagie.text.pdf.PdfWriter; import java.io.FileOutputStream; public class GlyphLayoutKernLiga { public static void main(String[] args) { try { Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("GlyphLayoutKernLiga.pdf")); document.open(); GlyphLayout glyphLayout = new GlyphLayout(); // Enable kerning and ligatures for the document glyphLayout.setKern(true); glyphLayout.setLigature(true); Paragraph paragraph = new Paragraph("This text demonstrates kerning and ligatures.", glyphLayout.getFont()); document.add(paragraph); document.close(); System.out.println("Document created successfully: GlyphLayoutKernLiga.pdf"); } catch (Exception e) { e.printStackTrace(); } } } ``` -------------------------------- ### Configure Gradle Repositories Source: https://github.com/librepdf/openpdf/wiki/Android-support Add the JitPack repository to your Gradle build file to resolve dependencies. ```gradle repositories { maven { url "https://jitpack.io" } } ``` -------------------------------- ### Configure Maven Central credentials Source: https://github.com/librepdf/openpdf/wiki/Pre‐requisites-for-publishing-releases Add your Central Portal access token credentials to the ~/.m2/settings.xml file. ```xml central My-Token-Username My-Token-Password ``` -------------------------------- ### Upload GPG public key Source: https://github.com/librepdf/openpdf/wiki/Pre‐requisites-for-publishing-releases Publish your public key to a keyserver using your key ID. ```sh gpg2 --keyserver hkp://pool.sks-keyservers.net --send-keys 3806A4CD ``` -------------------------------- ### Java: Specify Text Direction Per Font Source: https://github.com/librepdf/openpdf/wiki/Accents,-DIN-91379,-non-Latin-scripts This example shows how to explicitly set the text direction for each font used in the document, although this is generally not necessary when using the Bidi class. ```java package org.openpdf.examples.glyphlayout; import com.lowagie.text.Document; import com.lowagie.text.Paragraph; import com.lowagie.text.pdf.BidiOrder; import com.lowagie.text.pdf.GlyphLayout; import com.lowagie.text.pdf.PdfWriter; import java.io.FileOutputStream; import java.util.ArrayList; import java.util.List; public class GlyphLayoutBidiPerFont { public static void main(String[] args) { try { Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("GlyphLayoutBidiPerFont.pdf")); document.open(); GlyphLayout glyphLayout = new GlyphLayout(); List textSegments = new ArrayList<>(); textSegments.add("Hello World"); textSegments.add("שלום עולם"); // Hebrew textSegments.add("你好世界"); // Chinese textSegments.add("नमस्ते दुनिया"); // Hindi for (String segment : textSegments) { // Explicitly setting direction per font (generally not needed) byte direction = BidiOrder.getParagraphDirection(segment); Paragraph paragraph = new Paragraph(segment, glyphLayout.getFont(direction)); document.add(paragraph); } document.close(); System.out.println("Document created successfully: GlyphLayoutBidiPerFont.pdf"); } catch (Exception e) { e.printStackTrace(); } } } ``` -------------------------------- ### List GPG keys Source: https://github.com/librepdf/openpdf/wiki/Pre‐requisites-for-publishing-releases Display existing GPG keys to retrieve the key ID. ```sh gpg2 --list-keys ``` -------------------------------- ### Java: Use GlyphLayoutManager with HTML Content (OpenPDF 3.05+) Source: https://github.com/librepdf/openpdf/wiki/Accents,-DIN-91379,-non-Latin-scripts This example shows how to render HTML content into a PDF using GlyphLayoutManager, available from OpenPDF version 3.05 onwards. It requires the openpdf-html module. ```java package org.openpdf.pdf; import com.lowagie.text.Document; import com.lowagie.text.html.simpleparser.HTMLWorker; import com.lowagie.text.pdf.PdfWriter; import java.io.FileOutputStream; import java.io.StringReader; public class GlyphLayoutHtmlExample { public static void main(String[] args) { try { Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("GlyphLayoutHtmlExample.pdf")); document.open(); String htmlContent = "

Hello from HTML

This is a paragraph with bold text.

"; HTMLWorker worker = new HTMLWorker(document); worker.parse(new StringReader(htmlContent)); document.close(); System.out.println("Document created successfully: GlyphLayoutHtmlExample.pdf"); } catch (Exception e) { e.printStackTrace(); } } } ``` -------------------------------- ### Java: Use GlyphLayoutManager with an Image Source: https://github.com/librepdf/openpdf/wiki/Accents,-DIN-91379,-non-Latin-scripts Demonstrates integrating an image within the text flow using GlyphLayoutManager, allowing for mixed text and image content in PDFs. ```java package org.openpdf.examples.glyphlayout; import com.lowagie.text.Document; import com.lowagie.text.Image; import com.lowagie.text.Paragraph; import com.lowagie.text.pdf.GlyphLayout; import com.lowagie.text.pdf.PdfWriter; import java.io.FileOutputStream; public class GlyphLayoutWithImage { public static void main(String[] args) { try { Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("GlyphLayoutWithImage.pdf")); document.open(); GlyphLayout glyphLayout = new GlyphLayout(); Paragraph paragraph = new Paragraph("Text before image.", glyphLayout.getFont()); document.add(paragraph); // Add an image Image img = Image.getInstance("image.png"); // Replace with your image path img.scalePercent(10); document.add(img); Paragraph paragraph2 = new Paragraph("Text after image.", glyphLayout.getFont()); document.add(paragraph2); document.close(); System.out.println("Document created successfully: GlyphLayoutWithImage.pdf"); } catch (Exception e) { e.printStackTrace(); } } } ``` -------------------------------- ### Troubleshooting Font Rendering Issues Source: https://github.com/librepdf/openpdf/blob/master/openpdf-renderer/README.md Verify that necessary font files are accessible and correctly formatted to address font rendering problems. ```text Solution: Check that required font files are accessible and properly formatted ``` -------------------------------- ### Generate Javadoc with Maven Source: https://github.com/librepdf/openpdf/blob/master/openpdf-renderer/README.md Generates Javadoc documentation for the project using Maven. This command creates API documentation in HTML format. ```bash mvn javadoc:javadoc ``` -------------------------------- ### Generate PDF from HTML Source: https://github.com/librepdf/openpdf/blob/master/openpdf-kotlin/README.md Uses HtmlPdfBuilder to convert HTML strings into PDF documents with scaling and version configuration. ```kotlin import java.io.FileOutputStream import com.github.librepdf.html.HtmlPdfBuilder import org.openpdf.text.pdf.PdfWriter val outputStream = FileOutputStream("output.pdf") HtmlPdfBuilder(outputStream).apply { html( """ Example

Hello from HTML

This PDF was generated using openpdf-html and Kotlin.

""".trimIndent() ) scaleToFit(true) pdfVersion(org.openpdf.text.pdf.PdfWriter.VERSION_1_7) build() } ``` -------------------------------- ### Render PDF Page to Image in Java Source: https://github.com/librepdf/openpdf/wiki/Openpdf‐renderer This snippet demonstrates how to load a PDF file, extract a specific page, and render it as an image. Ensure the PDF file is in the classpath and the output directory exists. ```java package openpdf.renderer; import org.openpdf.renderer.PDFFile; import org.openpdf.renderer.PDFPage; import org.junit.jupiter.api.Test; import javax.imageio.ImageIO; import java.awt.*; import java.awt.image.BufferedImage; import java.io.File; import java.io.FileInputStream; import java.net.URL; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; public class ImageRendererTest { @Test public void testRenderPdfPageToImage() throws Exception { int pageIndex = 1; // 1-based index // Load PDF file from test resources URL resourceUrl = getClass().getClassLoader().getResource("HelloWorldMeta.pdf"); assertNotNull(resourceUrl, "PDF resource not found in classpath"); File file = new File(resourceUrl.getFile()); assertTrue(file.exists(), "PDF file does not exist"); try (FileInputStream fis = new FileInputStream(file); FileChannel fc = fis.getChannel()) { ByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size()); PDFFile pdfFile = new PDFFile(bb); PDFPage page = pdfFile.getPage(pageIndex); Rectangle rect = new Rectangle(0, 0, (int) page.getBBox().getWidth(), (int) page.getBBox().getHeight()); Image img = page.getImage(rect.width, rect.height, rect, null, true, true); // Convert to BufferedImage BufferedImage bufferedImage = new BufferedImage(rect.width, rect.height, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = bufferedImage.createGraphics(); g2.drawImage(img, 0, 0, null); g2.dispose(); // Save output image to target/test-output File outputDir = new File("target/test-output"); outputDir.mkdirs(); File outputImageFile = new File(outputDir, "page_" + pageIndex + ".png"); ImageIO.write(bufferedImage, "png", outputImageFile); System.out.println("PDF page rendered and saved to: " + outputImageFile.getAbsolutePath()); } } } ``` -------------------------------- ### Basic PDF to Image Conversion Source: https://github.com/librepdf/openpdf/blob/master/openpdf-renderer/README.md Renders the first page of a PDF document to a BufferedImage and saves it as a PNG file. Uses OpenPdfCoreRenderer for parsing and Java2D for rasterization. ```java import org.openpdf.renderer.core.OpenPdfCoreRenderer; import javax.imageio.ImageIO; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; public class PdfToImageExample { public static void main(String[] args) throws IOException { try (OpenPdfCoreRenderer renderer = new OpenPdfCoreRenderer(new File("document.pdf"))) { // Render the first page (1-based) at 150 DPI as TYPE_INT_ARGB. BufferedImage page = renderer.renderPage(1, 150f); ImageIO.write(page, "png", new File("output.png")); System.out.println("PDF page rendered successfully!"); } } } ``` -------------------------------- ### Generate GPG key Source: https://github.com/librepdf/openpdf/wiki/Pre‐requisites-for-publishing-releases Create a new GPG key pair for signing artifacts. ```sh gpg2 --gen-key ```