Skip to content

Instantly share code, notes, and snippets.

@sumanthkumarc
Last active November 18, 2022 14:53
Show Gist options
  • Save sumanthkumarc/91de05b96f358707e36191c672973d29 to your computer and use it in GitHub Desktop.
Save sumanthkumarc/91de05b96f358707e36191c672973d29 to your computer and use it in GitHub Desktop.
D8 : save a pdf using entity_print print builder service and display it as link
<?php
use Drupal\Core\Url;
$entities = [node_object];
$scheme = 'public';
$filename = 'something.pdf';
$export_type = 'pdf';
/* @var \Drupal\entity_print\PrintBuilder $print_builder */
$print_builder = \Drupal::service('entity_print.print_builder');
$print_engine = \Drupal::service('plugin.manager.entity_print.print_engine');
$engine = $print_engine->createSelectedInstance($export_type);
$file_uri = $print_builder->savePrintable($entities,$engine,$scheme,$filename, TRUE);
//$pdf_link is Url object
$pdf_link = Url::fromUi(file_create_url($file_uri));
@Bon2xl
Copy link

Bon2xl commented Nov 18, 2022

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment