TCPDF save page number in mysql

I am using tcpdf 6.2.13 to print mysql data into pdf format. I am creating custom index with school name and page number. For that i have fetched the mysql data in foreach loop and loading school id to store page number in mysql for that school.

Issue is using TCPDF to get the page number i am trying following code $pdf->getAliasNumPage() but when i try to store it in variable it shows empty.

Output: Day School{:pnp:}

If i remove exit and generate the pdf then it shows page number in pdf file like
Output: Day School 2

why $pdf->getAliasNumPage() showing {:pnp:} and not showing page number?
why it's value can not be stored in to variable or database?

Can anyone help me to get the page number in tcpdf to store in database? these function $pdf->getAliasNumPage() shows page number for pdf but when i pass it's value in mysql query or in variable it shows empty why?

Any help would be appreciated. Code:

   $pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
   $pdf->SetCreator(PDF_CREATOR);
    $pdf->SetAuthor('Nicola Asuni');
    $pdf->SetTitle('School DB');
    $pdf->SetSubject('TCPDF Tutorial');
    $pdf->SetKeywords('TCPDF, PDF, example, test, guide');
     $PgNo= $pdf->getAliasNumPage();
    $pdf->SetFont('dejavusans', '', 10);
    $rlt = $this->db->query("SELECT `school_pageno`,`school_country_id`,`school_state_id`,`school_city_id` FROM `school` where `school_country_id` = 2 group by `school_state_id`  order by `school_state_id` asc");
     $schoolquery = $rlt->result_array();
       foreach ($schoolquery as $key => $statevalue)
     {
     $html .= "<br/>". $statevalue['name'];
      $pnom =  $pdf->getAliasNumPage();
       $this->db->where('school_id', $statevalue['id']);
        $this->db->update('school', array('school_pageno' => $pnom));
      }
    //print_r($html);exit;
   $pdf->writeHTML($html, true, false, true, false, '');

Page number value doesn't work it shows {:pnp:} if i enable print_r.
qa testAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
Try TCPDF::PageNo()
1
Julian HansenCommented:
I am not sure what the question is
{:pnp:}

Is the correct output from that function based on the source.

This is a placeholder for the page number that is populated when the page is rendered out - I don't think it does what you think it does (want it to do)

I suspect you want $pdf->PageNo()
1
Ray PaseurCommented:
@Julian: Are you able to get to the online docs for TCPDF?  I tried to find the man page reference for the PageNo() method, and it looks like the TCPDF online docs may have been hacked.  Formatting was all bollixed up, links didn't work consistently, stray HTML, etc.  If you can find a working link to the PageNo() method, it might be helpful.  It returns the current page number as an integer, and tests out correctly in my examples.

This is the kind of thing I'm seeing:
https://tcpdf.org/docs/source_docs/functions_func_p/#index_p
0
Newly released Acronis True Image 2019

In announcing the release of the 15th Anniversary Edition of Acronis True Image 2019, the company revealed that its artificial intelligence-based anti-ransomware technology – stopped more than 200,000 ransomware attacks on 150,000 customers last year.

Julian HansenCommented:
@Julian: Are you able to get to the online docs for TCPDF?
No just get an error not found - had to browse the code to see how things worked.
0
Ray PaseurCommented:
Yeah, too bad about the docs.  It's an open source project; maybe someone will come to the rescue!
0
Brian TaoSenior Business Solutions ConsultantCommented:
@Ray and @Julian: The online doc was working well until this early morning.  I guess the author just updated it today, and messed up the links.
Those broken links can be "fixed" by changing the path "classTCPDF" to all lowercase and adding a "/" there.
from bad link:
https://tcpdf.org/docs/source_docs/classTCPDF#aa6e5b824889f7c484cc76ce1c134e2ed
to correct one:
https://tcpdf.org/docs/source_docs/classtcpdf/#aa6e5b824889f7c484cc76ce1c134e2ed
1
Julian HansenCommented:
Here is where I went
https://tcpdf.org/docs/
This page has an extra option at the top that is not visible in the links you provide. Link: Docs
Click on that - all you get is a Google Custom Search - type PageNo into that and you get results

