Dompdf add line break after the end of each article and also in between article pages i content is long?

25 Views Asked by At

I want to add page breaks in between long article content with header and footer, also after each new article. I am basically creating an e-book with selected articles. E-book is being generated but the header and footer doesn't appear on the page having long article content. Please help me solve the same.

 $articles_ids = $request->selected_articles;
    $get_articles = Article::whereIn('id',$articles_ids)->get();
        
        $html = '<style>       
        @page {
            margin: 0cm 0cm;
        }
        /** Define now the real margins of every page in the PDF **/
        body {
            margin-top: 2cm;
            margin-left: 2cm;
            margin-right: 2cm;
            margin-bottom: 2cm;
        }
        /** Define the header rules **/
        header {
            position: fixed;
            top: 0cm;
            left: 0cm;
            right: 0cm;
            height: 2cm;
            /** Extra personal styles **/
            background-color: #03a9f4;
            color: white;
            text-align: center;
            line-height: 1.5cm;
        }
        /** Define the footer rules **/
        footer {
            position: fixed; 
            bottom: 0cm; 
            left: 0cm; 
            right: 0cm;
            height: 2cm;
            /** Extra personal styles **/
            background-color: #03a9f4;
            color: white;
            text-align: center;
            line-height: 1.5cm;
        }
        .article {
            /*page-break-after: always;*/
            page-break-after: always;
        }
        </style>';
        foreach($get_articles as $ga){
            $html .= '<div class="article"><header>Header</header>'.$ga->content.'<footer>Footer</footer></div>';
        }
    
        $filename = Slugify($request->ebook_title).'.pdf';
        $file = public_path('ebooks').'/'.$filename;
    
        Pdf::loadHTML($html)->setPaper('a4', 'portrait')->setWarnings(false)->save($file);

Generated PDF Screenshot:- enter image description here

0

There are 0 best solutions below