How to write Euro (€) symbol to an Android PDF - android

I am creating a pdf from my android app but it is impossible to output the "€" symbol (it appears as "?")
I have already tried with the unicode value "\u20ac" and it is not working.
Any idea?
Many thanks in advance.

I had the same problem with APW (Android PDF Writer). Normally with ISO-8859-15 the EURO SIGN (U+20AC) is at position 164 (0xa4) but it gave me the currency sign (¤), so I tried with the position 128 (0x80) (€ in my string.xml) used in Windows-1252 and it worked.
I suppose it's related to the PDF font encoding using StandardFonts.WIN_ANSI_ENCODING.

Related

Weird characters while displaying hindi text in android

I want to display some text in hindi that I am getting from server.
While showing the text some weird characters are displayed (à¤à¥à¤¸à¥à¤à¤¿à¤à¤).
But in iOS its showing perfectly
I think its some encoding issue
By default Android phone (Now some does support) doesn’t support Devanagari fonts. However if you want to use hindi, tamil, bangali or other Devanagari fonts in your Android Application you have an alternative of using external fonts.
Follow these steps...
Download an external Devanagari font that you like to use in your application.
ex. (Verdana.ttf or anand-lipi-bold)
Create a new folder “fonts” under assets and copy the downloaded .ttf font to your assets/font folder.
then Load .ttf to your TextView.
TextView tv = (TextView) findViewById(R.id.textView);
Typeface fontHindi = Typeface.createFromAsset(getAssets(),
"fonts/Ananda Lipi Bold Cn Bt.ttf");
tv.setTypeface(fontHindi);
tv.setText("Hindi font");
Hope this will help you.
Please use below Code for getting string
new String("Your String".getBytes("ISO-8859-1"), "utf-8")
I was also getting some arabic string from server and it was displaying some chaaracters like yours but after using this it solved
Here instead of ISO-8859-1 you can use encode type in which data is encoded on server side
Finally got an answer myself
I am using volley as my networking library and by default its encoding was in latin-1
So after changing to utf-8 it worked perfectly
Thanks everyone for your help

Symbols show up as � after i parse an html webpage using jsoup and display contents in android listview

I would like to understand this problem i have been having.
Im parsing an html source page and displaying the content i want in a list view in android.
I parse the page using this command.
doc = Jsoup.connect(myURL).get();
Symbols such as é or “ ” show up as �.
I understand they are not being recognized by the encoding mechanism but is it because of jsoup or android?
Android default encoding im using is Utf-8 should it not support that?
If it should not how and what should i change it to?
Thank you for you help.
é in ISO-8859-1 (extend ASCII) is the value 233 but in UTF-8 it is the value 195 folowed by 169.
You need to know in what encoding the caracters are saved in because only the values are saved and then interpreted.
Thank you guys for the help.
making the jsoup call like this :
Document document = Jsoup.parse(new URL(url).openStream(), "ISO-8859-1", url);
was the way to go i then had to find out the real encoding of the webpage in chrome you can find it in 'more tools' and in my case it was
windowns-1252. One line of code solved the problem:
doc = Jsoup.parse(new URL(url).openStream(), "windows-1252", url);

How to add Currency Symbols in pdf, generated by my application?

