You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Richard van Heest <ri...@solcon.nl> on 2011/07/15 10:21:19 UTC

€ in PDF


Hello,

 

Does anyone know how to print an €-sign into a PDF, using the PDFBox-library?

I use the normal way of writing into a pdf with this code:

 

PDPage page = this.getPage(pagenr);

PDPageContentStream stream;

try {

      stream = new PDPageContentStream(this.document, page, true, false);

      stream.setFont(PDType1Font.HELVETICA, 10);

      stream.setNonStrokingColor(Color.black);

 

      stream.beginText();

      stream.moveTextPositionByAmount(5, 7);

      stream.drawString("€"); 

      stream.endText();

      stream.close();

}

catch(IOException e) {

      e.printStackTrace();

}

 

But then some other signs appears (look in the attachment).

This also happens when I use the Unicode “\u20AC” instead of “€”.

 

So, does anyone know how to do this?

 

Thanks a lot!

 

Richard van Heest

Prins Bernhardlaan 116

3241 TA  MIDDELHARNIS

Tel. 0187-482094

Mob. 06-51040247

E-mail  <ma...@solcon.nl> richardvanheest@solcon.nl

 


Re: € in PDF

Posted by Jeremias Maerki <de...@jeremias-maerki.ch>.
Hi Richard,

I think the easiest solution is to use a different font. The AFM files
from Adobe for the Base 14 fonts are from a pre-Euro-era (1997) and
don't contain metrics for the Euro glyph. With some hacking, you could
probably retrofit it as today's PDF viewers all have a Euro glyph, even
for the Euro glyph. But then, they usually display an ugly Arial instead
of Helvetica.

On 15.07.2011 10:21:19 Richard van Heest wrote:
> 
> 
> Hello,
> 
>  
> 
> Does anyone know how to print an €-sign into a PDF, using the PDFBox-library?
> 
> I use the normal way of writing into a pdf with this code:
> 
>  
> 
> PDPage page = this.getPage(pagenr);
> 
> PDPageContentStream stream;
> 
> try {
> 
>       stream = new PDPageContentStream(this.document, page, true, false);
> 
>       stream.setFont(PDType1Font.HELVETICA, 10);
> 
>       stream.setNonStrokingColor(Color.black);
> 
>  
> 
>       stream.beginText();
> 
>       stream.moveTextPositionByAmount(5, 7);
> 
>       stream.drawString("€"); 
> 
>       stream.endText();
> 
>       stream.close();
> 
> }
> 
> catch(IOException e) {
> 
>       e.printStackTrace();
> 
> }
> 
>  
> 
> But then some other signs appears (look in the attachment).
> 
> This also happens when I use the Unicode “\u20AC” instead of “€”.
> 
>  
> 
> So, does anyone know how to do this?
> 
>  
> 
> Thanks a lot!
> 
>  
> 
> Richard van Heest
> 
> Prins Bernhardlaan 116
> 
> 3241 TA  MIDDELHARNIS
> 
> Tel. 0187-482094
> 
> Mob. 06-51040247
> 
> E-mail  <ma...@solcon.nl> richardvanheest@solcon.nl
> 
>  
> 




Jeremias Maerki