1. Go to this page and download the library: Download orkestra/pdf-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
orkestra / pdf-bundle example snippets
namespace MyBundle\PdfGenerator;
use Orkestra\Bundle\PdfBundle\Generator\AbstractPdfGenerator;
use Symfony\Component\OptionsResolver\OptionsResolver;
class InvoiceGenerator extends AbstractPdfGenerator
{
/**
* Performs the PDF generation
*
* @param array $parameters An array of parameters to be used to render the PDF
* @param array $options An array of options to be passed to the underlying PdfFactory
*
* @return \Orkestra\Bundle\PdfBundle\Pdf\PdfInterface
*/
protected function doGenerate(array $parameters, array $options)
{
// Use the createPdf method to create the desired type of PDF
$pdf = $this->createPdf('wkpdf', $options);
// Call any native methods on the underlying library object
$builder = $pdf->getNativeObject();
$builder->useTemporaryFile();
$builder->setInput($this->render('MyBundle:Pdf/Invoice:template.html.twig', $parameters));
// Return the original PDF, calling getContents to retrieve the rendered content
return $pdf;
}
/**
* Configure the parameters OptionsResolver.
*
* Use this method to specify default and
class MyController extends Controller
{
// ...
public function someAction()
{
// Fetch the invoice from somewhere
$invoice = $this->getInvoice();
$generator = $this->get('my_bundle.invoice_pdf_generator');
$pdf = $generator->generate(array('invoice' => $invoice));
// Write the PDF to a file
file_put_contents('/some/path/to.pdf', $pdf->getContents());
// Output the PDF to the browser
return new Response($pdf->getContents(), 200, array('Content-type' => 'application/pdf'));
}
}