Laravel-snappy: How can I set margin on Cover Page ?

Created on 21 Mar 2017  路  3Comments  路  Source: barryvdh/laravel-snappy

I have a pdf with Cover page.

I use laravel 5.2 with snappy pdf.

My code is ::

$pdf = \PDF::loadHTML($view->render());
         $pdf->setOption('cover', View::make('generatereport.pdfcoverpage', $dataArray));
        $pdf->setOption('margin-top',0);
        $pdf->setOption('margin-bottom',10);
        $pdf->setOption('margin-left',0);
        $pdf->setOption('margin-right',0);
        $pdf->setOption('footer-html',  View::make('generatereport.pdffooter'));

The problem is 'margin-bottom' in also apply on cover page.
any way here to set cover page 'margin-bottom = 0' ?

stale

Most helpful comment

I have include PDFMerger library with this library (laravel-snappy).
(1) Install new library for PDFMerger - "rguedes/pdfmerger": "^1.0",
(2) Include PDFMerger library in file - use PDFMerger;

                    $file_name_generated = 'test.pdf';
                    $subfolder_path = 'test_pdf';
                    $exact_path = '../storage/'.$subfolder_path;

                    $headerHtml = view()->make('pdf.header')->render();

                    // Generate cover PDF
                    $cover = PDF::loadView('pdf.cover', $coverData)
                        ->setOption('no-background', false)
                        ->setOption('background', true)
                        ->setOption('disable-javascript', true)
                        ->setOption('print-media-type', false)
                        ->setOption('margin-bottom', 0)
                        ->setOption('margin-left', 0)
                        ->setOption('margin-right', 0)
                        ->setOption('margin-top', 0)
                        ->save($exact_path.'/tmp/cover_'.$file_name_generated);
                    $coverUrl = storage_path($subfolder_path.'/tmp/cover_'.$file_name_generated);

                    // Generate Draft Care Plan PDF
                    $pdf = PDF::loadView('pdf.content', $pdfContentData)
                        ->setOption('margin-left','15')
                        ->setOption('margin-right','15')
                        ->setOption('margin-top','30')
                        ->setOption('margin-bottom','20')
                        ->setOption('header-html', $headerHtml)
                        ->setOption('footer-html', route('pdf.footer'))
                        ->save($exact_path.'/tmp/'.$file_name_generated);
                    $contentUrl = storage_path($subfolder_path.'/tmp/'.$file_name_generated);
                    $tempFolderPath = storage_path($subfolder_path.'/tmp_'.$draftId);

                    // Merge PDF
                    $newpdf = new PDFMerger();
                    $newpdf->addPDF($coverUrl, '1');
                    $newpdf->addPDF($contentUrl, 'all');
                    $newpdf->merge('file', $exact_path.'/'.$file_name_generated);

Thanks

All 3 comments

I have same problem.

I have include PDFMerger library with this library (laravel-snappy).
(1) Install new library for PDFMerger - "rguedes/pdfmerger": "^1.0",
(2) Include PDFMerger library in file - use PDFMerger;

                    $file_name_generated = 'test.pdf';
                    $subfolder_path = 'test_pdf';
                    $exact_path = '../storage/'.$subfolder_path;

                    $headerHtml = view()->make('pdf.header')->render();

                    // Generate cover PDF
                    $cover = PDF::loadView('pdf.cover', $coverData)
                        ->setOption('no-background', false)
                        ->setOption('background', true)
                        ->setOption('disable-javascript', true)
                        ->setOption('print-media-type', false)
                        ->setOption('margin-bottom', 0)
                        ->setOption('margin-left', 0)
                        ->setOption('margin-right', 0)
                        ->setOption('margin-top', 0)
                        ->save($exact_path.'/tmp/cover_'.$file_name_generated);
                    $coverUrl = storage_path($subfolder_path.'/tmp/cover_'.$file_name_generated);

                    // Generate Draft Care Plan PDF
                    $pdf = PDF::loadView('pdf.content', $pdfContentData)
                        ->setOption('margin-left','15')
                        ->setOption('margin-right','15')
                        ->setOption('margin-top','30')
                        ->setOption('margin-bottom','20')
                        ->setOption('header-html', $headerHtml)
                        ->setOption('footer-html', route('pdf.footer'))
                        ->save($exact_path.'/tmp/'.$file_name_generated);
                    $contentUrl = storage_path($subfolder_path.'/tmp/'.$file_name_generated);
                    $tempFolderPath = storage_path($subfolder_path.'/tmp_'.$draftId);

                    // Merge PDF
                    $newpdf = new PDFMerger();
                    $newpdf->addPDF($coverUrl, '1');
                    $newpdf->addPDF($contentUrl, 'all');
                    $newpdf->merge('file', $exact_path.'/'.$file_name_generated);

Thanks

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Any issues with PDF rendering itself that are not directly related to this package, should be reported on https://github.com/KnpLabs/snappy instead. When having doubts, please try to reproduce the issue with just snappy.
If you believe this is an actual issue with the latest version of laravel-snappy, please reply to this issue so we can investigate further.
Thank you for your contribution! Apologies for any delayed response on our side.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

joaomlopes picture joaomlopes  路  3Comments

closca picture closca  路  7Comments

zhuojiawei picture zhuojiawei  路  5Comments

MaximeDawn picture MaximeDawn  路  3Comments

LucasPantoja picture LucasPantoja  路  8Comments