Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8551905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:18:06+00:00 2026-06-11T14:18:06+00:00

So, I’m using fpdi , version 1.2 to add some little mark to every

  • 0

So, I’m using fpdi, version 1.2 to add some little mark to every page in my document. Here is my code:

public static function markPdf($file, $text){
    define('FPDF_FONTPATH','font/');
    require_once('fpdi/fpdf.php');
    require_once('fpdi/fpdi.php');
    try{
        $pdf = new FPDI();
        $pagecount = $pdf->setSourceFile($file);
        for($i = 1 ; $i <= $pagecount ; $i++){
            $tpl  = $pdf->importPage($i);
            $size = $pdf->getTemplateSize($tpl);

            // Here you can see that I'm setting orientation for every single page,
            // depending on the orientation of the original page
            $orientation = $size['h'] > $size['w'] ? 'P':'L';
            $pdf->AddPage($orientation);
            $pdf->useTemplate($tpl);

            $pdf->SetXY(5, 5);
            $pdf->SetTextColor(150);
            $pdf->SetFont('Arial','',8);
            $pdf->Cell(0,0,$text,0,1,'R');
        }
        $pdf->Output($file, "F");
    }catch(Exception $e){
        Logger::log("Exception during marking occurred");
        return false;
    }
    return true;
}

And everything works just fine, except for one little issue: when I have a document with first page in landscape orientation, all pages in generated document are cropped from the bottom and right (if the first page is in portrait mode, everything goes just fine, even if following pages are in landscape mode).
The question is obvious: what’s wrong with this function?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T14:18:07+00:00Added an answer on June 11, 2026 at 2:18 pm

    The last argument to useTemplate() specifies whether to adjust page size. It defaults to false, but we want it to be true.

    Change this call:

    $pdf->useTemplate($tpl);
    

    to (for older fpdf versions):

    $pdf->useTemplate($tpl, null, null, $size['w'], $size['h'], true);
    

    or (for newer fpdf versions):

    $pdf->useTemplate($tpl, null, null, $size['width'], $size['height'], true);
    

    Consider updating all fpdf-related libraries (fpdf, fpdf_tpl and fpdi) to the most recent versions – that’s important, too.

    P.S.: When pushing new version of fpdi on testing server, I found that it doesn’t work with relatively old versions of PHP interpreter – it does work with version 5.3.10, but it can’t work with 5.3.2 or older. So, make sure that you have an up-to-date PHP version too.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm making a simple page using Google Maps API 3. My first. One marker
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.