Skip to content

Commit

Permalink
Added some tests and docs on dealing with exotic chars.
Browse files Browse the repository at this point in the history
  • Loading branch information
ldaley committed Nov 20, 2010
1 parent 0859445 commit ad837ac
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 2 deletions.
6 changes: 4 additions & 2 deletions grails-app/conf/Config.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/
log4j = {
debug 'grails.plugin.rendering'
debug 'grails.plugin.rendering', "org.xhtmlrenderer"
}

grails {
Expand All @@ -26,4 +26,6 @@ grails {
copyright = "Copies of this document may be made for your own use and for distribution to others, provided that you do not charge any fee for such copies and further provided that each copy contains this Copyright Notice, whether distributed in print or electronically."
footer = "Developed by the <a href='http://gpc.github.com'>Grails Plugin Collective</a>"
}
}
}

grails.views.gsp.encoding = "UTF-8"
4 changes: 4 additions & 0 deletions grails-app/controllers/RenderingController.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ class RenderingController {
renderGif(template: '/datauri')
}

def encodingTest = {
renderPdf(template: "/encoding-test")
}

protected getTemplate() {
[template: '/simple', model: [var: params.id]]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import org.w3c.dom.Document
import grails.plugin.rendering.datauri.DataUriAwareITextUserAgent

import org.springframework.util.ReflectionUtils
import com.lowagie.text.pdf.BaseFont

class PdfRenderingService extends RenderingService {

Expand Down
51 changes: 51 additions & 0 deletions grails-app/views/_encoding-test.gsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3c.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3c.org/1999/xhtml" xml:lang="pl" lang="pl">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title> Osobowość </title>
<style type="text/css" >
@font-face {
src: url(http://localhost:8080/grails-rendering/fonts/arial.ttf);
-fs-pdf-font-embed: embed;
-fs-pdf-font-encoding: cp1250;
}
@page {
size: 210mm 297mm;
}
body {
font-weight: bold;
font-family: "Arial Unicode MS", Arial, sans-serif;
font-size:18px;
width: 400px;
color: black;
background-color: white;
margin: 0px;
padding-top: 0px;
text-align: center;
}
p {
margin: 0px;
padding: 0px;
}
</style>
</head>
<body>
<p id="wnioskodawca">
¨ü¨¨ü¨¨ü¨¨üüøo łłłłłasdfasdfłłł
Numer Identyfikacyjny:
Nazwa / Nazwisko:
Pierwsze Imię:
Drugie Imię:
Obywatelstwo:
Płeć:
Data Urodzenia:
PESEL:
REGON:
Dowód tożsamości:
NIP:
KRS:
</p>
</body>
</html>
18 changes: 18 additions & 0 deletions src/docs/guide/8. Exotic Characters.gdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
In most cases, there are no issues with dealing with exotic Unicode characters. However, certain characters will not render in PDF documents without some extra work (the same problem does not exist when rendering images). This is a quirk with the way iText works, which is the library underpinning the PDF generation.

This "thread":http://www.mail-archive.com/itext-questions@lists.sourceforge.net/msg48788.html explains the issue.

The solution is to register the font to use with a particular encoding. Because we are using XHTMLRenderer we can specify this in CSS as opposed to programatically registering.

{code}
@font-face {
src: url(path/to/arial.ttf);
-fs-pdf-font-embed: embed;
-fs-pdf-font-encoding: cp1250;
}
body {
font-family: "Arial Unicode MS", Arial, sans-serif;
}
{code}

See "this page":http://pigeonholdings.com/projects/flyingsaucer/R8/doc/guide/users-guide-R8.html#xil_44 for details on these CSS directives.
Binary file added web-app/fonts/arial.ttf
Binary file not shown.

0 comments on commit ad837ac

Please sign in to comment.