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.