Quantcast
Channel: Webkul Blog
Viewing all articles
Browse latest Browse all 5553

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

$
0
0

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 $this->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.


Viewing all articles
Browse latest Browse all 5553

Trending Articles