简体   繁体   English

如何在Objective-C中的PDF中添加欧元货币符号

[英]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. 我在Objective-C中制作一个PDF文件,一切顺利。 But when I add some curreny symbols in the PDF, it shows something totally different. 但是当我在PDF中添加一些当前符号时,它会显示完全不同的东西。

‚dž2,060,0 instead of €2,060,0 ,dž2,060,0而不是€2,060,0

I have uses the following code to draw text in a PDF: 我使用以下代码在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. 提前致谢。

尝试使用欧元符号的unicode

\u20AC

Right way to go is needs to use NSNumberFormatter. 正确的方法是需要使用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. 结果将是带有货币符号的字符串,具体取决于区域设置。

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. 将文本添加到textToDraw字符串。 No need to convert to constant char. 无需转换为常量char。

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

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