• I’m trying to format my template. I’ve tried what seems to be the correct init (below), but it doesn’t work. Does your plugin work differently?
    Thanks

    <?php
        global $post;
    
        // Initialize mPDF with zero margins
        $mpdf = new \Mpdf\Mpdf([
            'margin_left' => 0,
            'margin_right' => 0,
            'margin_top' => 0,
            'margin_bottom' => 0,
            'margin_header' => 0,
            'margin_footer' => 0
        ]);
    
        // Fetch ACF fields
        $acf_property_types = get_field('acf_property_types');
        $acf_location = get_field('acf_location');
        $acf_email = get_field('acf_email');
        $acf_phone = get_field('acf_phone');
        $acf_fax = get_field('acf_fax');
        $acf_qrcode = get_field('acf_qrcode');
        $acf_qrcode_url = $acf_qrcode ? $acf_qrcode['url'] : '';
    
        // Convert featured image URL from https to http
        $featured_image_url = get_the_post_thumbnail_url($post, 'full');
        $featured_image_url = str_replace('https://', 'https://', $featured_image_url);
    
        // Build the HTML output
        $pdf_output = '<!DOCTYPE html>
            <html xml:lang="en">
            <head>
                <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
                <title>' . get_the_title() . '</title>
            </head>
            <body xml:lang="en">
                <div class="featured-image" style="background-image: url(\'' . $featured_image_url . '\');">
                    <h1 class="title">' . get_the_title() . '</h1>';
    
                    if ($acf_property_types) {
                        $pdf_output .= '<ul class="property-types">';
                        foreach ($acf_property_types as $type) {
                            $pdf_output .= '<li>' . esc_html($type) . '</li>';
                        }
                        $pdf_output .= '</ul>';
                    }
    
                    if ($acf_location) {
                        $pdf_output .= '<p class="location"><img src="path/to/map-icon.jpg" alt="Location Icon" />' . esc_html($acf_location) . '</p>';
                    }
    
                    if ($acf_email) {
                        $pdf_output .= '<p class="email"><img src="path/to/email-icon.jpg" alt="Email Icon" />' . esc_html($acf_email) . '</p>';
                    }
    
                    if ($acf_phone) {
                        $pdf_output .= '<p class="phone"><img src="path/to/phone-icon.jpg" alt="Phone Icon" />' . esc_html($acf_phone) . '</p>';
                    }
    
                    if ($acf_fax) {
                        $pdf_output .= '<p class="fax">' . esc_html($acf_fax) . '</p>';
                    }
    
                    if ($acf_qrcode_url) {
                        $pdf_output .= '<img class="qrcode" src="' . esc_url($acf_qrcode_url) . '" alt="QR Code" />';
                    }
    
                    $pdf_output .= '<div class="content">' . apply_filters('the_content', get_post_field('post_content', $post->ID)) . '</div>';
                
                $pdf_output .= '</div>
                <footer class="footer">
                    <img class="logo" src="path/to/logo.jpg" alt="Company Logo" />
                </footer>
            </body>
        </html>';
    
        // Write the HTML to the PDF and output it
        $mpdf->WriteHTML($pdf_output);
        $mpdf->Output();
    ?>
    
Viewing 1 replies (of 1 total)
  • Plugin Author fkrauthan

    (@fkrauthan)

    Hi, I don’t fully understand what you are doing there as this does not seem to be a wp-mpdf template (the code snippet posted above).

Viewing 1 replies (of 1 total)
  • The topic ‘Initialize mPDF without Margins’ is closed to new replies.