best way to include google fonts into a pdf?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jamie
    Senior Member
    • Aug 2025
    • 141

    #1

    best way to include google fonts into a pdf?

    Hi there,

    Like most companies, we have an official font, a Google Font. And I’m wondering what the best way is to include this in a PDF. We’ve tried a few plugins without success, and it seems like there should be an option or setting on the PDF object to include external font sources, but it doesn’t appear to exist.

    Any guidance or best practices for embedding a Google Font (especially in Dompdf) would be greatly appreciated.

    Thanks!
  • leon
    Junior Member
    • May 2019
    • 14

    #2
    Hi,

    Just include the correct CSS file in your Pdf Template as mentioned by Google Fonts.

    Example for Bitcount Grid Single font:

    <link href="https://fonts.googleapis.com/css2?family=Bitcount+Grid+Single:wght@100..900&amp ;display=swap" rel="stylesheet">
    <p style="font-family : 'Bitcount Grid Single';">The quick brown fox jumps over the lazy dog?</p>

    Don't forget to change

    private $isRemoteEnabled = false;

    to

    private $isRemoteEnabled = true;

    in /vendor/dompdf/dompdf/src/Options.php


    You should see the downloaded font files in /vendor/dompdf/dompdf/lib/fonts/

    Comment

    • jamie
      Senior Member
      • Aug 2025
      • 141

      #3
      Originally posted by leon
      Hi,

      Just include the correct CSS file in your Pdf Template as mentioned by Google Fonts.

      Example for Bitcount Grid Single font:

      The quick brown fox jumps over the lazy dog?


      Don't forget to change

      private $isRemoteEnabled = false;

      to

      private $isRemoteEnabled = true;

      in /vendor/dompdf/dompdf/src/Options.php


      You should see the downloaded font files in /vendor/dompdf/dompdf/lib/fonts/
      yeah not a bad solution though i traditionally never edit vendor files and ended up using an embedded font instead, has its advantages...

      Comment

      • rabii
        Active Community Member
        • Jun 2016
        • 1342

        #4
        Originally posted by leon
        Hi,

        Just include the correct CSS file in your Pdf Template as mentioned by Google Fonts.

        Example for Bitcount Grid Single font:

        The quick brown fox jumps over the lazy dog?


        Don't forget to change

        private $isRemoteEnabled = false;

        to

        private $isRemoteEnabled = true;

        in /vendor/dompdf/dompdf/src/Options.php


        You should see the downloaded font files in /vendor/dompdf/dompdf/lib/fonts/

        that might open up security issues

        Click image for larger version

Name:	fetch?id=101797&amp;d=1705782033.png
Views:	0
Size:	34.2 KB
ID:	122612
        Rabii
        EspoCRM & Web Dev

        🔗 See what I’ve built for EspoCRM

        Comment

        • jamie
          Senior Member
          • Aug 2025
          • 141

          #5
          Originally posted by rabii


          that might open up security issues

          Click image for larger version

Name:	fetch?id=101797&amp;d=1705782033.png
Views:	0
Size:	34.2 KB
ID:	122612
          o is that why its you have to hack the vendor files to enable it, It would be great to have an ESPo way so i can choose to enable it or not without hacking anything

          and there are plenty of reasons i'd want to include remote files not just for fonts but images, css and more

          Comment

          • rabii
            Active Community Member
            • Jun 2016
            • 1342

            #6
            This is from dompdf repo not from espocrm. I guess that is why it was not exposed as an option on espocrm. Best way is to create a small extension dowload all required fonts - then extend the fontList under pdfengines.json



            then use binding to change how the options are loaded in DomPdfInitialization.php



            and you should bind it so that when the EntityPrinter require the file it will pass yours



            That is how i would go about to keep everything safe-upgrade
            Rabii
            EspoCRM & Web Dev

            🔗 See what I’ve built for EspoCRM

            Comment

            • jamie
              Senior Member
              • Aug 2025
              • 141

              #7
              yes initinaly i was looking at adding in a switch here
              Click image for larger version

Name:	image.png
Views:	0
Size:	24.6 KB
ID:	122618

              The embedded fonts have proven to be the better approach overall.
              I may need to revisit the setup if we ever need to support non-Roman alphabets. Have you had any experience with that? I was surprised to find that Cyrillic isn’t supported by default, given the lead programmer's language of origin

              Comment


              • rabii
                rabii commented
                Editing a comment
                i don't think dompdf support that. i remember in the past i have helped a client with that building an extension that use a different pdf engine called mpdf which supports non-latin languages.
            • jamie
              Senior Member
              • Aug 2025
              • 141

              #8
              rabii i think you just need to set the multi-byte option and have an appropriate font

              Comment

            • jamie
              Senior Member
              • Aug 2025
              • 141

              #9
              that does seem quite complicated, though i notice that Cyrillic isn't there

              Comment

              Working...