Hot answers tagged

5

I found any relative link should not lead with a slash.


4

Since the templates are rendered on the server and not in a regular http request (in the front end templates), the globals are not loaded automatically, into the global twig namespace. You can still access your global set and use it as you usually would by setting it to a variable. You can do so like this: {% set companyInfo = craft.globals.getSetByHandle(...


4

Note: I've never used amforms nor mPDF, so I'm on a bit thin ice with this answer – hopefully it'll prove semi-useful, though. How do I add the mPDF library to Craft? To include any third-party PHP library in Craft, you'll need to build a custom plugin, since that's the only real way to write (or include) PHP inside a Craft CMS app. Craft plugins are ...


3

As far as I know, there is no ready-built solutions available for Craft that makes text in PDFs searchable. You probably have to look into building this plugin yourself, or hire someone to do it. Posting in the #jobs channel on Craft's Slack is a good place to start.


3

Here is a working example using mPDF 6.1. Thanks to Mats Mikkel Rummelhoff for pointing me in the right direction. Note: the event you need is amForms_submissions.onBeforeEmailConfirmSubmission. This event contains the confirmation email, so you can add your attachment straight to it. public function init(){ require_once __DIR__ . '/vendor/autoload....


3

You have to check if your matrix element has a block or not with the code $block->downloadablePdf[0]->url you'll access the first element in your matrix but when there is no it will throw an error. 'downloadablePDF' => $block->downloadablePdf[0]? $block->downloadablePdf[0]->getUlr() : '' will check if there is an asset and return the url ...


3

I would also suggest a custom plugin approach. A good starting point would be this package: https://github.com/smalot/pdfparser. I am mostly including this answer for anyone who happens to find this question and has the ability/inclination to create such a plugin.


3

I created a plugin specifically to do this - https://github.com/bymayo/craft-pdf-transform It takes Asset PDF files and coverts them to JPEG / PNG files automatically when they are uploaded. Or, do theres a Twig method that lets you convert the PDF to an image if the image already exists in Assets. But this can be a bit labour intensive on the server to ...


3

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 ...


3

We've used it successfully to generate PDF tickets for orders. It may/may not help in your case. On our order page, we simply have: <a target="_blank" href="/orders/tickets?orderId={{ order.number }}">Download PDF Tickets</a> Then, our order/tickets template: {% set html %} {% set orderId = craft.request.param('orderId') %} // HTML/...


3

No, I don't think there's a way of having a "live" pdf open, in the same way as a webpage. But, what I usually do is just open the pdf template directly in the browser and create the HTML and CSS while using my normal workflow to check how it looks in the browser. This usually get me 95% of the way, and then I can do the final tweaks when I see what dompdf ...


3

You'd need to make a simple Craft plugin that added a Twig filter/function that wrapped PHP's file_get_contents to grab the file contents, but at that point, you might as well just make it a wrapper for craft()->request->sendFile().


2

Depending on your server setup, DOMPDF might be resetting the output buffer when the PDF is generated. This is a fairly rare issue, but I have heard of it before. Solution: Try moving the Printmaker PDF-generation code to the top of the template before any output. For example, at the top of the template... {% set pdfUrl = craft.printmaker.pdfFromTemplate('...


2

In March, I released a Digital Download plugin which makes this process extremely simple... <a href="{{ craft.digitalDownload.url(asset) }}">{{ asset.title }}</a> View the complete documentation to read more about how it works.


2

There's currently not a native way to change this format, but it is planned for a future release. In the meantime as a workaround, you can listen to the onBeforeSaveOrder event and change the order number to whatever format you want. A by-product of that is that the PDF receipt filename should change to your format as well.


2

You can send an email via your plugin's init() function like so: craft()->on( 'email.onBeforeSendEmail', function( Event $event ){ $email = $event->params['emailModel']; $attachment = array( 'path' => '/var/www/public/assets/downloads/filename.pdf', 'name' => 'File Title', 'encoding' => 'base64', ...


2

Should be no problem, Craft has extensive user management capabilities, check https://craftcms.com/features/users & https://craftcms.com/docs/users as well as solid asset management https://craftcms.com/features/assets Log in to the demo https://demo.craftcms.com/ or do a local install, as long as your test domain has .dev in the url you can fully test ...


2

I've not yet tested specifically with Printmaker (only Laravel + Dompdf), but you should be able to add page numbers by using a special <script> block in the template you use for PDF rendering. This block's PHP instructions will be interpreted by Dompdf as it renders your document, so you can position additional elements like page numbers, headers/...


2

So the problem you're running into is all about context. Twig operates in the context of the http request for the parent page; so any headers you add via Twig will be added to the page http header, which is not what you want. This could be done server-side, as the article you reference mentions. But it becomes a bit more involved when we're dealing with ...


1

Well, the only i way i found to solve this was to made my custom plugin for craft 3 CP. I build my template scafold here: https://pluginfactory.io/ Then installed it via composer and started coding to achieve what i want. Job done.


1

Craft 3 doesn't do this natively and I'm not seeing any existing Craft 3 plugins that would do this, so at the moment, you'd need to write your own.


1

It's not as neat as something automated but could add a custom field to your asset type (or if each PDF has an entry, to that entry type) called something like 'PDF Content'. I would probably make it a multi-line plain text field. You can then get your client to copy and paste all the content from the pdf into that field when uploading and use this content ...


1

Got the same problem with Craft3 (3.0.0-beta.19). Had to change the imageDriver to GD. Add 'imageDriver' => 'gd', to config/general.php and replace/reupload the files in Craft.


1

Currently (Craft Commerce 1.1) there is no way to attach the PDF in an order status email, it can only be a link to download the PDF. For now, I suggest you make a feature request here: http://feedback.craftcms.com/forums/295386-commerce/filters/top


1

For anyone looking to do this on Craft 3, I used pThumb previously, but I created a plugin specifically to do this for Craft 3 - https://github.com/bymayo/craft-pdf-transform It takes Asset PDF files and coverts them to JPEG / PNG files automatically when they are uploaded. Or, do theres a Twig method that lets you convert the PDF to an image if the image ...


1

Martin, For reference, here's the template code you shared with me earlier: {% set html %} {% set entryId = craft.request.param('entryId') %} <html> ... <body> {{ entry.title }} </body> </html> {% endset %} {% set settings = { ... } %} {% set pdf = craft.printmaker.pdfFromHtml(html, settings) %} ...


Only top voted, non community-wiki answers of a minimum length are eligible