Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot override config.format on a per-file basis #149

Open
bestiony opened this issue Aug 24, 2024 · 0 comments
Open

Cannot override config.format on a per-file basis #149

bestiony opened this issue Aug 24, 2024 · 0 comments

Comments

@bestiony
Copy link

my config file looks like this :

return [
    'mode'                       => '',
    'format'                     => 'A4',
    'default_font_size'          => '12',
    // the rest of the config 
];

and when i make the pdf i use this code :

use App\Models\Invoice;
use Mccarlosen\LaravelMpdf\Facades\LaravelMpdf;


function print(){
       $invoice = Invoice::first();
       $data = [];
       $view = 'template_1';

       $pdf = LaravelMpdf::loadView($view, $data, [
                'format' => ['100','500'],
                'margin_left' => 0,
                'margin_right' => 0,
                'margin_top' => 0,
                'margin_bottom' => 0,
                'margin_header' => 0,
                'margin_footer' => 0,
            ]);
       $fileName = "invoice-#{$invoice->invoice_number}.pdf";

       header("Content-Type: application/octet-stream");
       header("Content-Disposition: attachment; filename={$fileName}");

       return  $pdf->stream($fileName);
}

the reason I am using the format ['100','500'] is to print a POS style invoice

the problem is that the the outcome page size is always 'A4' even if i clear all the cache using php artisan optimize:clear

possible workaround :
when I change the config before I load the view it works fine :

config(['pdf.format' => ['100','500']);
$pdf = LaravelMpdf::loadView($view, $data, [
                'margin_left' => 0,
                // the rest of the code 
];

is there a better solution? or a reason why it does not take the format value I am providing while loading the vue ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant