You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by bincy pothen <bi...@gmail.com> on 2018/01/16 11:15:10 UTC

PDF Box localization support for Japanese

Hi,

We are planning on using PDFBox. Wanted to confirm if localization can be
implemented i.e. can PDF reports be generated using PDFBox for languagues
like Japanese.

It would be good if you could help with any resources or materials of how
this can be achieved.

The code that we are using is :

String language = new String("ja");
            String country = new String("JP");

        Locale currentLocale;
        currentLocale = new Locale(language, country);
        ResourceBundle messages;
        messages = ResourceBundle.getBundle("MessageBundle", currentLocale);
        System.out.println(messages.getString("greeting"));
PDDocument document = new PDDocument();
            PDPage page = new PDPage();

            document.addPage(page);
            PDFont font = PDType1Font.HELVETICA_BOLD;

            PDPageContentStream content = new PDPageContentStream(document,
page);
            content.beginText();
            content.setFont( font, 12 );
            content.newLineAtOffset(150, 750);
            content.showText(messages.getString("greeting"));


But while executing this we receive the following error.

Exception in thread "main" java.lang.RuntimeException:
java.lang.IllegalArgumentException: U+30EC ('rekatakana')
is not available in this font Helvetica-Bold encoding: WinAnsiEncoding

PDFBox define 14 standard fonts in PDType1Font :

PDType1Font.TIMES_ROMAN
PDType1Font.TIMES_BOLD
PDType1Font.TIMES_ITALI
PDType1Font.TIMES_BOLD_ITALIC
PDType1Font.HELVETICA
PDType1Font.HELVETICA_BOLD
PDType1Font.HELVETICA_OBLIQUE
PDType1Font.HELVETICA_BOLD_OBLIQUE
PDType1Font.COURIER
PDType1Font.COURIER_BOLD
PDType1Font.COURIER_OBLIQUE
PDType1Font.COURIER_BOLD_OBLIQUE
PDType1Font.SYMBOL
PDType1Font.ZAPF_DINGBATS


Thanks,
Bincy

Re: PDF Box localization support for Japanese

Posted by Tilman Hausherr <TH...@t-online.de>.
https://pdfbox.apache.org/2.0/faq.html#fontencoding

==> use PDType0Font.load() instead of using the standard 14 fonts.

Tilman

PS: please post further questions on the users list, this is the dev list.

Am 16.01.2018 um 12:15 schrieb bincy pothen:
> Hi,
>
> We are planning on using PDFBox. Wanted to confirm if localization can be
> implemented i.e. can PDF reports be generated using PDFBox for languagues
> like Japanese.
>
> It would be good if you could help with any resources or materials of how
> this can be achieved.
>
> The code that we are using is :
>
> String language = new String("ja");
>              String country = new String("JP");
>
>          Locale currentLocale;
>          currentLocale = new Locale(language, country);
>          ResourceBundle messages;
>          messages = ResourceBundle.getBundle("MessageBundle", currentLocale);
>          System.out.println(messages.getString("greeting"));
> PDDocument document = new PDDocument();
>              PDPage page = new PDPage();
>
>              document.addPage(page);
>              PDFont font = PDType1Font.HELVETICA_BOLD;
>
>              PDPageContentStream content = new PDPageContentStream(document,
> page);
>              content.beginText();
>              content.setFont( font, 12 );
>              content.newLineAtOffset(150, 750);
>              content.showText(messages.getString("greeting"));
>
>
> But while executing this we receive the following error.
>
> Exception in thread "main" java.lang.RuntimeException:
> java.lang.IllegalArgumentException: U+30EC ('rekatakana')
> is not available in this font Helvetica-Bold encoding: WinAnsiEncoding
>
> PDFBox define 14 standard fonts in PDType1Font :
>
> PDType1Font.TIMES_ROMAN
> PDType1Font.TIMES_BOLD
> PDType1Font.TIMES_ITALI
> PDType1Font.TIMES_BOLD_ITALIC
> PDType1Font.HELVETICA
> PDType1Font.HELVETICA_BOLD
> PDType1Font.HELVETICA_OBLIQUE
> PDType1Font.HELVETICA_BOLD_OBLIQUE
> PDType1Font.COURIER
> PDType1Font.COURIER_BOLD
> PDType1Font.COURIER_OBLIQUE
> PDType1Font.COURIER_BOLD_OBLIQUE
> PDType1Font.SYMBOL
> PDType1Font.ZAPF_DINGBATS
>
>
> Thanks,
> Bincy
>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org