datatable pdfmaker export pdf changing font to calibri

datatable pdfmaker export pdf changing font to calibri

zprofreelancerzprofreelancer Posts: 4Questions: 0Answers: 0
edited November 2021 in Buttons

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

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    This thread should help, it's asking the same thing.

    Cheers,

    Colin

  • zprofreelancerzprofreelancer Posts: 4Questions: 0Answers: 0
    edited November 2021

    Thanks. i already did what's in the thread but it's not working. my datatable is serverside...could this be the problem?

  • zprofreelancerzprofreelancer Posts: 4Questions: 0Answers: 0

    Also, i need to know do i have to put the fonts at a certain path?

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    You haven't specified serverSide in 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 want Calibri, it would be worth removing Roboto as I'm not sure why that would be needed,

    Colin

  • zprofreelancerzprofreelancer Posts: 4Questions: 0Answers: 0

    i added serverside option and removed roboto but still no use. please help

  • allanallan Posts: 61,438Questions: 1Answers: 10,052 Site admin

    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

Sign In or Register to comment.