Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8270553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:36:04+00:00 2026-06-08T06:36:04+00:00

The following code is simplified case for my Java2D application which prints to PDF.

  • 0

The following code is simplified case for my Java2D application which prints to PDF. It some how does not print ‘Dotted I in turkish language.‘ using the PDFGrahics2D.

import com.lowagie.text.pdf.PdfWriter;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfTemplate;
import com.lowagie.text.pdf.DefaultFontMapper;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Rectangle;

import java.io.FileOutputStream;
import java.io.File;
import java.io.IOException;
import java.awt.Graphics2D;
import java.awt.Font;

public class DottedIExampleWithGraphics2D
{

    private static final float WIDTH = 900;
    private static final float HEIGHT = 500;
    private DefaultFontMapper mapper = new DefaultFontMapper();

    public void testWriteOfStringWithFont() throws IOException, DocumentException
    {

        File fontFile = new File("c:/windows/fonts/arialuni.ttf");
        BaseFont bf = BaseFont.createFont(fontFile.getAbsolutePath(),
                BaseFont.IDENTITY_H,
                BaseFont.NOT_EMBEDDED);
        Font theFont = mapper.pdfToAwt(bf, 18);
        Document document = new Document(new Rectangle(WIDTH, HEIGHT));

        File testFile = new File("learning_withfont.pdf");
        FileOutputStream fos = new FileOutputStream(testFile);
        PdfWriter writer = PdfWriter.getInstance(document, fos);
        document.open();

        PdfContentByte cb = writer.getDirectContent();
        PdfTemplate tp = cb.createTemplate(WIDTH, HEIGHT);
        cb.addTemplate(tp, 0, 0);
        Graphics2D graphics = tp.createGraphics(WIDTH, HEIGHT, mapper);

        graphics.setFont(theFont);
        graphics.drawString(" \u0130 , \u0131 ", 25, 50);

        graphics.drawString(bf.getPostscriptFontName(), 25, 100);

        //
        graphics.dispose();
        document.close();

        System.out.println("testFile.getAbsolutePath() = " + testFile.getAbsolutePath());
    }

    /**
     */
    public static void main(String[] args) throws IOException, DocumentException
    {
        new DottedIExampleWithGraphics2D().testWriteOfStringWithFont();
    }
}

The output is like this.

Dotted I missing in this

The problem is how to print such characters to PDFGraphics2D. The java code for creating PDF normally, works. Code is here for quick reference.

import com.lowagie.text.Chunk;
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.File;
import java.io.FileOutputStream;
import java.io.IOException;

public class DottedIExample
{

    /**
     * Creates a PDF document. write a string and font name
     */
    public void createPdf(String filename) throws IOException, DocumentException
    {

        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream(filename));

        document.open();
        File fontFile = new File("c:/windows/fonts/arialuni.ttf");
        BaseFont bf = BaseFont.createFont(fontFile.getAbsolutePath(),
                BaseFont.IDENTITY_H,
                BaseFont.NOT_EMBEDDED);
        Font font = new Font(bf, 12);
        document.add(new Paragraph(bf.getPostscriptFontName(), font));
        document.add(new Paragraph("\u0131 , \u0130", font));
        document.add(Chunk.NEWLINE);

        document.close();
    }

    /**
     */
    public static void main(String[] args) throws IOException, DocumentException
    {
        File result = new File("dottedi.pdf");
        new DottedIExample().createPdf(result.getAbsolutePath());
        System.out.println("result at = " + result.getAbsolutePath());
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T06:36:06+00:00Added an answer on June 8, 2026 at 6:36 am

    The problem was with mapper. Its awtToPdf()/pdf2awt() should be setup to return the correct font.

    Fixed code , just for reference.. (actual setup of mapper is more complicated)

    import com.lowagie.text.pdf.PdfWriter;
    import com.lowagie.text.pdf.PdfContentByte;
    import com.lowagie.text.pdf.PdfTemplate;
    import com.lowagie.text.pdf.DefaultFontMapper;
    import com.lowagie.text.pdf.BaseFont;
    import com.lowagie.text.Document;
    import com.lowagie.text.DocumentException;
    import com.lowagie.text.Rectangle;
    
    import java.awt.*;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.File;
    import java.io.IOException;
    
    public class DottedIExampleWithGraphics2D {
    
        private static final File aFontFile = new File(("c:/windows/fonts/arialuni.ttf"));
        private static final float WIDTH = 90;
        private static final float HEIGHT = 50;
        private DefaultFontMapper mapper = new DefaultFontMapper() {
            @Override
            public BaseFont awtToPdf(Font font) {
                try {
                    return BaseFont.createFont(aFontFile.getAbsolutePath(),
                            BaseFont.IDENTITY_H,
                            BaseFont.NOT_EMBEDDED);
                } catch (DocumentException e) {
                    e.printStackTrace();  //blah
                } catch (IOException e) {
                    e.printStackTrace();  //blah
                }
                return null;
            }
    
            @Override
            public Font pdfToAwt(BaseFont baseFont, int i) {
                try {
                    return Font.createFont(Font.TRUETYPE_FONT, new FileInputStream(aFontFile));
                } catch (FontFormatException e) {
                    e.printStackTrace();  //blah
                } catch (IOException e) {
                    e.printStackTrace();  //blah
                }
                return null;
            }
        };
    
    
        public void testWriteOfStringWithFont() throws IOException, DocumentException {
    
    
            Font theFont = mapper.pdfToAwt(null, 18);
            Document document = new Document(new Rectangle(WIDTH, HEIGHT));
    
            File testFile = new File("learning_withfont.pdf");
            FileOutputStream fos = new FileOutputStream(testFile);
            PdfWriter writer = PdfWriter.getInstance(document, fos);
            document.open();
    
            PdfContentByte cb = writer.getDirectContent();
            PdfTemplate tp = cb.createTemplate(WIDTH, HEIGHT);
            cb.addTemplate(tp, 0, 0);
            Graphics2D graphics = tp.createGraphics(WIDTH, HEIGHT, mapper);
    
            graphics.setColor(Color.blue);
            graphics.setFont(theFont);
            graphics.drawString(" \u0130 , \u0131 , \u0049, \u0069", 10, 10);
    
            graphics.drawString("some", 10, 30);
    
            //
            graphics.dispose();
            document.close();
    
            System.out.println("testFile.getAbsolutePath() = " + testFile.getAbsolutePath());
        }
    
        /**
         */
        public static void main(String[] args) throws IOException, DocumentException {
            new DottedIExampleWithGraphics2D().testWriteOfStringWithFont();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the below (simplified) code, which uses the following source: <html> <p>line 1</p>
Imagine I have the following code (simplified regarding my real context of course): <div
I'm using gcc 4.3.2. I have the following code (simplified): #include <cstdlib> template<int SIZE>
Following simplified code snippet: #include <QtGui> int main(int argc, char **argv) { QApplication app(argc,
The following code is a simplified version of what I use for event dispatching.
I've got following (simplified for example purpose) code and it works: void log(const string
I have the following code (simplified): ostringstream oss; oss << Text ; oss <<
I've reduced my code down to the following, which is as simple as I
This is a simplified version of some of my code: public struct info {
I have the following code (simplified for the sake of discussion). What I don't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.