• Resolved muttly

    (@muttly)


    I’m trying to get custom fonts to work on my PDF form. I’ve followed the instructions provided here (https://docs.wpovernight.com/woocommerce-pdf-invoices-packing-slips/using-custom-fonts/) however no matter what changes I make they simply will not load. To prove that they load on my server I wrote a basic file, in the link provided so I know its not a CSS issue.

    I’ve added the very same CSS to the demo file and the style.css from my template. My templaste is an exact copy of “Simple” save for the section where I want text with specfic fonts in place of an image.

    I would appreciate some help.

    The reason for this is I cannot get an image to look good. I’ve tried using gif, jpg, png. I’ve even tried using a svg and a pdf and nothing will give me a clean looking logo. If you can suggest a different way of displaying the logo as sharp (vector based) as the rest of the text that would do also.

    The page I need help with: [log in to see the link]

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

    (@pomegranate)

    Hi! I checked the test.php file from your link, but it has the fonts as a URL rather than a server path. It’s possible that your server has disabled downloading remote files directly from the internet (URLs are always treated as remote/external, even when it’s on the same server), that’s why the documentation uses the template path (which is a server path rather than a URL).
    Note that the <?php echo $this->get_template_path(); ?>/fonts/myfont.ttf bit in the documentation refers to a path within your custom template, i.e. wp-content/themes/flatsome-child/woocommerce/pdf/PretendTickets/fonts/myfont.ttf in your case.

    Let us know if that helps!

    Thread Starter muttly

    (@muttly)

    I’ve made several more attempts with this and while it works fine in the test.php

    It still does not work on the pdf generating file.

    I’ve moved the location of the file linked originally, it is now here.
    https://pretendtickets.com/28n042di0plzc6tv8jqgk9499kf52dmi/wp-content/themes/flatsome-child/woocommerce/pdf/PretendTickets/test.php

    Plugin Contributor Ewout

    (@pomegranate)

    Are the PDF invoice temporary folders writable (WooCommerce > PDF Invoices > Status, “Write Permissions”)?
    If they are, I’m not sure why it doesn’t work because the fonts are now properly written as path. In that case, could you zip the template and sent it to [email protected]?

    Thread Starter muttly

    (@muttly)

    The temp folders are writable.

    To test I’ve also changed “Output to HTML” and the fonts generate correctly there. I have also checked the font files I’m using and they are embedded to PDF. I will forward the template and fonts to the address provided, thank you.

    Plugin Contributor Ewout

    (@pomegranate)

    Thanks for sending that. I checked your source but it used get_cwd() rather than the $this->get_template_path(); as written in the documentation and my previous post. get_cwd() will only write the correct path if you open the PHP file directly , which is not the case when it’s loaded into the PDF library – get_cwd() will then be the /wp-admin folder in most cases.
    I changed it to $this->get_template_path(); in my test environment which succesfully included the fonts.

    This also explains why it showed the correct path when I accessed the file directly from your above link, because in that particular case get_cwd() has the same output as $this->get_template_path();

    Thread Starter muttly

    (@muttly)

    I’ve just tried this and its still not working in pdf mode. When i do it in output to html it works fine.

    Plugin Contributor Ewout

    (@pomegranate)

    how are you calling the PDF exactly?

    Since you mentioned you have done multiple tests I would recommend clearing the wp-content/uploads/wpo_wcpdf folder so that it reinitializes the fonts. One of the attempts may have installed a corrupted font.

    Thread Starter muttly

    (@muttly)

    I cleared the suggested folder and it made no difference.

    I’ve called the pdf 3 different ways.
    1. From the orders page, I’m ticking the order I want to print and selecting “PDF Packing Slip” from the drop down at the top left and click Apply.
    2. From the orders page, I’ve clicked the “PDF Packing Slip” box in the actions box.
    3. In the actual order, I’ve clicked the “PDF Packing Slip” in the right side of the screen.

    All 3 options work when in Output to HTML but not as PDF.

    Plugin Contributor Ewout

    (@pomegranate)

    I’ve called the pdf 3 different ways.

    except all 3 ways will open the packing slip and not the ‘test’ document! Can you copy the contents of test.php to packing-slips.php (of the template you sent us) and replace get_cwd() with $this->get_template_path()?
    You can also change ‘packing-slip’ in the url with ‘test’ to open the test document.

    I checked your packing-slip.php and found what was likely causing it not to work. You put the font-built logo in td.header but in style.css you also put:

    
    td.header {
    	font-family: 'badaboom', sans-serif;
    	font-size: 16pt;
    	font-weight: 700;
    }
    

    But haven’t defined the font source for the 700 font weight (only for normal). I recommend working with the named font-weights instead (normal, bold), as dompdf doesn’t seem to like numeric font-weights.

    When i do it in output to html it works fine.

    Don’t forget that your browser will use your system fonts if it can’t find the remote fonts! It will certainly not be able to read the server path fonts.

    • This reply was modified 6 years, 5 months ago by Ewout. Reason: analysis of packing slip
    Thread Starter muttly

    (@muttly)

    Thank you! Thank you! Thank you!!

    It was the CSS. I removed the section above and it was displaying the fonts correctly. its taken another 30 minutes to get the logo right but its done now. Thank you so much!!

    Plugin Contributor Ewout

    (@pomegranate)

    Very glad to hear that solved it… quite the puzzle ??
    If you can spare a minute of your time, I’d really appreciate it if you could leave a plugin review here on www.ads-software.com.

    Thanks in advance and have a fantastic day!

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Custom Fonts Not Working’ is closed to new replies.