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

  • SEARCH
  • Home
  • 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 8814775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:12:49+00:00 2026-06-14T04:12:49+00:00

Possible Duplicate: Using PDFBox to write UTF-8 encoded strings to a PDF I need

  • 0

Possible Duplicate:
Using PDFBox to write UTF-8 encoded strings to a PDF

I need to create PDF with Czech national characters, and I’m trying to do it with PDFBox library.
I have copied following code from some tutorials:

public void doIt(String file, String message) throws IOException, COSVisitorException
{
    PDDocument doc = null;
    try
    {
        doc = new PDDocument();
        PDSimpleFont font = PDType1Font.TIMES_ROMAN;

        TextToPDF textToPdf = new TextToPDF();

        textToPdf.setFont(font);
        textToPdf.setFontSize(12);
        doc = textToPdf.createPDFFromText(new StringReader(message));
        doc.save(file);
    }
    finally
    {
        if( doc != null )
        {
            doc.close();
        }
    }
}

Now, I’am calling function doIt:

app.doIt("test.pdf", "Skákal pes přes oves, přes zelenou louku.");

This completely works, but in output PDF I get: “þÿSkákal pes pYes oves, pYes zelenou louku.”

I tried to find how to set UTF-8 encoding in PDFBox, but IMHO there is just no solution for this on the internet.

Do you have any ideas, how to get right text in output PDF?

Thank you.

  • 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-14T04:12:50+00:00Added an answer on June 14, 2026 at 4:12 am

    I think its PDType1Font.TIMES_ROMAN font which is not supporting your Czech national characters. If you can manage to get the .ttf files for the Czech national characters, then use below to get PDFont as below and use the same:

          PDFont font = PDTrueTypeFont.loadTTF( doc, new File( "CheckRepFont.ttf" ) );
    

    Here CheckRepFont.ttf is your font file name as an example. Update it with actual one.

    EDIT:

      PDStream pdStream  = new PDStream(doc);
      PDSimpleFont font = PDType1Font.TIMES_ROMAN;
      font.setToUnicode(pdStream);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: using bash: write bit representation of integer to file I need to
Possible Duplicate: Using C/Pthreads: do shared variables need to be volatile? In Linux/C: Do
Possible Duplicate: Using an NSXMLParser to parse HTML I am trying to parse the
Possible Duplicate: Using a javascript variable to set PHP variable I need to do
Possible Duplicate: Using regular expression within a stored procedure I need to validate a
Possible Duplicate: Using ZXing to create an android barcode scanning app I know it
Possible Duplicate: Using jQuery to test if an input has focus I need to
Possible Duplicate: Using LibTiff in Visual Studio 2010 I have been trying to work
Possible Duplicate: error using CArray Duplicate : error using CArray so, i am trying
Possible Duplicate: using jquery $.ajax to call a PHP function I need to call

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.