• Resolved chicodarave

    (@chicodarave)


    Hello.
    I’m trying to load a custom font for my pdf but all I have tried has not worked, the only thing that has worked is using a local font, but if I uninstall it from my PC it does not work anymore, this means it is not loading the font.
    Below is the code I’m using following the directions from the developer site.
    It is a localhost install, I have put the full URL to avoid any addressing problem, I have tested the URL and it offers the file as download, so the URL is ok.
    What I’m doing wrong?
    Any help is appreciated.
    Thank you.

    @font-face {
    font-family: ‘CDB’;
    font-style: normal;
    font-weight: normal;
    src: local(‘CDB’), url(https://127.0.0.1/fonts/cdb.ttf) format(‘truetype’);
    }

    td.postcode {
    font-family: “CDB”;
    font-size: 25pt;
    }

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Contributor Ewout

    (@pomegranate)

    Hi! You can find more information in the documentation regarding this subject: Using custom fonts. It’s better to use server paths than URLS because not all servers allow fetching ‘external’ resources via http, even when ‘external’ is actually on the same server.

    Ewout

    Thread Starter chicodarave

    (@chicodarave)

    Hello Ewout.

    I followed the information on that document right on first time but still cant get it to work.
    I have tried both server paths and directly URL with no success.

    Plugin Contributor Ewout

    (@pomegranate)

    What’s the exact CSS you used when using server paths, and the exact location of the TTF file?
    Note that the documentation example assumes the TTF files are in a /fonts folder inside the template folder (your URL shows the file in the site root /fonts folder, this would require different code).

    Ewout

    Thread Starter chicodarave

    (@chicodarave)

    @font-face {
    font-family: ‘CDB’;
    font-style: normal;
    font-weight: normal;
    src: local(‘CDB’), url(?php echo $this->get_template_path(); ?>/fonts/cdb.ttf) format(‘truetype’);
    }

    I have two copies to test.
    One in root/fonts/
    other in template/fonts/

    I have tried putting it in template root too, nothing works.

    Plugin Contributor Ewout

    (@pomegranate)

    I just re-read your first post where it says “the only thing that has worked is using a local font, but if I uninstall it from my PC it does not work anymore, this means it is not loading the font.”

    This makes me suspect that you are testing this in HTML output – is that possible? PDF files normally do not read from the system fonts.
    When using fonts in the invoice, you will need to test in PDF output because HTML output does not utilize server paths or TTF files.

    Let me know if that’s indeed the case!

    Also, you could try clearing the fonts folder on wp-content/uploads/wpo_wcpdf/ to make sure there is no old/corrupted version from a previous attempt there.

    Ewout

    Thread Starter chicodarave

    (@chicodarave)

    Yes, this is correct, I’m using HTML input, it is ok for, faster and easier to debug, but I teste with PDF output and it does not work too.
    I’m near to give up ??

    I also cleared the fonts folder as you said, after generating the PDF some files appeared back there, also a file called: “cc025cf1ce3260ae61e857a8e7ba42f9.ttf”, I have opened it and it really is the font I’m trying to use.
    It is the only TTF file in the folder.
    PS: The file just appears there when I use the full path in CSS, using the PHP code it does not appear, both PDF and HTML mode.

    Plugin Contributor Ewout

    (@pomegranate)

    Hi! That explains part of the issue – I guess it may have been working in your first attempts, you were just looking at the wrong result.

    Since that new ttf file is now appearing, it means that it is correctly loading the font. What worries me is that it is the only TTF in the folder… Is that the wp-content/uploads/wpo_wcpdf/fonts folder? Are there no other files there?

    For one last try, I would recommend the following:

    1. Reinstall fonts, using the button from the Status tab – check that indeed all the font files are in wp-content/uploads/wpo_wcpdf/fonts.
    2. Use the following CSS:
      
      @font-face {
      	font-family: 'CDB';
      	font-style: normal;
      	font-weight: normal;
      	src: local('CDB'), url(?php echo $this->get_template_path(); ?>/fonts/cdb.ttf) format('truetype');
      }
      
    3. Make sure that the font cdb.ttf is in your custom template folder in /fonts/cdb.ttf
    4. Make sure that you have enabled the custom font as body font:
      
      body {
          font-family: 'CDB';
      }
      

    Let me know if that helps!
    Ewout

    Thread Starter chicodarave

    (@chicodarave)

    Hello Ewout.

    I have removed the “local” from CSS.

    With PDF output:
    -With full font path: 6 files are created – 4 php + 1 ttf + 1 ufm
    -With php path: 3 php files are created.

    With HTML output:
    -With full font path: Nothing is created.
    -With php path: Nothing is created.

    (I have cleared the folder at every try).
    Font not shown in any of the tries.

    I will not use as body font, I will use as a td font:
    td.postcode {
    font-family: “CDB”;
    font-size: 25pt;
    }
    I Set as body font (just to try), does not work too.

    After reinstalling the fonts there are 84 files in the fonts folder, but still not working.

    Ewout, you’re a thoughtful guy and you seem to really want to help, thank you for that, but unfortunately something is not letting this work, I’m sorry ??

    Plugin Contributor Ewout

    (@pomegranate)

    Hi! Let’s give this one more shot – can you zip up your custom template including the fonts etc and email it to [email protected]? Then I’ll take a look at this for you to see if I can spot what’s wrong. For one thing, this seems to be the correct method:

    With full font path: 6 files are created – 4 php + 1 ttf + 1 ufm

    Ewout

    Plugin Contributor Ewout

    (@pomegranate)

    Fixed! There was a typo in my example above (my bad), even though the documentation was correct. The td.postcode used was also not present in the invoice. So I guess it was just Murphy’s law playing up… First unknowingly testing HTML output instead of PDF, then because it didn’t work testing with URLs instead of paths, then using a class that didn’t exist and finally me giving an example with a typo… That’s just bad luck and I even added to it. But it works now ??

    CSS:

    
    @font-face {
    	font-family: 'CDB';
    	font-style: normal;
    	font-weight: normal;
    	src: local('CDB'), url(<?php echo $this->get_template_path(); ?>/fonts/cdb.ttf) format('truetype');
    }
    
    .postcode {
    	font-size: 25pt;
    	font-family: "CDB";
    }
    

    PHP in invoice.php:

    
    <div class="postcode">Custom font</div>
    

    Ewout

    Thread Starter chicodarave

    (@chicodarave)

    Problem is solved!
    It was a “train” of small errors, but Ewout is very kind and gentle and helped out.

    Thank you very much.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Loadong font’ is closed to new replies.