public function pdfAction() { $query = $this->getServiceLocator()->get('wrapperQuery'); $pressModel = new \CMS\Model\Press($query); $newsId = $this->params('newsId'); $newsDetails = $pressModel->getMoreDetails($newsId)[0]; $dompdf = new \DOMPDF(); $this->renderer = $this->getServiceLocator()->get('ViewRenderer'); $content = $this->renderer->render('cms/press/pdf', array('tmp_name' => $newsDetails->picture['tmp_name'], 'created' => $newsDetails->created, 'title' => $newsDetails->title, 'body' => $newsDetails->body, 'summary' => $newsDetails->summary, 'author' => $newsDetails->author)); // make a header as html $html = new MimePart($content); $html->type = "text/html"; $body = new MimeMessage("Hello"); $body->setParts(array($html)); // add html to convert it to pdf $dompdf->load_html($html->getContent()); $dompdf->set_paper("letter", "portrait"); $dompdf->render(); //download popup $dompdf->stream($newsDetails->title . '.pdf'); }
/** * @param null|'text/html'|'text' $type * * @return Email */ public function getMessage($type = null) { do { if (false !== strpos($this->current()->contenttype, 'text/html')) { $currentType = 'text/html'; } else { $currentType = 'text'; } } while ($type && $type != $currentType && $this->countParts() > $this->key() && !$this->next()); $message = new Email(); $message->setSubject($this->subject); $message->setTo($this->to); $message->setFrom($this->from); $part = new Part($this->current()); $body = (string) $part->getContent(); if ('text/html' == $currentType) { $body = quoted_printable_decode($body); } $message->setBody($body); return $message; }
/** * @link https://github.com/zendframework/zf2/issues/5428 * @group 5428 */ public function testContentEncodingWithStreamReadTwiceINaRow() { $testfile = realpath(__FILE__); $original = file_get_contents($testfile); $fp = fopen($testfile, 'rb'); $part = new Mime\Part($fp); $part->encoding = Mime\Mime::ENCODING_BASE64; $contentEncodedFirstTime = $part->getContent(); $contentEncodedSecondTime = $part->getContent(); $this->assertEquals($contentEncodedFirstTime, $contentEncodedSecondTime); fclose($fp); $fp = fopen($testfile, 'rb'); $part = new Mime\Part($fp); $part->encoding = Mime\Mime::ENCODING_QUOTEDPRINTABLE; $contentEncodedFirstTime = $part->getContent(); $contentEncodedSecondTime = $part->getContent(); $this->assertEquals($contentEncodedFirstTime, $contentEncodedSecondTime); fclose($fp); }