Webkul
Services
Technologies Bagisto QloApps
iOS Android SAP BigCommerce Wix
Trusted by
Samsung Intel Toyota Walmart Disney Nokia Nestlé Decathlon
See all customers
Back to Top
DOC

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

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.

. . .

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