To display how many pages are in this pdf you can actually use
$pdf->AliasNbPages('{customNb}');
$pdf->Cell(0, 10, 'Page '.$this->PageNo().'/{customNb}', 0, 0, 'C');
This should print something like e.g.
Page 1/5
What if i'm using a MultiCell, how can I use AliasNbPages there ?
$pdf->MultiCell(34, 5, 'Page '.$pdf->PageNo() . '/{customNb}');
This returns
Page 1/{customNb}
I tried to pass it like sample above, also as a part of a variable
$foo = 'Page '.$pdf->PageNo() . '/{customNb}';
$pdf->MultiCell(34, 5, $foo);
But this all is not working as expacted. Is there an other way to solve this ???
Ok, I guess I found a solution....
obviously there is a problem using custom name for pageiterator.
If I simply call
$pdf->AliasNbPages();
and than use
$pdf->MultiCell(34, 5, 'Page '.$pdf->PageNo() . '/{nb}');
everything works like expacted.
Related
I have a table generated pdf via fpdf and I needed something that will auto-wrap my cells if I need so I stumbled upon this: https://github.com/gemul/fpdf-multicell-table/blob/master/pdf_mc_table.php
With that, I have the following command for my page header:
function Header(){
$this->SetFont('Arial', 'B', 15);
$this->Cell(100,10,'Otaku Loaning Org', 0 , 1);
$this->Ln(5);
$this->SetWidths(Array(21,30,15,15,27,31,31,));
$this->SetLineHeight(5);
$this->SetFont('Arial', 'B', 12);
$this->SetFillColor(180,180,255);
$this->SetDrawColor(50,50,100);
$this->Row(Array(
'Date',
'Name',
'Trans ID',
'Loan ID',
'Interest Charge',
'Amount Paid',
'Total'
));
}
It currently looks like this:
However, as you can see I prepared a line of code for the Cells to be filled with a color. I would appreciate if someone could provide some insights because I tried adding a seventh parameter to line 60 and set it as true but to no avail. Thank you!
I am using TCPDF to create simple pdf document.
I am creating a page and adding link using below code
$pdf->addTOCPage();
$link = $pdf->AddLink();
$pdf->SetLink($link, 0, -1);
Now link is set successfull.But to navigate to that page what should I add ?
I tried below code , but it does nothing,
Return to TOC
// Create a fixed link to the first page using the * character
$index_link = $pdf->AddLink();
$pdf->SetLink($index_link, 0, '*1');
$pdf->Cell(0, 10, 'Link to INDEX', 0, 1, 'R', false, $index_link);
http://www.tcpdf.org/examples/example_045.phps
update -
refer to this function addHtmlLink() in tcpdf library.
You can add a internal link through this
$pdf->addHtmlLink('#'.$index_link, 'hello');
where 'hello' begin the name of anchor and and first param being identifier to the link.
In your case
$pdf->addHtmlLink('#'.$link, 'Whatever you like to name it');
$html = 'link name';
$pdf->writeHTML($html, true, false, true, false, '');
I'm using the follwing TCPDF code to generate PDFs with the writeHTML function. I have the page number footer function which puts page numbers at the bottom of each page as the pdf total pages grows. I'm trying to find a way at the end of creating all the pages to determine how many total pages the produced document has so that i can store that information into a variable and submit that data to a DB.
I've tried:
$total = $pdf->getAliasNbPages();
but doesnt work, Any ideas?
Thanks
// PAGE NUMBERED FOOTER
class MYPDF extends TCPDF {
// Page footer
public function Footer() {
// Position at 15 mm from bottom
$this->SetY(-15);
// Set font
$this->SetFont('Calibri', '', 8);
// Page number
$pageNumbers = 'Page '.$this->getAliasNumPage().' of '.$this->getAliasNbPages();
$this->Cell(0, 10, $pageNumbers, 0, false, 'C', 0, '', 0, false, 'T', 'M');
}
}
$html = 'html content';
$pdf->writeHTML($html, true, false, true, false, '');
$pdf->Output('file.pdf', 'I');
Use the getNumPages function instead:
$total = $pdf->getNumPages();
Note that this counts the amount of pages that have been created so far using the Addpage() function. So if you want the total amount of pages declare it after your last use of Addpage()
$pdf->Cell(0, 10,'{:ptp:}', 0, false, 'C', 0, '', 0, false, 'T', 'M');
To get the total number of pages, use $this->getAliasNbPages() as chown in this example https://tcpdf.org/examples/example_003/
I'm using the TCPDF library to generate PDFs with PHP/HTML. The docs can be found here: http://www.tcpdf.org/doc/code/classTCPDF.html.
I am trying to create a table of contents (as demonstrated in example 59 on the TCPDF site) but I'm experiencing a few issues:
1) The Table of Contents page number is showing as the last page of the document. (8 of 8 when in reality it's 2 of 8, comes after a cover page).
2) The page numbers on the other pages are not adjusting. The page after the TOC should be 3 of 8, but instead says 2 of 8.
3) The table of contents has the correct page numbers for the bookmarks, but these numbers don't match the page numbers on those pages (related to issue #2).
How I'm generating bookmarks:
I'm generating bookmarks for each page by calling the Bookmark() method after each added page.
$pdf->AddPage();
$pdf->Bookmark('Chapter 1', 0, 0, '', 'B', array(0,64,128));
How I'm generating the table of contents:
This is ripped directly from Example 59 linked above. In that example, the scenario is slightly different as it does not have a cover page.
// add a new page for TOC
$pdf->addTOCPage();
// write the TOC title and/or other elements on the TOC page
$pdf->SetFont('times', 'B', 16);
$pdf->MultiCell(0, 0, 'Table Of Content', 0, 'C', 0, 1, '', '', true, 0);
$pdf->Ln();
$pdf->SetFont('helvetica', '', 10);
// define styles for various bookmark levels
$bookmark_templates = array();
/*
* The key of the $bookmark_templates array represent the bookmark level (from 0 to n).
* The following templates will be replaced with proper content:
* #TOC_DESCRIPTION# this will be replaced with the bookmark description;
* #TOC_PAGE_NUMBER# this will be replaced with page number.
*
* NOTES:
* If you want to align the page number on the right you have to use a monospaced font like courier, otherwise you can left align using any font type.
* The following is just an example, you can get various styles by combining various HTML elements.
*/
// A monospaced font for the page number is mandatory to get the right alignment
$bookmark_templates[0] = '<table border="0" cellpadding="0" cellspacing="0" style="background-color:#EEFAFF"><tr><td width="155mm"><span style="font-family:times;font-weight:bold;font-size:12pt;color:black;">#TOC_DESCRIPTION#</span></td> <td width="25mm"><span style="font-family:courier;font-weight:bold;font-size:12pt;color:black;" align="right"> #TOC_PAGE_NUMBER#</span></td></tr></table>';
$bookmark_templates[1] = '<table border="0" cellpadding="0" cellspacing="0"><tr><td width="5mm"> </td><td width=" 150mm"><span style="font-family:times;font-size:11pt;color:green;">#TOC_DESCRIPTION#</span></td><td width="25mm"><span style="font-family:courier;font-weight:bold;font-size:11pt;color:green;" align="right">#TOC_PAGE_NUMBER#</span></td></tr ></table>';
$bookmark_templates[2] = '<table border="0" cellpadding="0" cellspacing="0"><tr><td width="10mm"> </td><td width=" 145mm"><span style="font-family:times;font-size:10pt;color:#666666;"><i>#TOC_DESCRIPTION#</i></span></td><td width="25mm "><span style="font-family:courier;font-weight:bold;font-size:10pt;color:#666666;" align="right">#TOC_PAGE_NUMBER#</span ></td></tr></table>';
// add other bookmark level templates here ...
// add table of content at page 1
// (check the example n. 45 for a text-only TOC
$pdf->addHTMLTOC(2, 'INDEX', $bookmark_templates, true, 'B', array(128,0,0));
// end of TOC page
$pdf->endTOCPage();
How I'm getting the page numbers for the footers:
// Page footer
public function Footer() {
$pageN = $this->PageNo();
if($pageN === 1){
// Do nothing
} else {
// Position at 15 mm from bottom
$this->SetY(-15);
// Set font
$this->SetFont($helvetica_light, '', 10);
$this->setTextColor(255,255,255);
// Page number
$this->Cell(0, 12, ' '.$this->PageNo().' of '.$this->getNumPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
}
}
Basically, I'd like the Table of Contents to fall on page 2, with a footer that says Page 2, all subsequent page numbers to be labeled correctly. How can I do this? I can clarify the question/code if needed.
Any help is appreciated :)
PageNo() is a bit funky when it comes to calculating pages. It outputs what page it is in order of creation, and since the ToC page is created as the very last it will show that as the last page.
So instead use
// Page number
$this->Cell(0, 12, ' '.$this->getAliasNumPage().' of '.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
The rest of the code you provided, like the check if it is the first page, should work with PageNo().
I am unsure if I am going about this correctly. Why using TCPDF when I attempt to post it returns an empty textfield?
$pdf->Cell(35, 5, 'Job Number ');
$pdf->TextField($_POST["jobnum"], 50, 5);
You need to use the fourth $opt parameter see the TCPDF TextField reference and Acrobat API Reference
$pdf->TextField("jobnum", 50, 5, array(), array('v'=>$_POST["jobnum"] ) );
TCPDF requires the TextField() function to be like so: TextField("string", number, number)
so you need to make it like this:
$pdf->TextField("'".$_POST["jobnum"]."'", 50, 5);