简体   繁体   English

日语的HTML到PDF

[英]HTML to PDF with Japanese

I want to export some table in HTML to PDF file using jquery. 我想使用jquery将HTML中的某些表导出为PDF文件。 So far I can use Ngiriraj to export to PDF but it can't encode Japanese character 到目前为止,我可以使用Ngiriraj导出为PDF,但是它不能对日语字符进行编码

Here is example 这是例子

So please help me to find the way to encode Japanese 所以请帮我找到编码日语的方法

When I use "全体デザイン", it show "全体デザイン" 当我使用"全体デザイン", it show "全体デザイン"

Thank you. 谢谢。

HTML 的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 PDF文件

Nation Population    Date           %ge
ä¸-国 1,363,480,000 March 24, 2014 19.1
日本 249,866,000   July 1, 2013   3.49

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. 客户端可以使用HTTP请求标头Accept-Charset指示如何对响应消息进行编码。

use utf-16 for encoding 使用utf-16进行编码

It took me some time to reproduce the problem. 我花了一些时间重现该问题。 Here is the minimal HTML: 这是最小的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 . 这是完整的文件夹(包括js),因此您可以在本地进行测试: 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. 如果查看生成的PDF,它将仅使用标准PDF字体Helvetica,该字体仅支持Latin-1字符集。 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. 我找不到HTML表格导出jquery插件的任何相关选项,所以我猜它只是不受支持。 But maybe I am missing a localization plugin. 但是也许我缺少本地化插件。

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

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