[Quoting myself]
> I want to display a hex string like in the example below in 
> the document
> 
> % example
> 3 0 obj
> <048180543954b8b1be5747b6ef1d7933988379e3ddfa7848f59f5e38ec200
> 3a17b241fd5bcf
> 94379536f64bcf4a218ff8debed6674929ba03d710c73396c2b791f00782d7
> 49f99a40f2e05a
> 1b88dd9a876e7fe2a17d3402d231d513a2a9488cbe9656e6a32d3ab3ffc683
> be8e83c760c391
> 667cdf0463b06eceafb1b1b16317fe889c1>
> endobj
> 
> In this example it should appear in the document like this:
> 048180543954b8b1be5747b6...

> And the second idea was to define (or use, if it already 
> exists) a special
> font with a special character set, so that for example the hex string
> <616263> will not be displayed as "abc" but as "616263" and  so on.


Now, I tried this approach, but I haven't come very far.
For test purposes, I defined my own true type font with only one arbitrary
glyph. And I mapped this one glyph to all characters with values from 00 to
FF - or at least I think that's what I did. You find the font file attached.

When I try to use this font for the annotation where I want to display the
hex string, like in the code sample below, I don't get the desired result.

        // ...
        PdfContentByte appearance = new PdfContentByte(writer);
        appearance = appearance.createAppearance(PageSize.A4.width(), 50);
        BaseFont hexFont = BaseFont.createFont("test.ttf", BaseFont.WINANSI,
BaseFont.EMBEDDED);
        ((PdfAppearance) appearance).setFontAndSize(hexFont, 10);
        PdfAnnotation annot = PdfAnnotation.createFreeText(writer, new
Rectangle(0, PageSize.A4.height()-50,
                                        PageSize.A4.width(),
PageSize.A4.height()), "Signaturwert", appearance);
        annot.put(PdfName.CONTENTS, sigReference); // sigReference is the
reference to the hex string object
        // ...

The creation of the PDF file does not throw any exceptions, but in the
resulting document, the annotation is not displayed. Now, for instance, if I
change the value of the hex string to <616263>, manually, the annotation is
displayed with the text "abc", which confuses me (I would have expected to
get my special glyph displayed three times).

I guess, I am doing something wrong with the encoding.
So, what do I have to do, that a certain glyph which is, for example, mapped
to the character code 00 in the font file, is displayed for the hex string
<00>?
Or maybe there is some fundamental misunderstanding?

Thanks for your help,
Stefan

Attachment: test.ttf
Description: Binary data

Reply via email to