wicked_pdf render thai text incorrectly - ruby-on-rails-4

I want to render thai text with wicked_pdf which uses wkhtmltopdf, but the resulting PDF is incorrect as you can see below. I try setting the font with css font-family but it doesn't help. My template has <meta charset='utf-8' />
Incorrect:
Correct:
Update:
I tried to convert a html with thai text to pdf using the wkhtmltopdf cli and the text is rendered correctly. I tried to point wicked_pdf to the same executable, but the problem still occur when rendered in wicked_pdf

When you render the pdf, try passing "UTF-8" to the encoding option as well.
render pdf: "my_pdf", encoding: "UTF-8"

Related

<pre> tag automatically added - HTMLCodeFormat() and HTMLEditFormat()

I have a form with several TinyMCE textareas. Content is loaded in some textareas when the form is called. Other textareas are empty.
The content that is preloaded into the text fields already has a <p> tag. Everything is fine with it. But i have a problem with the empty textareas. TinyMCE automatically adds a <pre> tag, which destroys the formatting and layout.
This is the process that leads to the problem:
Open the form and enter unformatted text to a empty textarea.
Save the form. The content is displayed correctly. Everything is fine so far.
Edit the form / content.
At this point, TinyMCE adds the pre tag. The tag is not yet saved in the database, it comes from the editor.
I also made some tests with preloaded content. This is the result.
Template code | TinyMCE textarea
<p>test</p> | <p>test</p>
test | <pre>test</pre>
How can I prevent TinyMCE from adding the <pre> tag? Alternatively, <pre> could also be replaced by <p>.
If you're on ColdFusion 10 or later, you should be using the OWASP ESAPI encoding functions. They handle a higher range of character encoding than HTMLEditFormat() and HTMLCodeFormat().
Output between HTML tags: <td>#encodeForHTML(variables.myVar)#</td>
Output in an HTML attribute: <input type="text" value="#encodeForHtmlAttribute(variables.myVar)#">
The cause of the problem was the use of HTMLCodeFormat instead of HTMLEditFormat before I handed the content over to TinyMCE. Both have nearly the same effect, but HTMLCodeFormat adds a <pre> tag in addition.
HTMLCodeFormat()
HTMLEditFormat()

How To Display Japanese Characters in ColdFusion With <cfoutput>

I am creating a ColdFusion page with some Japanese characters. I included the following in the top of the page.
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
If I explicitly include Japanese characters in the output, they look fine. However, if I output them using, say:
<cfoutput>#variables.TitleInJapanese#</cfoutput>
The output is garbled as though the encoding is not recognized. I have tried <cfcontent> and <cfprocessingdirective> tags to no avail.
If I open the .cfm source file, the Japanese characters that are assigned to the variables look as they should in my text editor. It's the content that is generated using <cfoutput> that is giving me trouble. Any suggestions would be welcome. Thanks!
Correction: The page I have created will not display any Japanese characters, explicit or referenced. However, other files using <cfinclude> within the page that have Japanese characters render just fine.

Incorrect displaying of russian characters in Python / Django

I am trying to parse a russian website using lxml. However ,I got an issue with displaying russian characters, that i am unable to overcome myself.
Let's take this html piece for example:
Квест в реальности «Карты, деньги, два стола»
I am using this piece to parse it:
title = root.xpath('//*[#id="event-id-41600"]/div[3]/div[2]/a/text()')[0].encode('utf-8').strip()
and this is what i get:
├É┬Ü├É┬▓├É┬Á├Ĺ┬ü├Ĺ┬é ├É┬▓ ├Ĺ┬Ç├É┬Á├É┬░├É┬╗├Ĺ┬î├É┬Ż├É┬ż├Ĺ┬ü├Ĺ┬é├É┬Ş ├é┬ź├É┬Ü├É┬░├Ĺ┬Ç├Ĺ┬é├Ĺ┬ő, ├É┬┤├É┬Á├É┬Ż├Ĺ┬î├É┬│├É┬Ş, ├É┬┤├É┬▓├É┬░ ├Ĺ┬ü├Ĺ┬é├É┬ż├É┬╗├É┬░├é┬╗
In database however instead of cyrillic i see this:
ÐвеÑÑ Ð² ÑеалÑноÑÑи «ÐаÑÑÑ, денÑги, два ÑÑола»
Oh and btw for reference:
this piece:
title = item.xpath('div[3]/div[2]/a')[0]
print etree.tostring(title)
returns me this :
Квест в реальности «Карты, деньги, два стола»
Not sure if it is database related of something to do with python encoding. Any help appreciated :)
Thanks in advance.
EDIT: i am using MySQL and Django ORM
Django settings:
DATABASE_OPTIONS = {
"charset": "utf8_general_ci",
"init_command": "SET storage_engine=INNODB"
}
Webpage :
<!DOCTYPE html>
<html lang="en" prefix="og: http://ogp.me/ns#" class="">
<head>
<title>Интересные события в Москве в январе - феврале 2016</title>
<meta charset="utf-8">
Cyrillic code page does not exist/not setted up on your server. So you can`t view russian characters in terminal even in UTF-8. But python stil work with unicode properly.
By this command:
title = root.xpath('//*[#id="event-id-41600"]/div[3]/div[2]/a/text()')[0].encode('utf-8').strip()
you get unicode string and encode it to bytes (str in python2). And save bytes in database.
When you load string from database python uses default code page (probably Latin-1) and you get this:
ÐвеÑÑ Ð² ÑеалÑноÑÑи «ÐаÑÑÑ, денÑги, два ÑÑола»
So, you should store unicode string in database (don't use encode)
title = root.xpath('//*[#id="event-id-41600"]/div[3]/div[2]/a/text()')[0].strip()
P.S. I don't understand how encode('Latin-1') helps (from comments), but problem is solved :)

Freemarker template not displaying image

Is there a particular syntax for freemarker template to be used to display image?
I have used the usual
<img src = "test1.png" />
in the body tag of the ftl template to display image but it is not displaying the image for me when I run the code. FTL generates the html page with all relevant data excpet that it doesnt display image.
SHould I use any escape sequences or any other syntax?
Thnks
Got the answer..
Its
<img src= "test1.jpg" />
just like I had added before. I wonder why it wasnt working earlier.

Why django displays unreadable characters in IE?

My django code works in chrome and firefox but in IE the webpage displays unreadable charactars. The following is my code setting:
DEFAULT_CHARSET = 'utf8'
FILE_CHARSET = 'utf8'
and the template files are saved as utf8 format, but my template file has some other language besides english. That non-english part is not readable.
Should I change some setting of django ? Most of the visitors of my website may use IE, so this is a big problem. Any suggestions?
did you add this meta to your base html?
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>