简体   繁体   English

使用PDFBox输出欧元符号

[英]Output euro sign using PDFBox

I have encountered the same problem as described here , ie to output € sign in my generated pdf document. 我遇到了与此处所述相同的问题,即在生成的pdf文档中输出€符号。 The euro sign should be appended after the data retrieved from database, in this case the solution provided is not very useful, I tried with this lines, so that I can use the variable euroToPDF anywhere I want: 从数据库检索到的数据后应附加欧元符号,在这种情况下,提供的解决方案不是很有用,我尝试过使用以下代码行,以便可以在任何需要的地方使用变量euroToPDF

Encoding e = EncodingManager.INSTANCE.getEncoding(COSName.WIN_ANSI_ENCODING);

String euroToPDF = String.valueOf(Character.toChars(e.getCode(e.getCharacter(128))));

but the application throws IOException, saying No character code for character name '€' , anyone knows how to solve this? 但是应用程序抛出IOException,说No character code for character name '€' ,有人知道如何解决吗?

If you are using v2 of PDFBox, you should use the € symbol in the string you output, without trying to convert the encoding. 如果使用的是PDFBox v2,则应在输出的字符串中使用€符号,而不必尝试转换编码。

In v1.8 you can use a trick: 在v1.8中,您可以使用技巧:

contentStream.beginText();
contentStream.setTextMatrix(100, 0, 0, 100, 50, 100);
contentStream.setFont(PDType1Font.HELVETICA, 8);
byte[] commands = "(x) Tj ".getBytes();
commands[1] = (byte) 128;
contentStream.appendRawCommands(commands);
contentStream.endText();
contentStream.close();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM