Author: tilman
Date: Sun Jul 5 10:03:54 2026
New Revision: 1935907
Log:
PDFBOX-4951: add example + test
Added:
pdfbox/trunk/pdfbox-layout-awt/src/main/java/org/apache/pdfbox/glyphlayout/examples/
pdfbox/trunk/pdfbox-layout-awt/src/main/java/org/apache/pdfbox/glyphlayout/examples/GlyphLayoutHelloWorld.java
(contents, props changed)
pdfbox/trunk/pdfbox-layout-awt/src/test/java/org/apache/pdfbox/glyphlayout/GlyphLayoutHelloWorldTest.java
(contents, props changed)
pdfbox/trunk/pdfbox-layout-awt/src/test/resources/pdf/HelloWorld.pdf
(contents, props changed)
Added:
pdfbox/trunk/pdfbox-layout-awt/src/main/java/org/apache/pdfbox/glyphlayout/examples/GlyphLayoutHelloWorld.java
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++
pdfbox/trunk/pdfbox-layout-awt/src/main/java/org/apache/pdfbox/glyphlayout/examples/GlyphLayoutHelloWorld.java
Sun Jul 5 10:03:54 2026 (r1935907)
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pdfbox.glyphlayout.examples;
+
+import java.awt.FontFormatException;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.pdfbox.glyphlayout.GlyphLayoutFontLoaderAwt;
+import org.apache.pdfbox.glyphlayout.GlyphLayoutProcessorAwt;
+import org.apache.pdfbox.pdmodel.PDDocument;
+import org.apache.pdfbox.pdmodel.PDPage;
+import org.apache.pdfbox.pdmodel.PDPageContentStream;
+import org.apache.pdfbox.pdmodel.font.PDType0Font;
+
+/**
+ * Creates a simple document with a TrueType font using GlyphLayoutProcessorAwt
+ * adapted from org.apache.pdfbox.examples.pdmodel.HelloWorldTTF
+ */
+public class GlyphLayoutHelloWorld
+{
+
+ public static void main(String[] args) throws IOException,
FontFormatException
+ {
+ new GlyphLayoutHelloWorld().test(args);
+ }
+
+ public void test(String[] args) throws IOException, FontFormatException
+ {
+ if (args.length != 3)
+ {
+ System.err.println("Usage: " + this.getClass().getName() + "
<output-file> <Message> <ttf-file>");
+ System.exit(1);
+ }
+
+ String pdfPath = args[0];
+ String message = args[1];
+ String ttfPath = args[2];
+
+ try (PDDocument doc = new PDDocument())
+ {
+ PDPage page = new PDPage();
+ doc.addPage(page);
+
+ GlyphLayoutProcessorAwt glyphLayoutProcessorAwt = new
GlyphLayoutProcessorAwt();
+ PDType0Font font;
+ GlyphLayoutFontLoaderAwt.FontOptions fontOptions = new
GlyphLayoutFontLoaderAwt.FontOptions();
+ // call fontOptions.setKerningOn() for kerning
+ // call fontOptions.setLigaturesOn() for additional ligatures,
e.g. "ffl", "ffi" etc
+ // however mandatory replacements (e.g. in Bengali, Thai, Arabic)
are always active
+ try (InputStream is = new FileInputStream(ttfPath))
+ {
+ font = glyphLayoutProcessorAwt.loadFont(doc, is, fontOptions);
+ }
+
+ try (PDPageContentStream contents = new PDPageContentStream(doc,
page))
+ {
+ contents.setGlyphLayoutProcessor(glyphLayoutProcessorAwt);
+ contents.beginText();
+ contents.setFont(font, 20);
+ contents.newLineAtOffset(100, 700);
+ contents.showText(message);
+ contents.endText();
+ }
+ doc.save(pdfPath);
+ System.out.println(pdfPath + " created!");
+ }
+ }
+}
Added:
pdfbox/trunk/pdfbox-layout-awt/src/test/java/org/apache/pdfbox/glyphlayout/GlyphLayoutHelloWorldTest.java
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++
pdfbox/trunk/pdfbox-layout-awt/src/test/java/org/apache/pdfbox/glyphlayout/GlyphLayoutHelloWorldTest.java
Sun Jul 5 10:03:54 2026 (r1935907)
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pdfbox.glyphlayout;
+
+import java.awt.FontFormatException;
+import java.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
+
+import org.junit.jupiter.api.Test;
+
+import org.apache.pdfbox.glyphlayout.examples.GlyphLayoutHelloWorld;
+
+/**
+ *
+ * @author Tilman Hausherr
+ */
+public class GlyphLayoutHelloWorldTest extends TestBase
+{
+ @Test
+ void testGlyphLayoutHelloWorld() throws IOException, FontFormatException,
URISyntaxException
+ {
+ String outputName = "HelloWorld.pdf";
+ String lohitBengaliPath = "/ttf/Lohit-Bengali.ttf";
+ File file = new
File(GlyphLayoutHelloWorldTest.class.getResource(lohitBengaliPath).toURI());
+ System.out.println(file.getPath());
+ String [] args = new String[]{ "target/" + outputName, "হ্যালো
ওয়ার্ল্ড", file.getPath() };
+ GlyphLayoutHelloWorld.main(args);
+ checkRenderIdent(outputName);
+ }
+}
Added: pdfbox/trunk/pdfbox-layout-awt/src/test/resources/pdf/HelloWorld.pdf
==============================================================================
Binary file. No diff available.