2017 © Pedro Peláez
 

library pdf-response

Fork of pdf-response, Pdf response extension for Nette Framework

image

lukyrys/pdf-response

Fork of pdf-response, Pdf response extension for Nette Framework

  • Tuesday, January 23, 2018
  • by lukyrys
  • Repository
  • 1 Watchers
  • 0 Stars
  • 559 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 23 Forks
  • 0 Open issues
  • 14 Versions
  • 2 % Grown

The README.md

PDF Response for Nette 2

Build Status Latest Stable Version Total Downloads, (*1)

  • sends template as PDF output
  • works fine with both Nette 2.0.* and Nette 2.1.* and even Nette 2.2.*
  • no js support
  • nice api

Install

Installation via Composer., (*2)

{
    "require":{
        "joseki/pdf-response": ">= 2.1"
    }
}

How to prepare PDF from template

// in a Presenter
public function actionPdf()
{
    $template = $this->createTemplate();
    $template->setFile("/path/to/template.latte");
    $template->someValue = 123;
    // Tip: In template to make a new page use <pagebreak>

    $pdf = new Joseki\Application\Responses\PdfResponse($template);

    // optional
    $pdf->documentTitle = date("Y-m-d") . " My super title"; // creates filename 2012-06-30-my-super-title.pdf
    $pdf->pageFormat = "A4-L"; // wide format
    $pdf->getMPDF()->setFooter("|© www.mysite.com|"); // footer
}

Save file to server

public function actionPdf()
{
    $template = $this->createTemplate();
    $template->setFile("/path/to/template.latte");

    $pdf = new Joseki\Application\Responses\PdfResponse($template);

    $pdf->save("/path/to/directory"); // as a filename $this->documentTitle will be used
    $pdf->save("/path/to/directory", "filename"); // OR use a custom name
}

Attach file to an email

public function actionPdf()
{
    $template = $this->createTemplate();
    $template->setFile("/path/to/template.latte");

    $pdf = new Joseki\Application\Responses\PdfResponse($template);

    $savedFile = $pdf->save("/path/to/directory");
    $mail = new Nette\Mail\Message;
    $mail->addTo("john@doe.com");
    $mail->addAttachment($savedFile);
    $mailer = new SendmailMailer();
    $mailer->send($mail);
}

Force file to download

public function actionPdf()
{
    $template = $this->createTemplate();
    $template->setFile("/path/to/template.latte");

    $pdf = new Joseki\Application\Responses\PdfResponse($template);
    $pdf->setSaveMode(PdfResponse::DOWNLOAD); //default behavior
    $this->sendResponse($pdf);
}

Force file to display in a browser

public function actionPdf()
{
    $template = $this->createTemplate();
    $template->setFile("/path/to/template.latte");

    $pdf = new Joseki\Application\Responses\PdfResponse($template);
    $pdf->setSaveMode(PdfResponse::INLINE);
    $this->sendResponse($pdf);
}

Set a pdf background easily

public function actionPdf()
{
    $pdf = new Joseki\Application\Responses\PdfResponse('');
    $pdf->setBackgroundTemplate("/path/to/an/existing/file.pdf");

    // to write into an existing document use the following statements
    $mpdf = $pdf->getMPDF();
    $mpdf->WriteFixedPosHTML('hello world', 1, 10, 10, 10);

    // to write to another page
    $mpdf->AddPage();

    // to move to exact page, use
    $mpdf->page = 3; // = move to 3rd page

    $this->sendResponse($pdf);
}

Create pdf with latte only

public function actionPdf()
{
    $latte = new Latte\Engine;
    $latte->setTempDirectory('/path/to/cache');
    $latte->addFilter('money', function($val) { return ...; }); // formerly registerHelper()

    $latte->onCompile[] = function($latte) {
        $latte->addMacro(...); // when you want add some own macros, see http://goo.gl/d5A1u2
    };

    $template = $latte->renderToString("/path/to/template.latte");

    $pdf = new Joseki\Application\Responses\PdfResponse($template);
    $this->sendResponse($pdf);
}

See also

The Versions

23/01 2018

dev-master

9999999-dev

Fork of pdf-response, Pdf response extension for Nette Framework

  Sources   Download

LGPL-3.0 LGPL-3.0-only

The Requires

 

The Development Requires

22/01 2018

v2.2.6

2.2.6.0

Fork of pdf-response, Pdf response extension for Nette Framework

  Sources   Download

LGPL-3.0-only

The Requires

 

The Development Requires

14/09 2017

v2.2.5

2.2.5.0

Fork of pdf-response, Pdf response extension for Nette Framework

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

09/08 2016

v2.2.4

2.2.4.0

Fork of pdf-response, Pdf response extension for Nette Framework

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

13/01 2015
22/11 2014
30/07 2014

v2.2.1

2.2.1.0

Pdf response extension for Nette Framework

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

12/06 2014

v2.2.0

2.2.0.0

Pdf response extension for Nette Framework

  Sources   Download

LGPL-3.0

The Requires

 

28/02 2014

v2.1.1

2.1.1.0

Pdf response extension for Nette Framework

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

07/02 2014

v2.1.0

2.1.0.0

Pdf response extension for Nette Framework

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

21/04 2013

v2.0.0

2.0.0.0

Personal fork of schmutzka/pdf-response - packagist enabled

  Sources   Download

LGPL-3.0

The Requires

 

11/04 2013

v1.2.0

1.2.0.0

Personal fork of schmutzka/pdf-response - packagist enabled

  Sources   Download

LGPL-3.0

The Requires

 

10/04 2013

v1.1.0

1.1.0.0

Personal fork of schmutzka/pdf-response - packagist enabled

  Sources   Download

LGPL-3.0

The Requires

 

09/02 2013

v1.0.0

1.0.0.0

Personal fork of schmutzka/pdf-response - packagist enabled

  Sources   Download

LGPL-3.0

The Requires