$post = $this->getRequest()->getParam('sku'); $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $helperImport = $objectManager->get('\Magento\Catalog\Helper\Image'); $productRepository = $objectManager->get('\Magento\Catalog\Model\ProductRepository'); $productObj = $productRepository->get($post); $sku = $productObj->getSku(); $name = $productObj->getName(); $price = $productObj->getPrice(); $description = $productObj->getDescription(); $shortDescripton = $productObj->getShortDescription(); $imageUrl = $helperImport->init($productObj, 'product_page_image_small') ->setImageFile($productObj->getSmallImage()) ->resize(380) ->getUrl();
$pdf = new \Zend_Pdf();
$pdf->pages[] = $pdf->newPage(\Zend_Pdf_Page::SIZE_A4);
$page = $pdf->pages[0]; // this will get reference to the first page.
$style = new \Zend_Pdf_Style();
$style->setLineColor(new \Zend_Pdf_Color_Rgb(0,0,0));
$font = \Zend_Pdf_Font::fontWithName(\Zend_Pdf_Font::FONT_TIMES);
$style->setFont($font,15);
$page->setStyle($style);
$width = $page->getWidth();
$hight = $page->getHeight();
$x = 30;
$pageTopalign = 700;
$this->y = 700 - 100;
$style->setFont($font,15);
$page->setStyle($style);
$page->drawRectangle(30, $this->y + 10, $page->getWidth()-30, $this->y +70, \Zend_Pdf_Page::SHAPE_DRAW_STROKE);
$style->setFont($font,15);
$page->setStyle($style);
$page->drawText(__("Product Attribute Information"), $x + 5, $this->y+50, 'UTF-8');
$style->setFont($font,11);
$page->setStyle($style);
//$page->drawText(__("Name : %1", "Test MageDelight"), $x + 5, $this->y+33, 'UTF-8');
// $page->drawText(__("Email : %1","[email protected]"), $x + 4, $this->y+15, 'UTF-8');
$style->setFont($font,11);
$page->setStyle($style);
$page->drawText(__("Image"), $x + 60, $this->y-10, 'UTF-8');
$page->drawText(__("Sku"), $x + 60, $this->y-10, 'UTF-8');
$page->drawText(__("Product Name"), $x + 200, $this->y-10, 'UTF-8');
$page->drawText(__("Price"), $x + 310, $this->y-10, 'UTF-8');
$page->drawText(__("Description"), $x + 440, $this->y-10, 'UTF-8');
$page->drawText(__("ShortDescription"), $x + 440, $this->y-10, 'UTF-8');
$style->setFont($font,10);
$page->setStyle($style);
$add = 9;
$om = \Magento\Framework\App\ObjectManager::getInstance();
$fileSystem = $om->create('\Magento\Framework\Filesystem');
$pdfImage =$fileSystem->getDirectoryRead(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA)->getAbsolutePath("catalog/product".$productObj->getImage());
$image = \Zend_Pdf_Image::imageWithPath($pdfImage);
$page->drawImage($image, $x + 210, $this->y-30, 'UTF-8');
$page->drawText($name, $x + 210, $this->y-30, 'UTF-8');
$page->drawText($price, $x + 330, $this->y-30, 'UTF-8');
$page->drawText($description, $x + 470, $this->y-30, 'UTF-8');
$page->drawText($sku, $x + 65, $this->y-30, 'UTF-8');
$page->drawRectangle(30, $this->y -62, $page->getWidth()-30, $this->y + 10, \Zend_Pdf_Page::SHAPE_DRAW_STROKE);
$page->drawRectangle(30, $this->y -62, $page->getWidth()-30, $this->y - 100, \Zend_Pdf_Page::SHAPE_DRAW_STROKE);
$style->setFont($font,15);
$page->setStyle($style);
//$page->drawText(__("Total : %1", "$50.00"), $x + 435, $this->y-85, 'UTF-8');
$style->setFont($font,10);
$page->setStyle($style);
//$page->drawText(__("Test Footer example"), ($page->getWidth()/2)-50, $this->y-200);
$fileName = 'attribute.pdf';
$this->fileFactory->create(
$fileName,
$pdf->render(),
\Magento\Framework\App\Filesystem\DirectoryList::VAR_DIR,
'application/pdf'
);