<p>Craft Commerce 1.x uses the Dompdf package to generate PDFs.</p>

<p>The issue is likely a font cache issue, Dompdf caches an index about all fonts. Removing the cache indexes should fix the issue. Remove:</p>

<p><code>craft/plugins/commerce/vendor/dompdf/dompdf/lib/fonts/dompdf_font_family_cache.php</code></p>

<p>This is as mentioned in the migration guide and occurs because Craft Commerce has gone from Dompdf 0.6 to 0.8:</p>

<p><a href="https://github.com/dompdf/dompdf/wiki/Migration-Guide" rel="nofollow noreferrer">https://github.com/dompdf/dompdf/wiki/Migration-Guide</a></p>

<blockquote>
  <p>The class naming conventions required a change to the dompdf_font_family_cache.php file. Though we have attempted to accommodate this change your first step when encountering bugs (if you don't know where to start) might be to reset your font directory (i.e. remove custom font files and the related font metrics files, and remove the non-dist, generated, font family cache file).</p>
</blockquote>

<p>First try removing the <code>dompdf_font_family_cache.php</code> as mentioned above. If that doesn't work try removing all files they list above from the same folder. I think that includes all <code>.afm</code>. The directory should end up looking something like the original: <a href="https://github.com/dompdf/dompdf/tree/master/lib/fonts" rel="nofollow noreferrer">https://github.com/dompdf/dompdf/tree/master/lib/fonts</a></p>

CC BY-SA 3.0
2017-05-30T01:32:22.243Z
2017-05-30T02:34:15.703Z
2017-05-30T02:34:15.703Z
Luke Holder
<p>I am getting an error when trying to generate a PDF in Craft Commerce.</p>

<p>The error is:</p>

<blockquote>
  <p>Undefined index: (/srv/data/web/vhosts/www.nihonshu-sake.lu/craft/plugins/commerce/vendor/dompdf/dompdf/lib/Cpdf.php:3855)
  $font = $this->fonts[$this->currentFont];</p>
</blockquote>

<plugin-craftcommerce><error-message>
Error when trying to generate a PDF in Craft Commerce
# Error when trying to generate a PDF in Craft Commerce

(Asked by: username_0 on 2017-05-30)

I am getting an error when trying to generate a PDF in Craft Commerce.

The error is:

> Undefined index: (/srv/data/web/vhosts/www.nihonshu-sake.lu/craft/plugins/commerce/vendor/dompdf/dompdf/lib/Cpdf.php:3855)
> $font = $this->fonts[$this->currentFont];

**Tags:** plugin-craftcommerce, error-message

---

## 1 answers

### Answer by username_0 on 2017-05-30. Score: 2

Craft Commerce 1.x uses the Dompdf package to generate PDFs.

The issue is likely a font cache issue, Dompdf caches an index about all fonts. Removing the cache indexes should fix the issue. Remove:

`craft/plugins/commerce/vendor/dompdf/dompdf/lib/fonts/dompdf_font_family_cache.php`

This is as mentioned in the migration guide and occurs because Craft Commerce has gone from Dompdf 0.6 to 0.8:

<https://github.com/dompdf/dompdf/wiki/Migration-Guide>

> The class naming conventions required a change to the dompdf\_font\_family\_cache.php file. Though we have attempted to accommodate this change your first step when encountering bugs (if you don't know where to start) might be to reset your font directory (i.e. remove custom font files and the related font metrics files, and remove the non-dist, generated, font family cache file).

First try removing the `dompdf_font_family_cache.php` as mentioned above. If that doesn't work try removing all files they list above from the same folder. I think that includes all `.afm`. The directory should end up looking something like the original: <https://github.com/dompdf/dompdf/tree/master/lib/fonts>


---

