You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by HK Kim <ju...@gmail.com> on 2013/11/01 16:42:27 UTC

Question about writing string to PDF with Slavic language.

Hi,

I'm having trouble figuring out how to get Slavic language writing working;
input I'm trying is:

przesyłkiąęćktórże

            PDSimpleFont font = PDType1Font.HELVETICA;

            font.setFontEncoding(new PdfDocEncoding());

            // PDSimpleFont font = PDTrueTypeFont.loadTTF(pdfDocument,
newByteArrayInputStream(
mFontBytes)); // tried importing multiple ttfs with no success

            PDPageContentStream stream =
newPDPageContentStream(pdfDocument, widget.getPage(),
true, true);

            stream.beginText();

            stream.setFont(font, 10);

            stream.moveTextPositionByAmount(lowerX, lowerY);

            if (rotate)

            {

                stream.setTextRotation(sNinetyDegreesInRadian, lowerX,
lowerY);

            }

            stream.drawString(value);

            stream.endText();

            stream.close();

It always comes out broken, or with gentium R102 ttf, it isn't broken but
it comes out completely wrong.


put it this way - if you had to write "przesyłkiąęćktórże" onto a pdf as a
text at a random location on PDF, how would you go about it?

Re: Question about writing string to PDF with Slavic language.

Posted by Andreas Lehmkühler <an...@lehmi.de>.
Hi,


> HK Kim <ju...@gmail.com> hat am 1. November 2013 um 16:42 geschrieben:
>
>
> Hi,
>
> I'm having trouble figuring out how to get Slavic language writing working;
> input I'm trying is:
>
> przesyłkiąęćktórże
>             PDSimpleFont font = PDType1Font.HELVETICA;
>
>             font.setFontEncoding(new PdfDocEncoding());
>
>             // PDSimpleFont font = PDTrueTypeFont.loadTTF(pdfDocument,
> newByteArrayInputStream(
> mFontBytes)); // tried importing multiple ttfs with no success
>
>             PDPageContentStream stream =
> newPDPageContentStream(pdfDocument, widget.getPage(),
> true, true);
>
>             stream.beginText();
>
>             stream.setFont(font, 10);
>
>             stream.moveTextPositionByAmount(lowerX, lowerY);
>
>             if (rotate)
>
>             {
>
>                 stream.setTextRotation(sNinetyDegreesInRadian, lowerX,
> lowerY);
>
>             }
>
>             stream.drawString(value);
>
>             stream.endText();
>
>             stream.close();
>
> It always comes out broken, or with gentium R102 ttf, it isn't broken but
> it comes out completely wrong.
>
>
> put it this way - if you had to write "przesyłkiąęćktórże" onto a pdf as a
> text at a random location on PDF, how would you go about it?
PDFBox doesn't support anything else but WinANSI encoded text.

We are working on UTF-8 support, see [1] for further details.

BR
Andreas Lehmkühler
[1] https://issues.apache.org/jira/browse/PDFBOX-922