Drawing Marathi and Hindi text, and filled rectangles with transparency.
Example_31.pdf — the PDF this example creates.
/*
* Example_31.java
*
* Copyright (c) 2026 PDFjet Software
* Licensed under the MIT License. See LICENSE file in the project root.
*/
package examples;
import java.io.*;
import com.pdfjet.*;
import com.pdfjet.fonts.*;
/**
* Example_31.java
*/
public class Example_31 {
public Example_31() throws Exception {
PDF pdf = new PDF(
new BufferedOutputStream(new FileOutputStream("Example_31.pdf")));
Font f1 = new Font(pdf, IBMPlexSansDevanagari.Regular);
f1.setSize(15f);
Page page = new Page(pdf, Letter.PORTRAIT);
TextBlock textBlock = new TextBlock(
f1, Content.ofTextFile("data/languages/marathi.txt"));
textBlock.setLocation(50f, 50f);
textBlock.setWidth(500f);
textBlock.drawOn(page);
String str = "असम के बाद UP में भी CM कैंडिडेट का ऐलान करेगी BJP?";
TextLine textLine = new TextLine(f1, str);
textLine.setLocation(50f, 175f);
textLine.drawOn(page);
page.setPenColor(Color.blue);
page.setBrushColor(Color.blue);
page.fillRect(50f, 200f, 200f, 200f);
page.saveGraphicsState();
GraphicsState gs = new GraphicsState();
gs.setAlphaStroking(0.5f); // The stroking alpha constant
gs.setAlphaNonStroking(0.5f); // The non-stroking alpha constant
page.setGraphicsState(gs);
page.setPenColor(Color.green);
page.setBrushColor(Color.green);
page.fillRect(100f, 250f, 200f, 200f);
page.setPenColor(Color.red);
page.setBrushColor(Color.red);
page.fillRect(150, 300, 200f, 200f);
page.restoreGraphicsState();
page.setPenColor(Color.orange);
page.setBrushColor(Color.orange);
page.fillRect(200, 350, 200f, 200f);
page.setBrushColor(0x00003865);
page.fillRect(50, 550, 200f, 200f);
pdf.complete();
}
public static void main(String[] args) throws Exception {
long time0 = System.currentTimeMillis();
new Example_31();
long time1 = System.currentTimeMillis();
System.out.printf("Example_31 => %4d ms%n", time1 - time0);
}
} // End of Example_31.java
©2026 PDFjet Software.