2017-08-29 133 views
-1

我使用指定代码到HTML页面导出为PDF通过使用drawDom方法:导出到使用剑道UI(与RTL语言问题)PDF

$(function(){ 
     $('#ExportToPdf').on("click", function (e) { 
      var selectedTab = $('.selected-tab').attr("id"); 
      selectedTab = selectedTab.replace("tab-", "#"); 
      var fileName = $(selectedTab).find($('.report-title')).text().replace(' ', '_'); 
      kendo.drawing.drawDOM($(selectedTab)) 
      .then(function (group) { 
       // Render the result as a PDF file 
       return kendo.drawing.exportPDF(group, { 
        paperSize: "auto", 
        margin: { left: "1cm", top: "1cm", right: "1cm", bottom: "1cm" } 
       }); 
      }) 
      .done(function (data) { 
       // Save the PDF file 
       kendo.saveAs({ 
        dataURI: data, 
        fileName: fileName + ".pdf" 
       }); 
      }); 
     }); 
    }); 

但结果下面给出了阿拉伯字符 enter image description here

我想这样的结果:

enter image description here

我想每一件事是我所得到的INTE RNET。

为unicode和kendo内建字体添加不同类型的字体,但都是静态的。

+0

你有没有试过改''​​的样式?在我看来,css prop'letter-spacing'是问题所在,尝试将其设置为1px;'如果您使用自定义字体,是否使用'kendo.pdf.defineFont'方法定义了它们? – Drops

+0

我刚刚尝试过,但没有工作 –

+0

很高兴您在互联网上除了Kendo文档之外都尝试了这一切。它说:不支持从右到左的文本。此外这是一个重复的问题:https://stackoverflow.com/questions/39488786/kendo-pdf-export-issue-for-rtl-languages – Drops

回答

0

这里是KENDO用户界面教程,它适用于我。你可以通过分析这段代码来重写你的代码吗?如果问题仍然存在,那么我们会尝试再次找到解决方案。

<script> 
 
    // Import DejaVu Sans font for embedding 
 

 
    // NOTE: Only required if the Kendo UI stylesheets are loaded 
 
    // from a different origin, e.g. cdn.kendostatic.com 
 
    kendo.pdf.defineFont({ 
 
     "DejaVu Sans"    : "https://kendo.cdn.telerik.com/2016.2.607/styles/fonts/DejaVu/DejaVuSans.ttf", 
 
     "DejaVu Sans|Bold"  : "https://kendo.cdn.telerik.com/2016.2.607/styles/fonts/DejaVu/DejaVuSans-Bold.ttf", 
 
     "DejaVu Sans|Bold|Italic" : "https://kendo.cdn.telerik.com/2016.2.607/styles/fonts/DejaVu/DejaVuSans-Oblique.ttf", 
 
     "DejaVu Sans|Italic"  : "https://kendo.cdn.telerik.com/2016.2.607/styles/fonts/DejaVu/DejaVuSans-Oblique.ttf", 
 
     "WebComponentsIcons"  : "https://kendo.cdn.telerik.com/2017.1.223/styles/fonts/glyphs/WebComponentsIcons.ttf" 
 
    }); 
 
</script> 
 

 
<!-- Load Pako ZLIB library to enable PDF compression --> 
 
<script src="https://kendo.cdn.telerik.com/2017.2.621/js/pako_deflate.min.js"></script> 
 

 
<script> 
 
$(document).ready(function() { 
 

 
    $(".export-pdf").click(function() { 
 
     // Convert the DOM element to a drawing using kendo.drawing.drawDOM 
 
     kendo.drawing.drawDOM($(".content-wrapper")) 
 
     .then(function(group) { 
 
      // Render the result as a PDF file 
 
      return kendo.drawing.exportPDF(group, { 
 
       paperSize: "auto", 
 
       margin: { left: "1cm", top: "1cm", right: "1cm", bottom: "1cm" } 
 
      }); 
 
     }) 
 
     .done(function(data) { 
 
      // Save the PDF file 
 
      kendo.saveAs({ 
 
       dataURI: data, 
 
       fileName: "HR-Dashboard.pdf", 
 
       proxyURL: "https://demos.telerik.com/kendo-ui/service/export" 
 
      }); 
 
     }); 
 
    }); 
 

 
    $(".export-img").click(function() { 
 
     // Convert the DOM element to a drawing using kendo.drawing.drawDOM 
 
     kendo.drawing.drawDOM($(".content-wrapper")) 
 
     .then(function(group) { 
 
      // Render the result as a PNG image 
 
      return kendo.drawing.exportImage(group); 
 
     }) 
 
     .done(function(data) { 
 
      // Save the image file 
 
      kendo.saveAs({ 
 
       dataURI: data, 
 
       fileName: "HR-Dashboard.png", 
 
       proxyURL: "https://demos.telerik.com/kendo-ui/service/export" 
 
      }); 
 
     }); 
 
    }); 
 

 
    $(".export-svg").click(function() { 
 
     // Convert the DOM element to a drawing using kendo.drawing.drawDOM 
 
     kendo.drawing.drawDOM($(".content-wrapper")) 
 
     .then(function(group) { 
 
      // Render the result as a SVG document 
 
      return kendo.drawing.exportSVG(group); 
 
     }) 
 
     .done(function(data) { 
 
      // Save the SVG document 
 
      kendo.saveAs({ 
 
       dataURI: data, 
 
       fileName: "HR-Dashboard.svg", 
 
       proxyURL: "https://demos.telerik.com/kendo-ui/service/export" 
 
      }); 
 
     }); 
 
    }); 
 

 

 
    var data = [{ 
 
     "source": "Approved", 
 
     "percentage": 237 
 
    }, { 
 
     "source": "Rejected", 
 
     "percentage": 112 
 
    }]; 
 

 
    var refs = [{ 
 
     "source": "Dev", 
 
     "percentage": 42 
 
    }, { 
 
     "source": "Sales", 
 
     "percentage": 18 
 
    }, { 
 
     "source": "Finance", 
 
     "percentage": 29 
 
    }, { 
 
     "source": "Legal", 
 
     "percentage": 11 
 
    }]; 
 

 
    $("#applications").kendoChart({ 
 
     legend: { 
 
     position: "bottom" 
 
     }, 
 
     dataSource: { 
 
     data: data 
 
     }, 
 
     series: [{ 
 
     type: "donut", 
 
     field: "percentage", 
 
     categoryField: "source" 
 
     }], 
 
     chartArea: { 
 
      background: "none" 
 
     }, 
 
     tooltip: { 
 
     visible: true, 
 
     template: "${ category } - ${ value } applications" 
 
     } 
 
    }); 
 

 
    $("#users").kendoChart({ 
 
     legend: { 
 
      visible: false 
 
     }, 
 
     seriesDefaults: { 
 
      type: "column" 
 
     }, 
 
     series: [{ 
 
      name: "Users Reached", 
 
      data: [340, 894, 1345, 1012, 3043, 2013, 2561, 2018, 2435, 3012] 
 
     }, { 
 
      name: "Applications", 
 
      data: [50, 80, 120, 203, 324, 297, 176, 354, 401, 349] 
 
     }], 
 
     valueAxis: { 
 
      labels: { 
 
       visible: false 
 
      }, 
 
      line: { 
 
       visible: false 
 
      }, 
 
      majorGridLines: { 
 
       visible: false 
 
      } 
 
     }, 
 
     categoryAxis: { 
 
      categories: [2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011], 
 
      line: { 
 
       visible: false 
 
      }, 
 
      majorGridLines: { 
 
       visible: false 
 
      } 
 
     }, 
 
     chartArea: { 
 
      background: "none" 
 
     }, 
 
     tooltip: { 
 
      visible: true, 
 
      format: "{0}", 
 
      template: "#= series.name #: #= value #" 
 
     } 
 
    }); 
 

 
    $("#referrals").kendoChart({ 
 
     legend: { 
 
     position: "bottom" 
 
     }, 
 
     dataSource: { 
 
     data: refs 
 
     }, 
 
     series: [{ 
 
     type: "pie", 
 
     field: "percentage", 
 
     categoryField: "source" 
 
     }], 
 
     chartArea: { 
 
      background: "none" 
 
     }, 
 
     tooltip: { 
 
     visible: true, 
 
     template: "${ category } - ${ value }%" 
 
     } 
 
    }); 
 

 
    $("#grid").kendoGrid({ 
 
     dataSource: { 
 
     type: "odata", 
 
     transport: { 
 
      read: "https://demos.telerik.com/kendo-ui/service/Northwind.svc/Customers" 
 
     }, 
 
     pageSize: 15, 
 
     group: { field: "ContactTitle" } 
 
     }, 
 
     height: 450, 
 
     groupable: true, 
 
     sortable: true, 
 
     selectable: "multiple", 
 
     reorderable: true, 
 
     resizable: true, 
 
     filterable: true, 
 
     pageable: { 
 
     refresh: true, 
 
     pageSizes: true, 
 
     buttonCount: 5 
 
     }, 
 
     columns: [ 
 
     { 
 
      field: "ContactName", 
 
      template: "<div class=\'customer-name\'>#: ContactName #</div>", 
 
      title: "Contact", 
 
      width: 200 
 
     },{ 
 
      field: "ContactTitle", 
 
      title: "Contact Title", 
 
      width: 220 
 
     },{ 
 
      field: "Phone", 
 
      title: "Phone", 
 
      width: 160 
 
     },{ 
 
      field: "CompanyName", 
 
      title: "Company Name" 
 
     },{ 
 
      field: "City", 
 
      title: "City", 
 
      width: 160 
 
     } 
 
     ] 
 
    }); 
 
    }); 
 
</script>
<style> 
 
    /* 
 
     Use the DejaVu Sans font for display and embedding in the PDF file. 
 
     The standard PDF fonts have no support for Unicode characters. 
 
    */ 
 
    .k-widget { 
 
     font-family: "DejaVu Sans", "Arial", sans-serif; 
 
     font-size: .9em; 
 
    } 
 
</style> 
 

 
<style> 
 
.export-app { 
 
    display: table; 
 
    width: 100%; 
 
    height: 750px; 
 
    padding: 0; 
 
} 
 

 
.export-app .demo-section { 
 
    margin: 0 auto; 
 
    border: 0; 
 
} 
 

 
.content-wrapper { 
 
    display: table-cell; 
 
    vertical-align: top; 
 
} 
 

 
.charts-wrapper { 
 
    height: 250px; 
 
    padding: 0 0 20px; 
 
} 
 

 
#applications, 
 
#users, 
 
#referrals { 
 
    display: inline-block; 
 
    width: 50%; 
 
    height: 240px; 
 
    vertical-align: top; 
 
} 
 
#applications, 
 
#referrals { 
 
    width: 24%; 
 
    height: 250px; 
 
} 
 

 
.customer-photo { 
 
    display: inline-block; 
 
    width: 40px; 
 
    height: 40px; 
 
    border-radius: 50%; 
 
    background-size: 40px 44px; 
 
    background-position: center center; 
 
    vertical-align: middle; 
 
    line-height: 41px; 
 
    box-shadow: inset 0 0 1px #999, inset 0 0 10px rgba(0,0,0,.2); 
 
} 
 
.customer-name { 
 
    display: inline-block; 
 
    vertical-align: middle; 
 
    line-height: 41px; 
 
    padding-left: 10px; 
 
} 
 
</style>
<!DOCTYPE html> 
 
<html> 
 
<head> 
 
    <base href="https://demos.telerik.com/kendo-ui/pdf-export/index"> 
 
    <style>html { font-size: 14px; font-family: Arial, Helvetica, sans-serif; }</style> 
 
    <title></title> 
 
    <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2017.2.621/styles/kendo.common-material.min.css" /> 
 
    <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2017.2.621/styles/kendo.material.min.css" /> 
 
    <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2017.2.621/styles/kendo.material.mobile.min.css" /> 
 

 
    <script src="https://kendo.cdn.telerik.com/2017.2.621/js/jquery.min.js"></script> 
 
    <script src="https://kendo.cdn.telerik.com/2017.2.621/js/jszip.min.js"></script> 
 
    <script src="https://kendo.cdn.telerik.com/2017.2.621/js/kendo.all.min.js"></script> 
 
</head> 
 
<body> 
 
<div id="example"> 
 
    
 
    <div class="box wide hidden-on-narrow"> 
 
     <h4>Export page content</h4> 
 
     <div class="box-col"> 
 
      <button class='export-pdf k-button'>Export as PDF</button> 
 
     </div> 
 
     <div class="box-col"> 
 
      <button class='export-img k-button'>Export as Image</button> 
 
     </div> 
 
     <div class="box-col"> 
 
      <button class='export-svg k-button'>Export as SVG</button> 
 
     </div> 
 
    </div> 
 

 
    <div class="demo-section k-content export-app wide hidden-on-narrow"> 
 
     <div class="demo-section content-wrapper wide"> 
 
      <div class="demo-section charts-wrapper wide"> 
 
      <div id="users"></div> 
 
      <div id="applications"></div> 
 
      <div id="referrals"></div> 
 
      </div> 
 
      <div id="grid"></div> 
 
     </div> 
 
    </div> 
 
    
 
    <div class="responsive-message"></div> 
 
</div> 
 

 
</body> 
 
</html>

+0

感谢您的帮助,这完全是从Kendo文档复制和粘贴的。我已经尝试过,但没有工作。 –

+0

我只有阿拉伯字符的问题。我可以以正确的格式导出除阿拉伯字符以外的所有内容(图表,网格,html)。 –