We help IT Professionals succeed at work.

TCPDF save page number in mysql

qa test
qa test asked
on
587 Views
Last Modified: 2017-05-01
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.
Comment
Watch Question

Most Valuable Expert 2011
Author of the Year 2014
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2019
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
Most Valuable Expert 2011
Author of the Year 2014

Commented:
@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
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2019

Commented:
@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.
Most Valuable Expert 2011
Author of the Year 2014

Commented:
Yeah, too bad about the docs.  It's an open source project; maybe someone will come to the rescue!
Brian TaoOwner
CERTIFIED EXPERT
Top Expert 2014
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2019
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
Most Valuable Expert 2011
Author of the Year 2014
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

Author

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.
Most Valuable Expert 2011
Author of the Year 2014
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
Most Valuable Expert 2011
Author of the Year 2014

Commented:
another abandoned question

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions