문제

I want to export some table in HTML to PDF file using jquery. So far I can use Ngiriraj to export to PDF but it can't encode Japanese character

Here is example

So please help me to find the way to encode Japanese

When I use "全体デザイン", it show "全体デザイン"

Thank you.

HTML

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
<script type="text/javascript" src="jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="tableExport.js"></script>
<script type="text/javascript" src="jquery.base64.js"></script>
<script type="text/javascript" src="html2canvas.js"></script>
<script type="text/javascript" src="sprintf.js"></script>
<script type="text/javascript" src="jspdf.js"></script>
<script type="text/javascript" src="base64.js"></script>

<table id="nation">
<thead>         
    <tr class='warning'>
        <th>Nation</th>
        <th>Population</th>
        <th>Date</th>
        <th>%ge</th>
    </tr>
</thead>
<tbody>
    <tr>
        <td>中国</td>
        <td>1,363,480,000</td>
        <td>March 24, 2014</td>
        <td>19.1</td>
    </tr>
    <tr>
        <td>日本</td>
        <td>249,866,000</td>
        <td>July 1, 2013</td>
        <td>3.49</td>
    </tr>
</tbody>
</table>

The PDF

Nation Population    Date           %ge
ä¸-国 1,363,480,000 March 24, 2014 19.1
日本 249,866,000   July 1, 2013   3.49
도움이 되었습니까?

해결책 2

It took me some time to reproduce the problem. Here is the minimal HTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

    <!-- jQuery 2.0.2 -->
    <script type="application/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>

    <script type="application/javascript" src="tableExport.js"></script>
    <script type="application/javascript" src="jquery.base64.js"></script>
    <script type="application/javascript" src="jspdf/libs/sprintf.js"></script>
    <script type="application/javascript" src="jspdf/jspdf.js"></script>
    <script type="application/javascript" src="jspdf/libs/base64.js"></script>
</head>

<body>
    <table id="nation">
        <tbody>
            <tr>
                <td>
                    中国
                </td>
             </tr>
        </tbody>
    </table>
    <a href="#" onclick ="$('#nation').tableExport({type:'pdf',escape:'false'});">PDF</a>
</body>
</html>

Here is the complete folder (including the js) so you can test locally: http://bit.ly/1fW0YbX.

If you look at the generated PDF, it only uses the standard PDF font Helvetica which supports the Latin-1 character set only. This is why you do not see the expected Japanese glyphs. I couldn't find any related option for the HTML table export jquery plugin so I guess it just isn't supported. But maybe I am missing a localization plugin.

다른 팁

Simply put, character encoding denotes how characters—letters, digits and other symbols—are represented as bits and bytes for storage and communication. The HTTP request header Accept-Charset can be used by a client to indicate how the response message can be encoded.

use utf-16 for encoding

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top