Last active
November 18, 2022 14:53
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you