enupal / snapshot

PDF or Image generation from a URL or HTML page easily for Craft CMS

Home Page:https://enupal.com/craft-plugins/enupal-snapshot/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Generation triggered programatically

K31Z0 opened this issue · comments

Hello,

I would like to know if it is possible to generate a PDF or IMG using Enupal Snapshot programatically in a Craft Module ?

Thanks in advance

Luigi

Hi @K31Z0

Yes, it is possible. Please follow the next examples:

use enupal\snapshot\Snapshot;
...

// PDFs
Snapshot::$app->pdf->displayHtml($html, $settings)
Snapshot::$app->pdf->displayTemplate($template, $settings)
Snapshot::$app->pdf->displayOrder($order, $settings)
Snapshot::$app->pdf->displayUrl($url, $settings)

// Images
Snapshot::$app->image->displayHtml($html, $settings);
Snapshot::$app->image->displayTemplate($template, $settings);
Snapshot::$app->image->displayOrder($order, $settings);
Snapshot::$app->image->displayUrl($url, $settings);

Remember to add a return statement if you want to display a inline PDF:

return Snapshot::$app->image->displayHtml($html, $settings);

Please let me know if you have any questions

Hi @andrelopez,

Thanks for the quick reply,

I tried the code you sent me with (which was the methods I tried before opening this ticket) :

use enupal\snapshot\Snapshot;
...
$settings = [
    'filename' => 'my-first-image.png',
    'asImage'  => true
];

Snapshot::$app->image->displayHtml('<h1>my image generation test</h1>', $settings);

but I have this error in return:

Trying to get property 'image' of non-object

Best regards