Crazy Developer
Crazy Developer

Reputation: 3464

How to add a Euro currency symbol in a PDF in Objective-C

I am making a PDF file in Objective-C and all goes well. But when I add some curreny symbols in the PDF, it shows something totally different.

‚dž2,060,0 instead of €2,060,0

I have uses the following code to draw text in a PDF:

NSString *reducedString = @"€4,854,525";
CGContextShowTextAtPoint (currentContext,xPos, yPos, [textToDraw UTF8String], [reducedString length]);

Anyone knows how to draw the Euro symbol using this same code ? Is there anything I need to change in the text encoding?

[reducedString drawAtPoint:CGPointMake(xPos  ,yPos) withFont:[UIFont systemFontOfSize:15];

Thanks in advance.

Upvotes: 3

Views: 932

Answers (3)

Suyog Patil
Suyog Patil

Reputation: 1616

Try this

//for the document Header
NSString *textToDraw = @"Your text";
UIFont *font = [UIFont boldSystemFontOfSize:18.0];
CGSize stringSize = [textToDraw sizeWithFont:font constrainedToSize:CGSizeMake(pageSize.width - 2*kBorderInset, pageSize.height - 2*kBorderInset - 2*kMarginInset) lineBreakMode:UILineBreakModeWordWrap];
//for title
fYheight=fYheight+25;
CGRect renderingRect = CGRectMake(kBorderInset, fYheight, pageSize.width - 2*kBorderInset, stringSize.height);
[textToDraw drawInRect:renderingRect withFont:font lineBreakMode:UILineBreakModeWordWrap alignment:UITextAlignmentCenter];

Add your text to textToDraw string. No need to convert to constant char.

Upvotes: 0

Ramis
Ramis

Reputation: 16549

Right way to go is needs to use NSNumberFormatter.

NSInteger currency = 4345;
NSNumberFormatter *numberFormatter = [[[NSNumberFormatter alloc] init] autorelease];
[numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
NSString *result = [numberFormatter stringFromNumber:[NSNumber numberWithInteger:currency]];

And result will be string with currency sign depending on the locale.

Upvotes: 1

Shamis Shukoor
Shamis Shukoor

Reputation: 2515

Try using the unicode of euro symbol

\u20AC

Upvotes: 5

Related Questions