1
  1. Why he generate the PDF again and again when nothing changes? Is there a hidden option for that?
  2. I tried to use it with the Google Font Rubik but no chance. Any Ideas?
  3. Is it possible to Save the generated PDF in an Asset field to the Post?

I've a preparse Field at the Moment but I've nothing what I can prompt if it's exist or not. He also regenerate the PDF on every Save. No cool :/

Here is my Preparse Field

{% spaceless %}
  {% if not entry.preparsePrintmakerCertificate|length %}
    {% set html %}
      <html>
      <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
        <style>
          @page {
            margin: 0in;
          }

          @font-face {
            font-family: 'Rubik Webfont';
            src: url('/assets/fonts/Rubik-Black.ttf') format('truetype');
            font-weight: 900;
            font-style: normal;
          }

          body {
            font-family: "Rubik Webfont", sans-serif;
            font-weight: 900;
            margin: 0;
            padding: 0;
            font-size: 160px;
            line-height: 1;
            width: 100%;
            height: 100%;
            position: relative;
            color: #2e3743;
            text-transform: uppercase;
            letter-spacing: -6px;
            background-image: url('/assets/images/bitmap/printmaker/certificate_background.png');
          }

          .background {
            position: fixed;
            width: 100%;
            height: 100%;
            left: 0;
            right: 0;
            top: 0;
            bottom: 0;
          }

          .name {
            position: fixed;
            width: 1000px;
            left: 356px;
            top: 2764px;
          }

          .date {
            position: fixed;
            width: 900px;
            left: 356px;
            top: 4318px;
          }
        </style>
      </head>
      <body>
      <div class="background">
        <div class="name">
          {{ entry.title }}
        </div>
        <div class="date">
          <span class="month">{{ entry.postDate.format('M') }}</span>
          <span class="day">{{ entry.postDate.format('d') }}</span><br/>
          <span class="year">{{ entry.postDate.format('Y') }}</span>
        </div>
      </div>
      </body>
      </html>
    {% endset %}

    {% set settings = {
        filename : 'bestwebsite-gallery_sotd_' ~ entry.postDate.format('Y-m-d') ~ '_' ~ entry.slug|kebab
    } %}
    {% set pdfUrl = craft.printmaker.pdfFromHtml(html, settings).url %}
    {{ pdfUrl }}
  {% endif %}
{% endspaceless %}
  • 3
    Howdy David — Thanks for these questions! In the future, please try to ask only one question per SE post. (Questions are easier to search that way, which makes the answers more accessible to others in the future.) – Michael Rog Jan 16 '17 at 2:34
3
  1. Unfortunately, Printmaker must regenerate the PDF on every save... It can’t simply check to see whether a certain PDF file already exists, because the underlying content or template may have changed that PDF was last generated. You can use Craft's template caching to capture PDF URLs/filenames, to avoid unnecessarily generating the PDF if you know the underlying content hasn't changed.

  2. You can use Google Fonts (or any other external web font) by linking an external stylesheet, or by including the @font-face directive in your inline styles.

  3. Printmaker saves PDF to files in a cache directory that you specify, but it doesn't create or update an Asset element. You could write a custom plugin to do that, leveraging Printmaker's API. Alternatively, you can commission Top Shelf Craft to develop the functionality you need.

Feel free to write support@topshelfcraft.com or post additional questions here on SE if I can be of further help!

  • Hm OK, So, it's a bit useless for me. You're right, the Content can changed but a simple option to generate this file one time would be, hm nice? :) And what you mean with caching? `{% cache %} Tag? I don't know how if I can cache this with this Tag. Hm. Overall… the plugin does what I need but I'm not happy 100% and I can't launch now (PHP7 Bug in Dom PDF, wrote you an email about that). – davidhellmann Jan 31 '17 at 19:38
  • 1
    Actually, that's not a bad idea: I could add an overwrite param to tell Printmaker not to bother regenerating a file if it already exists. Also, as you've discovered, you can use a Preparse field to store the URL to a PDF. Meanwhile, trying to resolve that PHP 7.1 issue for you. :-) – Michael Rog Jan 31 '17 at 20:33
  • Yeah I use preparse and it works fine. To store it in a field after generating would be yet better. But I know, it's not the use case most of the time. But thanks anyway :) – davidhellmann Feb 7 '17 at 8:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.