cooltronicpl / Craft-document-helpers

Craft CMS 3 and 4, 5 plugin enabling PDF document generation from template Twig files, code blocks and URLs
Other
13 stars 6 forks source link

Pdf includes CSS #22

Closed arentsen closed 11 months ago

arentsen commented 11 months ago

The pdf generator used to work find, but since a short time (I guess since the plugin update of last week), the pdf text shows the following CSS text on top of the text of the document:

Welcome to Craft CMS html, body { font-size: 16px; -webkit-text-size-adjust: 100%; height: 100%;
font-family: system-ui, BlinkMacSystemFont, -apple-system, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif; } body { margin: 0; padding: 0; ETC

It shows like this:

Screenshot 2023-11-29 at 13 15 41

Also, my local installation gives an error message:

Template „“ could not be found.

on this line (which is not cached):

<a href="{{alias('@web')}}/{{craft.documentHelper.pdf("artists/_biography-pdf.twig", "file", 'pdf/' ~ entry.title ~ '-' ~ craft.app.language|upper ~ '.pdf' ,entry, pdfOptions) }}" download target="_blank">Download Bio {{ craft.app.language|upper }}</a

and the pdfOptions is defined as follows:

{% set pdfOptions = {
    header: "/artists/_biography-pdf-header.twig",
    custom: {
       url: entry.url,
       bioTitle: "Biografie"|t,
       langShort: craft.app.language
    },
    footer: ""
} %}
cooltronicpl commented 11 months ago

Did you use the date option? So we fixed the issue about headers and footers because in many systems it can't be passed, we changed variable ?? null into isset(). Do you use a footer template? Because you passed an empty variable into a footer. It can be as not a founded template, and the content of the header (the top) is similar to the default Craft CMS page. When you use date option in pdfOptions your PDF may not be updated for a long time... Also, the header can be defined as the root of templates folder without the slash /, so in this example, many of our solutions header and footer templates are defined as the following PDF Options in _pdf folder of templates:

{% set pdfOptions = {
    ...
    header: "_pdf/header.twig",
    footer: "_pdf/footer.twig",
    ...
    }
%}    
arentsen commented 11 months ago

Thank you, that is helpful. No, I took out the date function since it did not work, but now it looks like it works again! Thanks for the update.