Getting total page count from outside

5,871 views
Skip to first unread message

Nikita Savik

unread,
Jan 22, 2014, 10:53:31 PM1/22/14
to dom...@googlegroups.com
Hello!

Here is the question: I need to get total page count from the generated pdf in the PHP script.

e.g.
$dompdf = new DOMPDF();
$dompdf->set_paper("a5","portrait");
$dompdf->load_html($html,'UTF-8');
$dompdf->render();
$pdf = $dompdf->output();

file_put_contents("test.pdf", $pdf);
echo "TotalPages ".$dompdf->get_page_count();

get_page_count is not working (taken from cpdf_adapter docs), Is there anything I can use instead of this?

Thanks in advance

BrianS

unread,
Jan 22, 2014, 10:57:53 PM1/22/14
to dom...@googlegroups.com
You're close. The canvas object is defined as a property of the dompdf object. So the actual call is $dompdf->get_canvas()->get_page_count().

Nikita Savik

unread,
Jan 22, 2014, 11:04:29 PM1/22/14
to dom...@googlegroups.com
Thanks a lot!

rath...@zhservices.com

unread,
Mar 21, 2014, 5:26:49 AM3/21/14
to dom...@googlegroups.com
HI do you know the same in ZF2 ?? I am using dompdf with ZF2 but i dont knw how to get the tottal page number in pdf I tried a lot but didnt get any thing .. Current page number got via css but total is not . please help me ...

BrianS

unread,
Mar 21, 2014, 11:01:08 AM3/21/14
to dom...@googlegroups.com
Are you trying to retrieve the total page number externally from the PDF? Or do you want to write out the total number of pages inside the PDF (e.g. in a header/footer)?

Ratheesh R

unread,
Mar 22, 2014, 12:00:33 AM3/22/14
to dom...@googlegroups.com
Hii thank you very much for replying me .   Exactly I m trying to get the total page number inside the pdf  . (header/footer) . I get the current page number using the css property " counter(page) " but unable to retrieve the total number of pages using " counter(pages) "   . Is there any way to get this using zf2 dompdf module ??  .


--
You received this message because you are subscribed to a topic in the Google Groups "dompdf" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/dompdf/8BhTBiabR2w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to dompdf+un...@googlegroups.com.
To post to this group, send email to dom...@googlegroups.com.
Visit this group at http://groups.google.com/group/dompdf.
For more options, visit https://groups.google.com/d/optout.



--

Thanks &  Regards

Ratheesh R
Software Engineer
ZH Healthcare
Cochin
Mob : 9747 333 543



Ratheesh R

unread,
Mar 22, 2014, 12:05:04 AM3/22/14
to dom...@googlegroups.com
Here is my code :

controller

 public function somePdfAction()
  {
    $labOrderid = $this->params('id');
    global $pid;   
    $pdf = new PdfModel();
    $pdf->setOption('filename', 'requistion' . $labOrderid); // Triggers PDF download, automatically appends ".pdf"
    $pdf->setOption('paperSize', 'a4'); // Defaults to "8x11"
    $pdf->setOption('paperOrientation', 'portrait'); // Defaults to "portrait"
 
    // To set view variables
    $pdf->setVariables(array(
     'someData' => $someData

    ));

    return $pdf;
  }

pdfView.phtml

  @page {
    margin: 170px 50px 0px 50px;
    counter-increment: page;
    counter-reset: page 1;
  }
  #header { position: fixed; left: 0px; top: -160px; right: 0px; height: 100px; text-align: center; background-color: white }
  #footer { position: fixed; left: 0px; bottom: 30px; right: 0px; height: 50px; background-color: white; }
  #content { padding: 0px; margin: 0px}
  #footer .page:after { content: "*****For Illustration Purposes Only****"}
  #header .page:after { content: "Page " counter(page);}


...... etc




BrianS

unread,
Mar 24, 2014, 10:03:33 AM3/24/14
to dom...@googlegroups.com
Unfortunately dompdf does not yet support displaying the total page count using CSS. Until that functionality is available you would have to use inline script to display the total number of pages.

Ratheesh R

unread,
Mar 25, 2014, 12:33:23 AM3/25/14
to dom...@googlegroups.com
HI Brian

 I m trying to use the total number of page with zend frame work 2 . In ZF2 they use the dompdf model objects . So i didnt find how to use the inline php scripts with ZF2 . I saw that there are some function inside the dompdf moule libke  get_canvas()->get_page_num(), getcanvas->get_page_count() etc ... I serached a lot to get some to use it but i failed to impliment the same with ZF2 . If you have any idea to use this with ZF2 please share with me .. still i m stuck with this area .. Also I m a newbie in ZF2 .. Thanks a lot ....

BrianS

unread,
Mar 26, 2014, 1:24:14 PM3/26/14
to dom...@googlegroups.com
Inline script is PHP code placed inside your HTML document, surrounded by <script type="text/php"></script> tags. Here's a question on StackOverflow that covers the basics:
http://stackoverflow.com/questions/7484318/header-in-pdf-page-using-dompdf-in-php

If that doesn't get you started post back and I'll provide more detail.

Ratheesh R

unread,
Mar 27, 2014, 8:28:22 AM3/27/14
to dom...@googlegroups.com
hi Brian the illustrated things are working with core php .. these did not work with ZendFramework2 .  But I need to work the same with dompdf in ZendFramework2 .

The following is my code :

At the top of the controller i have use the line like

use DOMPDFModule\View\Model\PdfModel;

 public function myPdfAction()

  {
    $labOrderid = $this->params('id');
    global $pid;   
    $pdf = new PdfModel();
    $pdf->setOption('filename', 'requistion' . $labOrderid); // Triggers PDF download, automatically appends ".pdf"
    $pdf->setOption('paperSize', 'a4'); // Defaults to "8x11"
    $pdf->setOption('paperOrientation', 'portrait'); // Defaults to "portrait"
   
  
    // To set view variables
    $pdf->setVariables(array(
      'var1' => $var1,
      'var2' => $var2,
      'var3' => $var3,
     

    ));
    return $pdf;
  }


In my  view there is corrospnding HTML codes ..

the pdfview.phtml file will render to pdf document . Here I need to display the total number of pages .



Thnk u Brian to keep continues replies .. thanks a lot ...



BrianS

unread,
Mar 27, 2014, 3:27:47 PM3/27/14
to dom...@googlegroups.com
What do you mean that they do not work in ZF2? dompdf should render the document independent of any ZF2 functionality, it's basically a stand-along library wrapped in a ZF2 module. If inline script isn't working you might check your configuration file.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages