datatable pdfmaker export pdf changing font to calibri
datatable pdfmaker export pdf changing font to calibri
 zprofreelancer            
            
                Posts: 4Questions: 0Answers: 0
zprofreelancer            
            
                Posts: 4Questions: 0Answers: 0            
            i'm trying to change roboto font to calibri
i followed pdfmaker documentation and created vfs_fonts.js and replace roboto with calibri in pdfmake.min.js and
here is my datatable configuration:
<script type="text/javascript">
  $(document).ready(function() {
    $('#example').DataTable({
      dom: 'Bfrtip',
      buttons: [{
        extend: 'pdf',
        customize: function ( doc ) {
          processDoc(doc);
        }
      }]
    });
  });
  function processDoc(doc) {
    //
    // https://pdfmake.github.io/docs/fonts/custom-fonts-client-side/
    //
    // Update pdfmake's global font list, using the fonts available in
    // the customized vfs_fonts.js file (do NOT remove the Roboto default):
    pdfMake.fonts = {
      Roboto: {
        normal: 'Roboto-Regular.ttf',
        bold: 'Roboto-Medium.ttf',
        italics: 'Roboto-Italic.ttf',
        bolditalics: 'Roboto-MediumItalic.ttf'
      },
      Calibri: {
               normal: 'calibri.ttf',
               bold: 'calibrib.ttf',
              italics: 'calibrii.ttf"',
               bolditalics: 'calibriz.ttf',
          }
    };
    // modify the PDF to use a different default font:
    doc.defaultStyle.font = "Calibri";
    var i = 1;
  }
</script>
if i change defaultstyle.font = "Roboto" the export is working...if i used calibri, clicking the pdf export button doen't do anything.
Note:
 vfs_fonts.js is included after pdfmake so that's not the problem.
Please help.
Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
Replies
This thread should help, it's asking the same thing.
Cheers,
Colin
Thanks. i already did what's in the thread but it's not working. my datatable is serverside...could this be the problem?
Also, i need to know do i have to put the fonts at a certain path?
You haven't specified
serverSidein your config, so your table will have all the data client-side.In all the examples I've seen, there's only a single object in
pdfMake.fonts. If you only wantCalibri, it would be worth removingRobotoas I'm not sure why that would be needed,Colin
i added serverside option and removed roboto but still no use. please help
Have you loaded your customised vfs_fonts.js file? To be honest, you might be best asking for help from the pdfmake team, as we just hook into their software for the pdf export.
Allan