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

dompdf page numbering and cover image for html content exceeding one print page. #6305

Open
solmazb128 opened this issue Oct 21, 2024 · 1 comment

Comments

@solmazb128
Copy link

Hi everyone.
i fetched some html content from phpmyadmin sql table and print them to pdf by dompdf in my codeigniter 3 project.
here, i have some columns (page titles) with some html content which could exceed one print page (A4 landscape).
as well i add page number or background cover for pages, but just the first page in each column content has cover image and just the last page has footers for page number.
here is the function i used to create html content for dompdf:
PHP Code:

    // Helper function to generate page HTML with title
    public function generatePageHtml($name,$title1, $title2 = null, $title3 = null, $content, $image_path, $page_number=null) {
        $html = '<div style="position: relative; width: 100%; height: 100%; page-break-after: always; margin: 0; padding: 0;">';
        $html .= '<style>@page { margin: 0; }</style>';
    
        if ($image_path && file_exists($image_path)) {
            $image = file_get_contents($image_path);
            $base64 = 'data:image/jpeg;base64,' . base64_encode($image);
            $html .= '<img src="' . $base64 . '" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: -1; object-fit: cover; margin: 0; padding: 0;">'; // opacity: 0.7;
        }
    
        $html .= '<div style="padding: 20px; position: relative; z-index: 1; margin: 0;">';
        $html .= '<h1 style="text-align: center; text-decoration: underline; margin: 0;">' . $title1 . '</h1>';
    
        if ($title2) {
            $html .= '<h2 style="text-align: center; margin: 0;">' . $title2 . '</h2>';
        }
        if ($title3) {
            $html .= '<h3 style="text-align: center; margin: 0;">' . $title3 . '</h3>';
        }
    
        $html .= $content;
        $html .= '</div>';
        $html .= '<div style="position: absolute; bottom: 20px; left: 20px; font-size: 12px; font-weight: bold;font-style: italic; color: gray;"> '. $name .' - '. $title1. ' - '. $title2. '</div>';

        if ($page_number !== null) {
            $html .= '<div style="position: absolute; bottom: 20px; right: 10px; font-size: 12px; font-weight: bold; color: gray;border: 1px solid black; padding: 10px; display: inline-block; border-radius: 3px;"> '.$page_number . '</div>';
        }
        $html .= '</div>';
        return $html;
    } 

how should i consider coding so that when a html content exceeds one print page, the next pages of same content as well has cover image and page numbering for all.

@jamieburchell
Copy link
Contributor

jamieburchell commented Oct 22, 2024

Hi @solmazb128

This area is for reporting bugs with CodeIgniter 3.

You can ask any question relating to Dompdf on StackOverflow or in Discussions. Also see the Dompdf GitHub page.

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

3 participants
@jamieburchell @solmazb128 and others