Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PDF Khmer Unicode Font Not Rendering Correctly #1264

Open
sinsarath opened this issue Feb 7, 2025 · 2 comments
Open

PDF Khmer Unicode Font Not Rendering Correctly #1264

sinsarath opened this issue Feb 7, 2025 · 2 comments
Labels

Comments

@sinsarath
Copy link

Hello everyone,

I'm using Eclipse BIRT Report Designer to generate reports in PDF format, but I’m facing issues with rendering Khmer Unicode Font. The Khmer characters either:

  • Appear as blank or missing text, or
  • Show incorrect khmer characters.

I've tested generating a simple PDF using OpenPDF with the Hanuman font. Here’s the code I used:

import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
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.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class Main {
	public static void main(String[] args) throws DocumentException, IOException {
		// Output PDF file
        Document document = new Document();
        try {
			PdfWriter.getInstance(document, new FileOutputStream("Khmer_Font_Test.pdf"));
		} catch (DocumentException | FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        document.open();
        // Load Hanuman TTF font
        BaseFont hanumanFont = BaseFont.createFont("/Users/sinsarath/eclipse-workspace/SamplePdf/fonts/Hanuman.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
        Font font = new Font(hanumanFont, 14); // Set font size to 14
        // Add Khmer text
        String khmerText = "លេខ";
        document.add(new Paragraph(khmerText, font));

        document.close();
        System.out.println("PDF generated successfully!");
	}
}

Result are render not correct:

Image

It should be displayed like that: លេខ

@sinsarath sinsarath added the bug label Feb 7, 2025
@vk-github18
Copy link
Contributor

@speckyspooky
Copy link

@vk-github18 Thanks for your hint, this was helpful for the original cause which was coming from the BIRT-project - discussion: eclipse-birt/birt#2040

Short additional hint to the reference, the layout-processor enabling LayoutProcessor.enableKernLiga(); must be done before the BaseFont is created to support advanced glyph handling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants