Output the page numbers of the PDF starting from the initial page and configure the footer

I've encountered an issue with my code. The first page is not numbered and the footer I have set appears as the header. Any suggestions on how to fix this?

      $full_name = 'custom_worksheets/' . $sheet_name . '.pdf';

        $pdf = new FPDI('P', 'mm', 'A4');
        $pdf->AliasNbPages();
        $pdf->AddPage();
        // set the sourcefile
        $pages_count = $pdf->setSourceFile($full_name);


        for ($i = 1; $i <= $pages_count; $i++) {
            //$pdf->AddPage(); 

            $tplIdx = $pdf->importPage($i);
    // Go to 1.5 cm from bottom
            $pdf->SetY(-31);
            // Select Arial italic 8
            $pdf->SetFont('Arial', 'I', 8);
            // Print centered page number
            $pdf->Cell(0, 10, 'Page ' . $pdf->PageNo() . ' of {nb}', 0, 0, 'C');
            $pdf->Cell(0, 10, date('d/m/Y'), 0, 0, 'R');
            $pdf->Cell(0, 0,$labref . '/' . ucfirst(str_replace('_', ' ', $sheet_name)) . ' / Download x : author - ' . $full_names,0,0);

            $pdf->useTemplate($tplIdx);




        }


       // Output
        $pdf->Output('generated_custom_sheets/' . $labref . '_' . $sheet_name . '.pdf', 'D');

        redirect('generated_custom_sheets/' . $labref . '_' . $sheet_name . '.pdf');

Answer №1

Your footer text may be causing your page to wrap or expand, leading it onto the next page. To prevent this, try adjusting the offset by setting it to -30:

$pdf->SetY(-30);

This adjustment can help avoid the text moving to the next page. If your PDF has already wrapped to the next page, consider placing the footer drawing logic above your template. This way, the footer is drawn first before the template sets to the top of the page for content writing. I always prioritize drawing headers and footers before adding content to my PDF pages.

Furthermore, I suggest switching from using Write to utilizing Cell, as Write is a free-flowing text object.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Transforming the add to cart button into a view button within the product listings: an easy guide

I am currently developing a unique ecommerce website called bookslab.in. To enhance the user experience, I would like to replace the "add to cart" button with a "view details" button when users view the list of available products. Furthermore, when users c ...

Establish and oversee remote connections for a variety of devices

I have a unique setup where I am using a cross domain and PHP server to retrieve user information when they log in. On my website, I incorporate PHP code that includes: session_start(); After a successful login, I declare the user information as follows: ...

jqgrid's date restriction is set to November 30th, 1999 at midnight

I have a table displaying DATETIME values. However, after editing the datetime value, it always changes to "1999-11-30 00:00:00", both in jqgrid and the database, regardless of the date entered. [Tue Mar 12 11:39:28 2013] [error] [client 171.43.1.4] PHP N ...

Creating a PHP session exclusively for a subdomain within a specific domain

I have a unique system where each client is assigned their own subdomain. Users are currently able to log in directly from their subdomain, but I am looking to enable login from the main domain as well before redirecting them to their respective subdomains ...

Troubleshooting Ajax: What's preventing me from fetching data from an external PHP file?

I've been working on developing a grade calculator application that incorporates ajax functionality. While the ajax feature appears to be functioning smoothly, I am encountering an issue with the separate PHP file 'response.php' not receivin ...

Show the most recent image from a folder in real-time

Looking for a solution to automatically display the latest image from a folder without refreshing the page? Check out this code snippet that achieves just that: <?php foreach (glob('/home/pi/camera/*.jpg') as $f) { $list[] = $f; } sort( ...

Transforming a Joomla template into a standard HTML template

I have a question about Joomla. Although I already have a Joomla template that was not originally intended for use with Joomla, I would like to utilize it as an HTML template so I can easily modify and edit it without using Joomla. Therefore, I am looki ...

execute php function when form is submitted

Hello, I am attempting to create a code using this PHP function: <?php function generateRandomString($length = 6) { return substr(str_shuffle(str_repeat($x='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', ceil($length/str ...

Retrieve the chosen selection from a dropdown menu using AngularJS and Ionic

I've been encountering some issues with the select feature in AngularJS. Despite searching extensively for solutions, none seem to be working for me. The JSON structure I'm dealing with is generated from my service.php: [ { "Name": ...

Tips for resolving an error in PHP and MYSQL code where data is being selected from the incorrect table in the database

I am working on a PHP code with MYSQL. It involves selecting data from the database using a dropdown list with AJAX and displaying the results on the screen. I have three dropdown lists that are dependent on each other and each dropdown has its own table t ...

Unable to output the string using htmlspecialchars

Oops! I made a mistake... just came across a JavaScript alert box! I just included htmlspecialchars. $src = './imgs/flag.jpg'; echo sprintf("<img alt=\"'.htmlspecialchars($name).'\" src=\"%s\" />", $src); I ...

How do I save basic information to a MySQL database with JQuery/AJAX in Symfony?

I am currently trying to save a basic piece of data (the file title) within a div element into a MySQL database. Can anyone help me identify any errors in my code? Below is the script I am using: $( document ).ready(function() { $( "#store-button" ). ...

Issue with Ajax Form Handling

I am struggling to get my ajax form post working correctly. It seems like there might be an issue with the $.ajax lines in my code. When the code reaches the $.ajax portion, the console.log() function stops working and the form redirects normally to the aj ...

What is the best way to design a content page with linked boxes to various arrays in PHP?

How can I create a PHP menu template that navigates to different pages? I am new to PHP and still learning. I want to achieve something similar to this image: https://i.stack.imgur.com/ylfe8.jpg I have the code for the navigation bar, but I need help crea ...

Converting a byte array to an image file using PHP

After receiving a JPEG byte array from Java SDK, I need to display that image using PHP. Is there a way to convert the byte array into a readable JPEG format for displaying it on a webpage? $byteArray = "[A@53d9e469"; //example of Java generated byte arr ...

Tips for deleting "Category: [category name]" in Wordpress

I have attempted various solutions found in previous threads, but none of them seem to work for me. Here is a screenshot I am looking to remove the text from the header in the category and only display [category name]. Can anyone assist me with this, ple ...

Having issues removing cookies, they refuse to be unset

I've been searching the php manual and internet for information on how to delete cookies, following the instructions I found: setcookie("name", '', 1); or setcookie("name", '', time()-3600); However, when I check the cookies in ...

Utilizing Bootstrap Modal to Display PHP Data Dynamically

Modals always pose a challenge for me, especially when I'm trying to work with someone else's code that has a unique take on modals that I really appreciate (if only I can make it function correctly). The issue arises when the modal is supposed ...

Obtain the unique identifier (ID) after successfully inserting data into a

I have a table structured like this: Person: -------------------- | Person | -------------------- | IDPerson | | IDName | | IDAddress | ------------------- Name: -------------------- | Name | ------------- ...

Fengyuanchen's jQuery cropper plugin: Ensuring Minimum Crop Validation

I'm currently using the fengyuanchen jquery cropper plugin (https://github.com/fengyuanchen/cropper) to crop my data output. I want to set a minimum size for the cropped area, but the plugin's options "minCropBoxWidth" and "minCropBoxHeight" only ...