Back to Top

Generate pdf file from pdf string and image string content in Magento 2

Updated 22 February 2024

here we will learn, how to generate pdf file if you have string data of pdf and image.

public function generatePdf()
{
   $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
   $labelGenerator = $objectManager->create('Magento\Shipping\Model\Shipping\LabelGenerator');
   $labelContent[] = base64_decode((string) $imageString); //you can add more image strings.
   $outputPdf = $labelGenerator->combineLabelsPdf($labelContent);

   $fileFactory = $objectManager->create('Magento\Framework\App\Response\Http\FileFactory');

   return $fileFactory->create(
         'Labels.pdf',
          $outputPdf->render(),
          \Magento\Framework\App\Filesystem\DirectoryList::VAR_DIR,
          'application/pdf'
       );
}

By calling this function you can generate pdf file from string content.

Searching for an experienced
Magento 2 Company ?
Find out More
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Back to Top

Message Sent!

If you have more details or questions, you can reply to the received confirmation email.

Back to Home