Uploaded image for project: 'PDFBox'
  1. PDFBox
  2. PDFBOX-3147

PDFBox fail to write Thai character properly

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.0.0
    • None
    • Writing
    • None
    • Windows 7 x86-64.
      JRE 8 build 1.8.0_66-b17

    Description

      		try {
      			// Create a document and add a page to it
      			PDDocument document = new PDDocument();
      			PDPage page = new PDPage();
      			document.addPage( page );
      
      			// Create a new font object by loading a TrueType font into the document
      			PDFont font = PDType0Font.load(document, new File("ARIALUNI.TTF"));
      
      			// Start a new content stream which will "hold" the to be created content
      			PDPageContentStream contentStream = new PDPageContentStream(document, page);
      
      			// Define a text content stream using the selected font, moving the cursor and drawing the text "Hello World"
      			contentStream.beginText();
      			contentStream.setFont( font, 12 );
      			contentStream.newLineAtOffset( 100, 700 );
      			contentStream.showText( "กูกินก้งปิ้งอยู่ในถ้ำ" );
      			contentStream.endText();
      
      			// Make sure that the content stream is closed:
      			contentStream.close();
      
      			// Save the results and ensure that the document is properly closed:
      			document.save( "ArialUnicode.pdf");
      			document.close();
      		} catch (IOException e) {
      			e.printStackTrace();
      		}
      

      The code above is modified from sample code provided via PDFBox example.
      I tried to use Arial Unicode font which is shipped as part of Windows 7.
      The generated PDF missing some glyph and render some other gibberish glyph.

      Attachments

        1. ArialUnicode.pdf
          14 kB
          Nattapong Sirilappanich
        2. compareresult.jpg
          24 kB
          Nattapong Sirilappanich
        3. ThaiText.txt
          0.1 kB
          Nattapong Sirilappanich
        4. example.pdf
          22 kB
          Tilman Hausherr

        Activity

          People

            Unassigned Unassigned
            natta@th.ibm.com Nattapong Sirilappanich
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: