Cześć.
Mam pytanie czy wie ktoś może jak ustawić w bibliotece :
https://github.com/rek72/tableExport
aby eksportowała do pdf polskie znaki ?
packagist.org github.com
Ustaw w bibliotece charset na UTF-8. Ponadto plik do którego eksportujesz, czyli ten który ma zostać utworzony też raczej musi być zapisany w UTF-8.
Export wygląda tak ,że mam zbudowaną tabele.I po id tabeli pobieram wszystkie wartości i generuje.Dla przykładu korzystam z tej samej biblioteki do generowania excela.I w Excelu widzi polskie znaki.
Tak exportuje:
function exportPDF(){ $('#dt').tableExport({type:'pdf', jspdf: {orientation: 'l', format: 'a4', margins: {left:0, right:0, top:20, bottom:20}, autotable: {styles: {fillColor: 'inherit', textColor: 'inherit'}, tableWidth: 'auto'} } }); }
Pliki konfiguracyjny:
var defaults = { csvEnclosure: '"', csvSeparator: ',', csvUseBOM: true, displayTableName: false, escape: false, exportHiddenCells: false, // true = speed up export of large tables with hidden cells (hidden cells will be exported !) fileName: 'tableExport', htmlContent: false, ignoreColumn: [], ignoreRow: [], jsonScope: 'all', // head, data, all jspdf: { // jsPDF / jsPDF-AutoTable related options orientation: 'p', unit: 'pt', format: 'a4', // One of jsPDF page formats or 'bestfit' for autmatic paper format selection margins: {left: 0, right: 0, top: 10, bottom: 10}, onDocCreated: null, autotable: { styles: { cellPadding: 6, rowHeight: 12, fontSize: 7, fillColor: 255, // Color value or 'inherit' to use css background-color from html table textColor: 50, // Color value or 'inherit' to use css color from html table fontStyle: 'normal', // normal, bold, italic, bolditalic or 'inherit' to use css font-weight and fonst-style from html table overflow: 'ellipsize', // visible, hidden, ellipsize or linebreak halign: 'inherit', // left, center, right or 'inherit' to use css horizontal cell alignment from html table valign: 'middle' // top, middle, bottom }, headerStyles: { fillColor: [52, 73, 94], textColor: 255, fontStyle: 'bold', halign: 'inherit', // left, center, right or 'inherit' to use css horizontal header cell alignment from html table valign: 'middle' // top, middle, bottom }, alternateRowStyles: { fillColor: 245 }, tableExport: { doc: null, // jsPDF doc object. If set, an already created doc will be used to export to onAfterAutotable: true, onBeforeAutotable: true, onAutotableText: true, onTable: true, outputImages: true } } }, mso: { // MS Excel and MS Word related options fileFormat: 'xlshtml', // xlshtml = Excel 2000 html format // xmlss = XML Spreadsheet 2003 file format (XMLSS) // xlsx = Excel 2007 Office Open XML format onMsoNumberFormat: null, // Excel 2000 html format only. See readme.md for more information about msonumberformat pageFormat: 'a4', // Page format used for page orientation pageOrientation: 'portrait', // portrait, landscape (xlshtml format only) rtl: false, // true = Set worksheet option 'DisplayRightToLeft' styles: [], // E.g. ['border-bottom', 'border-top', 'border-left', 'border-right'] worksheetName: '' }, numbers: { html: { decimalMark: '.', thousandsSeparator: ',' }, output: { // Use 'output: false' to keep number format in exported output decimalMark: '.', thousandsSeparator: ',' } }, onAfterSaveToFile: null, onBeforeSaveToFile: null, // Return false as result to abort save process onCellData: null, onCellHtmlData: null, onIgnoreRow: null, // onIgnoreRow($tr, rowIndex): function should return true to not export a row outputMode: 'file', // 'file', 'string', 'base64' or 'window' (experimental) pdfmake: { enabled: false, // true: use pdfmake instead of jspdf and jspdf-autotable (experimental) docDefinition: { pageOrientation: 'portrait', // 'portrait' or 'landscape' defaultStyle: { font: 'Roboto' // Default is 'Roboto', for arabic font set this option to 'Mirza' and include mirza_fonts.js } }, fonts: {} }, preserve: { leadingWS: false, // preserve leading white spaces trailingWS: false // preserve trailing white spaces }, preventInjection: true, // Prepend a single quote to cell strings that start with =,+,- or @ to prevent formula injection sql: { tableEnclosure: '`', // If table or column names contain any characters except letters, numbers, and columnEnclosure: '`' // underscores usually the name must be delimited by enclosing it in back quotes (`) }, tbodySelector: 'tr', tfootSelector: 'tr', // Set empty ('') to prevent export of tfoot rows theadSelector: 'tr', tableName: 'Table', type: 'csv' // 'csv', 'tsv', 'txt', 'sql', 'json', 'xml', 'excel', 'doc', 'png' or 'pdf' }; var pageFormats = { // Size in pt of various paper formats. Adopted from jsPDF. 'a0': [2383.94, 3370.39], 'a1': [1683.78, 2383.94], 'a2': [1190.55, 1683.78], 'a3': [841.89, 1190.55], 'a4': [595.28, 841.89], 'a5': [419.53, 595.28], 'a6': [297.64, 419.53], 'a7': [209.76, 297.64], 'a8': [147.40, 209.76], 'a9': [104.88, 147.40], 'a10': [73.70, 104.88], 'b0': [2834.65, 4008.19], 'b1': [2004.09, 2834.65], 'b2': [1417.32, 2004.09], 'b3': [1000.63, 1417.32], 'b4': [708.66, 1000.63], 'b5': [498.90, 708.66], 'b6': [354.33, 498.90], 'b7': [249.45, 354.33], 'b8': [175.75, 249.45], 'b9': [124.72, 175.75], 'b10': [87.87, 124.72], 'c0': [2599.37, 3676.54], 'c1': [1836.85, 2599.37], 'c2': [1298.27, 1836.85], 'c3': [918.43, 1298.27], 'c4': [649.13, 918.43], 'c5': [459.21, 649.13], 'c6': [323.15, 459.21], 'c7': [229.61, 323.15], 'c8': [161.57, 229.61], 'c9': [113.39, 161.57], 'c10': [79.37, 113.39], 'dl': [311.81, 623.62], 'letter': [612, 792], 'government-letter': [576, 756], 'legal': [612, 1008], 'junior-legal': [576, 360], 'ledger': [1224, 792], 'tabloid': [792, 1224], 'credit-card': [153, 243] }; var FONT_ROW_RATIO = 1.15; var el = this; var DownloadEvt = null; var $hrows = []; var $rows = []; var rowIndex = 0; var trData = ''; var colNames = []; var ranges = []; var blob; var $hiddenTableElements = []; var checkCellVisibilty = false; $.extend(true, defaults, options);
superuser.com Plik z którego eksportujesz zapisz w kodowaniu UTF-8 bez BOM i plik .pdf też w tym kodowaniu.
W pliku konfiguracyjnym tej biblioteki ustaw kodowanie bez BOM oraz kodowanie na UTF-8. Posprawdzaj całą konfigurację. Zmień może to csvUseBOM: true na false. Ogólnie to podaj wersję tego, bo może ta którą masz nie obsługuje tego, co byś chciał.
Może czcionka nie obsługuje UTF-8, zmień na inną i sprawdź.
pdfmake: { enabled: false, // ...
Powyższą linię zmień na
pdfmake: { enabled: true, // ...
website website
Przyznam szczyrze ,że nie za bardzo rozumiem ,ale po zmianie tej wartość dostałem takie błędy :
pdfmake.min.js:8 Uncaught File 'Roboto-Regular.ttf' not found in virtual file system r.readFileSync @ pdfmake.min.js:8 gt.openSync @ pdfmake.min.js:11 t.open @ pdfmake.min.js:11 font @ pdfmake.min.js:11 i.provideFont @ pdfmake.min.js:5 (anonymous) @ pdfmake.min.js:5 c @ pdfmake.min.js:5 r.buildInlines @ pdfmake.min.js:5 r.measureLeaf @ pdfmake.min.js:5 (anonymous) @ pdfmake.min.js:5 n.auto @ pdfmake.min.js:6 r.measureNode @ pdfmake.min.js:5 (anonymous) @ pdfmake.min.js:5 n.auto @ pdfmake.min.js:6 r.measureTable @ pdfmake.min.js:5 (anonymous) @ pdfmake.min.js:5 n.auto @ pdfmake.min.js:6 r.measureNode @ pdfmake.min.js:5 r.measureVerticalContainer @ pdfmake.min.js:5 (anonymous) @ pdfmake.min.js:5 n.auto @ pdfmake.min.js:6 r.measureNode @ pdfmake.min.js:5 r.measureDocument @ pdfmake.min.js:5 i.tryLayoutDocument @ pdfmake.min.js:5 i.layoutDocument @ pdfmake.min.js:5 r.createPdfKitDocument @ pdfmake.min.js:2 r._createDoc @ pdfmake.min.js:2 r.getBuffer @ pdfmake.min.js:2 $.fn.tableExport @ tableExport.js:950 exportPDF @ generator.js:409 onclick @ basic:251
Chociaż wszystkie biblioteki mam podpięte i prawidłowo się pobierają każda ma status 200
Tutaj masz podane jak włączyć do Excela. Wykorzystaj spróbuj dodać kodowanie UTF-8 do PDF'a.
93,628 zapytań
142,551 odpowiedzi
323,052 komentarzy
63,134 pasjonatów
Top 15 użytkowników
Motyw:
Pajacyk od wielu lat dożywia dzieci. Pomóż klikając w zielony brzuszek na stronie. Dziękujemy! ♡
Oto polecana książka warta uwagi.Pełną listę książek znajdziesz tutaj