I want to add currency symbols in pdf report, generated by my android application. String symbols i am adding to the file... but its not displaying. Is there any solution? Do i need to use any fonts or encoding for that?
If you need to use just a few currency signs then you may use a walk around for for some symbols, for example for the Euro sign in PDF using the built-in pdf font Helvetica with the 1252 code page:
BaseFont helvetica = BaseFont.createFont("Helvetica", BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
Font font = new Font(helvetica, 12, Font.NORMAL);
Chunk chunk = new Chunk("Euro symbol: 20\u20ac.", font);
document.add(chunk);
But if you are looking to support all currency symbols then you should use the unicode enabled font (like Arial Unicode MS) and embed it into output PDF. You may find the complete list of Unicode currency symbols at unicode.org.

Encoding URL with German Characters

In my app I receive a URL such as
http://www.wassersportlotse.de/php/lib/smart_image_resizer/image.php/Mühlendammschleuse.jpg?image=/media/images/uploads/Mühlendammschleuse.jpg
When there are no German characters in the fullurl I can just use it without encoding and it works fine. However if I receive a URL such as the one above it doesn't work (the ü is causing the problem). Below I have tried to encode the seperate parts of the URI to no avail. As alway advice is very much appreciated.
public ImageDownloader(String fullurl) throws URISyntaxException{
URI uri = new URI(fullurl);
path = uri.getPath();
path = URLEncoder.encode(path);
query = uri.getQuery();
query = URLEncoder.encode(query);
auth = uri.getAuthority();
url = "http://" + auth + path + query;
}
Maybe the encoder das encode the Umlaut as UTF-8 characters (so ü would be encoded with two characters) and they are not put back together properly at the server (for us it didn't work with Tomcat). To solve this situation we used URLEncoder.encode(param, "ISO-8859-1") to encode the parameters.
There's no simple answer, because it depends on the server serving that URI which encoding is expected.
Usually it's UTF-8.
In that case: use String.getBytes, specifying the UTF-8 encoding, and obtain a byte array from that. Re-encode that byte array as string by taking all bytes <= 127 as-is, and substituting all others by the %hh form. (percent sign, then two hex digits). See http://greenbytes.de/tech/webdav/rfc3986.html#rfc.section.2.1.
You can use Android's Uri class to help you out. That class has an encode() method which will use UTF-8 to encode your string.
I recently had a problem with URLs for images whose names included umlauts and German special characters, and I lost a day looking for the solution. The images simply did not appear if there was an ä or and ü in the file name or the directory name. I thought it might be spring, or some other Java technology I am working with, or in the browser. And strangely enough, even with the url encoded, it failed to find the image. But in the end, the solution was in my tomcat server.xml configuration. In your server.xml file, find your connector and add these two lines:
URIEncoding="UTF-8"
useBodyEncodingForURI="true"
At the end, it should look something like this:
<Connector connectionTimeout="20000"
port="8080"
protocol="HTTP/1.1"
redirectPort="8443"
URIEncoding="UTF-8"
useBodyEncodingForURI="true"/>
Now I do not need to url-encode the url. This is a help to my clients, because they can see the German words in the urls spelled correctly.
Here is another tip: if you are coding in eclipse and starting and stopping your server from inside eclipse, then the configuration file (server.xml) could be in your eclipse workspace in the Servers folder. It must be changed here for it to work with eclipse. This can be maddening, when you have made the change in your principal tomcat configuration, and the urls work there, but they are still broken when running the server in eclipse.
That did it for me. I hope it helps someone out there! :-)
Have your tried unsing:
android.net.Uri.encode(urlString, ":/");
It encodes the string but skips ":" and "/".

Why is WebView unable to open some local URLs (Android)?

I have a WebView that I'm using to open some files stored in the assets/ directory of my project. It works fine for most of the files, but there's one in particular (and I'm sure others I haven't found) that it just will not open.
The file I'm having problems with is named:
"assets/ContentRoot/Photos/XXX Software Logo - jpg - 75%.JPG"
When I pass it to WebView, and it shows the error page, it shows it as:
"file:///android_asset/ContentRoot/Photos/XXX%20Software%20Logo%20-%20jpg%20-%2075%.JPG"
I then tried running URLEncoder.encode() on it and got the error page with the URL presented as:
"file:///android_asset/ContentRoot/Photos/XXX+Software+Logo+-+jpg+-+75%.JPG"
Neither of these URLs were able to open the file (and they both look okay to me). Anyone have any ideas?
UPDATE: If I encode the % by hand (using %25, as commonsware.com suggested) then it loads the image, but it tries to parse it as text, not as an image, so I just get a lot of (basically) garbage.
Also, referring to the image in an HTML document with a relative URL isn't working (probably because it's not being parsed as an image?):
<img src="../Photos/XXX%20Software%20Logo%20-%20jpg%20-%2075%.JPG" />
<img src="../Photos/XXX%20Software%20Logo%20-%20jpg%20-%2075%25.JPG" />
Okay, after spending way too long on this, I've figured out what's going on. Basically, if images stored in the assets/ directory contain a space (e.g., " ") in their file name, they won't render as images.
myWebView.loadUrl("file:///android_asset/testimage.jpg");
works fine. However,
myWebView.loadUrl("file:///android_asset/test+image.jpg");
just throws a not found error and
myWebView.loadUrl("file:///android_asset/test image.jpg");
// and
myWebView.loadUrl("file:///android_asset/test%20image.jpg");
show it improperly displayed (as text... see screenshot in question).
This unexpected behaviour is present on (at least) 1.5, 1.6, and 2.0 and I filed a bug report.
Try getting rid of the % in the filename. Or, escape it as %25.
I would guess that WebView only understands text related content types so it faithfully treating your JPG as base64 encoding, decodes and displays resulted gobble-goop as text. I don't really know if it's possible to set content type for WebView but as workaround you can try to throw img tag inside html tag and load resultet page. Also you probably can only use WebView#loadDataWithBaseUrl

Categories

Resources