/** * Generates certificate of exellence and * triggers an event when the file is generated * @param \User\Model\Entity\User $user * @param string $examName */ public function generateCertificate($user, $examName) { $config = $this->services->get('config'); $pdf = PdfDocument::load($config['pdf']['exam_certificate']); // get the first page $page = $pdf->pages[0]; // Extract the AdineKirnberg-Script font included in the PDF sample $font = $page->extractFont('AdineKirnberg-Script'); $page->setFont($font, 80); // and write the name of the user with it $page->drawText($user->getName(), 200, 280); // after that use Time Bold to write the name of the exam $font = PdfFont::fontWithName(PdfFont::FONT_TIMES_BOLD); $page->setFont($font, 40); $page->drawText($examName, 200, 120); // We use the png image from the public/images folder $imageFile = 'public/images/zf2-logo.png'; // get the right size to do some calculations $size = getimagesize($imageFile); // load the image $image = \ZendPdf\Image::imageWithPath($imageFile); $x = 580; $y = 440; // and finally draw the image $page->drawImage($image, $x, $y, $x + $size[0], $y + $size[1]); return $pdf; }
/** * Generate the Pdf * @param IntentDocumentGeneratedEvent $event the event * @see http://stackoverflow.com/questions/7585474/accessing-files-relative-to-bundle-in-symfony2 * @todo finaliser l'inscrition de toutes les info dynamiques * @todo avoir une sepa-template neutre * @todo insérer le logo du layout courant dans le pdf * @todo insérer des textes simple en y ajoutant le nom du client dynamiquement * @todo insérer l'ICS */ public function generate(IntentDocumentGeneratedEvent $event) { /** * @var Ecedi\Donate\CoreBundle\Entity\Intent */ $intent = $event->getIntent(); if ($intent->getPaymentMethod() === SepaOfflinePaymentMethod::ID && $event->getDocument() === null) { $pdf = new Pdf\PdfDocument(); $pdf->pages[] = $page1 = $pdf->newPage('A4'); $page1->setFont(Pdf\Font::fontWithName(Pdf\Font::FONT_HELVETICA), 12); $path = $this->kernel->locateResource('@DonatePaymentBundle/Resources/public/img/sepa-template.jpg'); $stampImageJPG = Pdf\Image::imageWithPath($path); $page1->drawImage($stampImageJPG, 0, 0, 595, 842); $page1->drawText($this->rumGenerator->generate($intent), 170, 389, 'UTF-8'); //TODO faire la suite $event->setDocument($pdf); $event->stopPropagation(); } }
public function attachImage($image_path, $x1, $y1, $x2, $y2) { if (!file_exists($image_path)) { throw new \Exception("Image file not accessible "); } $image = Image::imageWithPath($image_path); $this->single_page->drawImage($image, $x1, $y1, $x2, $y2); }
/** * Draw the character's image onto a PDF page, within the given coordinates * * @param \SimplePdf\Page $page page to draw on * @param float $x1 x-coordinate of the top-left corner of the box to draw the image in * @param float $y1 y-coordinate of the top-left corner of the box to draw the image in * @param float $x2 x-coordinate of the bottom-right corner of the box to draw the image in * @param float $y2 y-coordinate of the bottom-right corner of the box to draw the image in * @param int $dpi DPI to use to render the image */ public function drawToPage(\SimplePdf\Page $page, $x1, $y1, $x2, $y2, $dpi) { $conversion = $dpi / 72; $page->convertToPoints($conversion); $width = $x2 - $x1; $height = $y2 - $y1; $imageWidth = $width * $conversion; $imageHeight = $height * $conversion; $tempFile = $this->prepareTemporaryImageFile($imageWidth, $imageHeight); list($newImageWidth, $newImageHeight) = getimagesize($tempFile); $imageResource = \ZendPdf\Image::imageWithPath($tempFile); unlink($tempFile); list($horizontalGravity, $verticalGravity) = $this->getGravityCoordinates(); if ($newImageHeight / $newImageWidth < $imageHeight / $imageWidth) { $remainder = $height - $width * ($newImageHeight / $newImageWidth); $y1 += $verticalGravity * $remainder; $y2 -= (1 - $verticalGravity) * $remainder; } else { $remainder = $width - $height / ($newImageHeight / $newImageWidth); $x1 += $horizontalGravity * $remainder; $x2 -= (1 - $horizontalGravity) * $remainder; } $page->drawImage($imageResource, $x1, $y1, $x2, $y2); }
/** * @{inheritDoc} */ public function getImage($filePath) { return $image = Image::imageWithPath($filePath); }