/** * @param File $file */ public function __construct(File $file) { parent::__construct($file->getContent()); $this->addHeader(sprintf('Content-Type: %s', $file->getType())); $this->addHeader(sprintf('Content-Length: %d', $file->getSize())); $this->addHeader(sprintf('Content-Disposition: attachment; filename="%s"', $file->getName())); }
/** * @param $html * @return File * @throws \Exception */ public function generate($html) { $tempName = md5(rand()); $htmlFile = new File(); $htmlFile->setPath(sprintf('%s/tmp/%s.html', APP_DIR, $tempName))->setContent($html); $pdfFile = new File(); $pdfFile->setName(sprintf('%s.pdf', $tempName))->setPath(sprintf('%s/tmp/%s.pdf', APP_DIR, $tempName))->setType('application/pdf'); exec(sprintf('%s %s %s', $this->getBinaryPath(), $htmlFile->getPath(), $pdfFile->getPath())); return $pdfFile; }