Skip to content

Commit

Permalink
Polished docs
Browse files Browse the repository at this point in the history
- use 4 spaces in CSS, in JS, in HTML and in Latte
- use tab in NEON and in PHP
- neon highlighting syntax
  • Loading branch information
petrparolek authored and kodiakhq[bot] committed Mar 10, 2021
1 parent b295868 commit 9a56bd4
Showing 1 changed file with 63 additions and 63 deletions.
126 changes: 63 additions & 63 deletions .docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
- [Save file to server](#save-file-to-server)
- [Attach file to an email](#attach-file-to-an-email)
- [Force file to download](#force-file-to-download)
- [Force file to display in a browser](#force-file-to-display-in-a-browser)
- [Set a pdf background easily](#set-a-pdf-background-easily)
- [Create pdf with latte only](#create-pdf-with-latte-only)
- [Configuration of custom temp dir for mPDF in PdfResponse](#configuration-of-custom-temp-dir-for-mpdf-in-pdfresponse)
- [Force file to display in a browser](#force-file-to-display-in-a-browser)
- [Set a pdf background easily](#set-a-pdf-background-easily)
- [Create pdf with latte only](#create-pdf-with-latte-only)
- [Configuration of custom temp dir for mPDF in PdfResponse](#configuration-of-custom-temp-dir-for-mpdf-in-pdfresponse)

## Usage

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

$pdf = new \Contributte\PdfResponse\PdfResponse($template);
$pdf = new \Contributte\PdfResponse\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
// 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

// do something with $pdf
$this->sendResponse($pdf);
// do something with $pdf
$this->sendResponse($pdf);
}
```

Expand All @@ -42,13 +42,13 @@ public function actionPdf()
```php
public function actionPdf()
{
$template = $this->createTemplate();
$template->setFile(__DIR__ . "/path/to/template.latte");
$template = $this->createTemplate();
$template->setFile(__DIR__ . "/path/to/template.latte");

$pdf = new \Contributte\PdfResponse\PdfResponse($template);
$pdf = new \Contributte\PdfResponse\PdfResponse($template);

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

Expand All @@ -57,17 +57,17 @@ public function actionPdf()
```php
public function actionPdf()
{
$template = $this->createTemplate();
$template->setFile(__DIR__ . "/path/to/template.latte");
$template = $this->createTemplate();
$template->setFile(__DIR__ . "/path/to/template.latte");

$pdf = new \Contributte\PdfResponse\PdfResponse($template);
$pdf = new \Contributte\PdfResponse\PdfResponse($template);

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

Expand All @@ -76,12 +76,12 @@ public function actionPdf()
```php
public function actionPdf()
{
$template = $this->createTemplate();
$template->setFile(__DIR__ . "/path/to/template.latte");
$template = $this->createTemplate();
$template->setFile(__DIR__ . "/path/to/template.latte");

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

Expand All @@ -90,12 +90,12 @@ public function actionPdf()
```php
public function actionPdf()
{
$template = $this->createTemplate();
$template->setFile(__DIR__ . "/path/to/template.latte");
$template = $this->createTemplate();
$template->setFile(__DIR__ . "/path/to/template.latte");

$pdf = new \Contributte\PdfResponse\PdfResponse($template);
$pdf->setSaveMode(PdfResponse::INLINE);
$this->sendResponse($pdf);
$pdf = new \Contributte\PdfResponse\PdfResponse($template);
$pdf->setSaveMode(PdfResponse::INLINE);
$this->sendResponse($pdf);
}
```

Expand All @@ -104,20 +104,20 @@ public function actionPdf()
```php
public function actionPdf()
{
$pdf = new \Contributte\PdfResponse\PdfResponse('');
$pdf->setBackgroundTemplate(__DIR__ . "/path/to/an/existing/file.pdf");
$pdf = new \Contributte\PdfResponse\PdfResponse('');
$pdf->setBackgroundTemplate(__DIR__ . "/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 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 write to another page
$mpdf->AddPage();

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

$this->sendResponse($pdf);
$this->sendResponse($pdf);
}
```

Expand All @@ -126,29 +126,29 @@ public function actionPdf()
```php
public function actionPdf()
{
$latte = new Latte\Engine;
$latte->setTempDirectory('/path/to/cache');
$latte->addFilter('money', function($val) { return ...; }); // formerly registerHelper()
$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
};
$latte->onCompile[] = function($latte) {
$latte->addMacro(...); // when you want add some own macros, see http://goo.gl/d5A1u2
};

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

$pdf = new \Contributte\PdfResponse\PdfResponse($template);
$this->sendResponse($pdf);
$pdf = new \Contributte\PdfResponse\PdfResponse($template);
$this->sendResponse($pdf);
}
```

### Configuration of custom temp dir for mPDF in PdfResponse

```yaml
```neon
services:
-
factory: Contributte\PdfResponse\PdfResponse
setup:
- $mpdfConfig([tempDir: %tempDir%/mpdf])
-
factory: Contributte\PdfResponse\PdfResponse
setup:
- $mpdfConfig([tempDir: %tempDir%/mpdf])
```


Expand Down

0 comments on commit 9a56bd4

Please sign in to comment.