-1

I am going to use DynamicPDF plugin to export to pdf some fields from backend on update/edit view of my plugin in OctoberCMS, can someone help me?

on plugin controller i have this call:

<?php namespace Vimagem\Pacientes\Controllers;

use Backend\Classes\Controller;
use BackendMenu;
use Renatio\DynamicPDF\Classes\PDF;
use Renatio\DynamicPDF\Classes\PDFWrapper;


class Pacientes extends Controller
{
    public $implement = [        'Backend\Behaviors\ListController',        'Backend\Behaviors\FormController',        'Backend\Behaviors\ReorderController'    ];

    public $listConfig = 'config_list.yaml';
    public $formConfig = 'config_form.yaml';
    public $reorderConfig = 'config_reorder.yaml';

    public function __construct()
    {
        parent::__construct();
        BackendMenu::setContext('Vimagem.Pacientes', 'main-menu-item');
    }


    /** PDF **/




public function pdf($id)
{

    return PDF::loadTemplate('export-data-pdf')->stream('download.pdf');
}



}

On the PDF Template (export-data-pdf) i need to call some form fields from one client:

{{ name }}
{{ address }}
{{ phone }}
etc...

but i can´t get the fields show up, what its wrong ?

Thank you, Vitor

azvm
  • 41
  • 1
  • 8
  • Yes, but we need more specific information about what you are trying to do and what issues you are running into. – Joseph Oppegaard Oct 28 '19 at 21:00
  • Hello, i have created a from on builder plugin. now o need to get the fields value to be output on the PDF. i will update the code i use in my question, thank you Joseph – azvm Oct 28 '19 at 23:01

2 Answers2

0

This code was found in the plugins documents.

use Renatio\DynamicPDF\Classes\PDF; // import facade

...

public function pdf()
{
    $templateCode = 'renatio::invoice'; // unique code of the template
    $data = ['name' => 'John Doe']; // optional data used in template

    return PDF::loadTemplate($templateCode, $data)->stream('download.pdf');
}

I have used this plugin and it works well. You need to pass in data to the PDF stream.

Pettis Brandon
  • 875
  • 1
  • 6
  • 8
  • thank you, i have use this code to, but not working for what i need, i need to pull data from record id from client, dynamic data. – azvm Oct 29 '19 at 00:25
  • Yeah but this is how you inject data into the pdf. For example `Patient::where('id', $id')->first()` then you have access to the user record you want. Easy Peazy. – Pettis Brandon Oct 29 '19 at 17:14
0

This is done, worked around a solution for this.

Here is the controller application:

<?php namespace Vimagem\Pacientes\Controllers;

use Backend\Classes\Controller;
use BackendMenu;
use Renatio\DynamicPDF\Classes\PDFWrapper;
use Vimagem\Pacientes\Models\Paciente;
use \October\Rain\Database\Traits\Validation;
use Str;

class Pacientes extends Controller
{
    public $implement = [        'Backend\Behaviors\ListController',        'Backend\Behaviors\FormController',        'Backend\Behaviors\ReorderController'    ];

    public $listConfig = 'config_list.yaml';
    public $formConfig = 'config_form.yaml';
    public $reorderConfig = 'config_reorder.yaml';

    public function __construct()
    {
        parent::__construct();
        BackendMenu::setContext('Vimagem.Pacientes', 'main-menu-item');
    }




/**** PDF Export ***/

public function pdf($id)
    {
        $paciente = Paciente::find($id);
        if ($paciente === null) {
            throw new ApplicationException('User not found.');
        }


        $filename = Str::slug($paciente->nome) . '.pdf';

        try {
            /** @var PDFWrapper $pdf */
            $pdf = app('dynamicpdf');

            $options = [
                'logOutputFile' => storage_path('temp/log.htm'),
            ];

            return $pdf
                ->loadTemplate('export-data-pdf', compact('paciente'))
                ->setOptions($options)
                ->stream($filename);

        } catch (Exception $e) {
            throw new ApplicationException($e->getMessage());
        }
    }   


}


Now i can use partials on the template like this:

<p>{{ paciente.nome }}</p>

<p>{{ paciente.morada }}</p>


etc...

Thank you all that try to helped me.

Vitor

azvm
  • 41
  • 1
  • 8