The first result points to
https://tcpdf.org/docs/source_docs/classTCPDF/
Link broken
Change the capitals to lower case on TCPDF and the link works

So yes the documentation is there - just you have to have worked for Microsoft in order to be able to find it.
0
Ray PaseurCommented:
Nice catch, Brian.  In my tests these methods gave equivalent output.
// BURP OUT THE PAGE NUMBER
var_dump($pdf->PageNo());
var_dump($pdf->getPage());

Open in new window

0
qa testAuthor Commented:
@ray, @julian: Thanks for you reply,  if i type  PageNO()  then it return 3 for all schools  which is not correct.
here is my code;

$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
   $pdf->SetCreator(PDF_CREATOR);
    $pdf->SetAuthor('Nicola Asuni');
    $pdf->SetTitle('School DB');
    $pdf->SetSubject('TCPDF Tutorial');
    $pdf->SetKeywords('TCPDF, PDF, example, test, guide');
     $PgNo= $pdf->getAliasNumPage();
 $pdf->AddPage();
    $pdf->SetFont('dejavusans', '', 10);
    $rlt = $this->db->query("SELECT `school_pageno`,`school_country_id`,`school_state_id`,`school_city_id` FROM `school` where `school_country_id` = 2 group by `school_state_id`  order by `school_state_id` asc");
     $schoolquery = $rlt->result_array();
       foreach ($schoolquery as $key => $statevalue)
     {
     $html .= "<br/>". $statevalue['name'];
      $pnom =  $pdf->PageNo();
       $this->db->where('school_id', $statevalue['id']);
        $this->db->update('school', array('school_pageno' => $pnom));
      }
    //print_r($html);exit;
   $pdf->writeHTML($html, true, false, true, false, '');

As i entered PageNo(); it shows  following output:

school One 3
School two 3
School three 3

It's not showing correct page number.  i gone through all docs but failed to find a solution of it.
0
Ray PaseurCommented:
This is not a TCPDF problem; if it were, it would be immediately obvious, well-known and already fixed.  It's probably a logic error in your scripts.  You might consider getting a professional programmer to help you design this application.  E-E has "gigs."  I'd like to help, but I don't have your database to test with, so all I can do is show you how to move from page to page in the PDF document with addPage().  In the code example above, the script calls addPage() once, then uses the value from pageNo() to update the database.  My guess is that there is more to the application than we can see here.

This shows how the addPage() and pageNo() methods work.
https://iconoun.com/demo/temp_qa_test.php
<?php // demo/temp_qa_test.php
/**
 * Demonstrate page numbers in a TCPDF document
 *
 * TCPDF 6.2.13
 *
 * See http://www.tcpdf.org/doc/code/annotated.html ?
 */
error_reporting(E_ALL);

// LOAD THE TCPDF CLASS AND CONFIGURATION
require_once('tcpdf/config/tcpdf_config.php');
require_once('tcpdf/tcpdf.php');

// EXTEND THE TCPDF OBJECT SO WE CAN SUBSTITUTE OUR OWN METHODS
class PDF extends TCPDF { }

// INSTANTIATE THE OBJECT
$pdf = new PDF('P', 'mm', 'LETTER', true, 'UTF-8', false);

// ADD A PAGE AND SHOW THE PAGE NUMBER
$pdf->AddPage('P', 'LETTER', TRUE);
var_dump($pdf->PageNo());

// ADD ANOTHER PAGE
$pdf->AddPage('P', 'LETTER', TRUE);
var_dump($pdf->PageNo());

// ADD YET ANOTHER PAGE
$pdf->AddPage('P', 'LETTER', TRUE);
var_dump($pdf->PageNo());

Open in new window

Outputs:
int(1)
int(2)
int(3)

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ray PaseurCommented:
another abandoned question
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PDF

From novice to tech pro — start learning today.