Attach footer at very bottom to every page in tcpdf - yii

I need to attach footer at the very bottom of every page. I am using tcpdf for generating pdf's. i tried many solution on google but did not found any luck. My current framework is yii and i am using tcpdf extension.

you need to write Footer method in your class for example
// Page footer
public function Footer() {
// Position at 15 mm from bottom
$this->SetY(-15);
// Set font
$this->SetFont('helvetica', 'I', 8);
// Page number
$this->Cell(0, 10, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
}

Well, if you're subclassing the tcpdf class, just add a public function Footer() in which you do your stuff. It might help to set the bottom page margin to a sensible value before doing the content work, so that the Footer function has "space" to put in the footer.

why don't you try mpdf extension i am not sure if you can get its library for yii but it has one for codeigniter and it is awesome converts css + Html to pdf accurately.

Related

TCPDF Spotcolor specific for SVG

I would like to put a specific color to a svg that i insert in a PDF thanks to TCPDF
this color will allow a printer to cut automatically
I know i would have to use spotcolors.
as here: https://tcpdf.org/examples/example_037/
the SetFillSpotColor function works perfectly for text or a rectangle
but when I use ImageSVG this has no effect
i add name CutContour directly in svg, example :
<path fill="CutContour" d="M271.44,849.229c-1.254,0.174-2.604,0.489-3,0.701...
but not works too.
example my code PHP:
$pdf->AddSpotColor('CutContour', 0, 0, 0, 100);
$pdf->ImageSVG( $filename_svg , 0, 0, $largeurmm, $hauteurmm, 'CutContour', false, false, 0, false);
I can't find a solution,
can you help me?
I'm guessing you can't get away with using cutcontour as the spot color name, correct? The ImageSVG parser appears to force the color name to lowercase, which means it doesn't match against the CutContour name when it goes to look for it in the TCPDF instance's list of added spot colors.
If that guess is correct, try adding the color to the predefined list in the TCPDF_COLORS class (see spotcolor static property), either by editing include/tcpdf_colors.php or adding a line like this to your script.
TCPDF_COLORS::$spotcolor['cutcontour'] = array( 0, 0, 0, 100, 'CutContour');
$pdf->AddSpotColor('CutContour', 0, 0, 0, 100);
This way, when it goes to look for the lowercase name, it'll find a match and return the proper spot color array. (Note: Tested in TCPDF 6.2.17)

How to create pdf file of the webview content in titanium

I am new to Titanium. I have a webview. The content of the webview can be a pdf file, or a url. I want to save the webview content as a pdf file. I have created webview using the below code:
var webViews = Ti.UI.createWebView({
left : 0,
top : 0,
right : 0,
bottom : 0,
url : 'http://www.appcelerator.com'
});
Please anyone help me out...
You cant directly convert the webview data in pdf but you have to first parse html and then use the js pdf to create the pdf.Here is the code with example
https://github.com/Mindelusions/TiJSPDF
Thanks

DOMPDF: page_script(): Check current page content?

I am using dompdf to generate reports which sometimes has a front page, and sometimes has some attachments. The main content has a header and a footer, but the front page and the attachments (the last 3 to 5 pages of the pdf) should not contain header and footer. I'm placing the header and footer with a inline php page_script(), like this:
<script type="text/php">
if (isset($pdf) ) {
$pdf->page_script('
if ( $PAGE_COUNT > 10 && $PAGE_NUM == 1) {
//front page footer
}else{
//other pages' header and footer
}
');
}
</script>
The whole report is built by a database engine which outputs it all as a temporary html.txt-file which is then read into DOMPDF.
Now, to recognize the front page I just have to check if the page number is = 1. If any attachments are added (which are comprised of 1000px-height jpg images, each on their own page)
Does anyone have an idea for how to identify these "attachment"-pages and get DOMPDF to not render a header and footer on those pages? Or is there any way I could check within the page_script()-script whether the current page contains only an image (or perhaps an image with a specific class or identifier)?
Thanks for any help,
David
Detecting the current page contents may be possible, but I'd have to research exactly what you can do at this level. An easier method would be if you could inject some inline script in your generated document. After the main content and before the attachments you could add something like $GLOBALS['attachments'] = true; and then add a check on the status of this variable to your conditional.
<script type="text/php">
if (isset($pdf) ) {
$pdf->page_script('
if ( $PAGE_COUNT > 10 && $PAGE_NUM == 1) {
//front page footer
}elseif ($GLOBALS['attachments']) {
//attachments actions
}else{
//other pages' header and footer
}
');
}
</script>
Of course, don't forget to initialize the variable to false at the top of the document.
(from https://groups.google.com/d/topic/dompdf/mDsYi8Efnhc/discussion)

TCPDF with FPDI templates and THEAD

I have a html table with THEAD output with writeHTML which should be displayed on every page at the top of the table. It works but when I use a template loaded by FPDI the head is white and disappears on the second page and further. I can mark the head field with the mouse but the appear white. The border only appears as a little point on the left.
I already tried to add $this->setPageMark() to the addPage method. But its still the same issue.
public function AddPage($orientation = '', $format = ''){
parent::AddPage($orientation, $format);
if($this->template != null){
$this->useTemplate($this->template);
$this->setPageMark();
}
}
you need to enable page breaks at the beginning which is causing the issue you are having;
this is a sample code snippet ;
require_once('tcpdf/tcpdf.php'); //main code
require_once('tcpdf/fpdi.php'); //read existing pdf and sends to fpdf
$pdf = new FPDI();
$pdf->setPrintHeader(false); //no header
$pdf->setPrintFooter(false);//no footer
$pdf->SetAutoPageBreak(FALSE, 0); // set auto page breaks
//loop starts here
{
$pdf->setSourceFile($page_background); //set page
$templateId = $pdf->importPage(1); //we only need the first page
$pdf->useTemplate($templateId); //use the imported page
//your write html code and any other tcpdf related code comes here
}
$pdf->Output(outcome.pdf, 'I'); //use F instead of I to show generated pdf.

iText Pdf Header Removal for particular page

I'm generating a PDF with iText, in that I'm displaying a header and footer.
Now i want to remove header for a particular page.
For eg: If I'm generating a 50 pages pdf, for the final 50th I don't want to show header,
how could this be achieved?
Here's my code where I'm generating footer (header part removed).
public class HeaderAndFooter extends PdfPageEventHelper {
public void onEndPage (PdfWriter writer, Document document) {
Rectangle rect = writer.getBoxSize("art");
switch(writer.getPageNumber() % 2) {
case 0:
case 1:
ColumnText.showTextAligned(writer.getDirectContent(),
Element.ALIGN_CENTER, new Phrase(String.format("%d", writer.getPageNumber())),
300f, 62f, 0);
break;
}
}
}
Any suggestions? Thanks in advance.
You can use a 2-pass approach:
1st pass : generate the PDF file without header
2nd pass : stamp the header on all but the last page
Have a look at this example taken from the iText book. You'll just have to adapt the second pass by only going through the N-1 first pages:
int n = reader.getNumberOfPages() - 1;
instead of
int n = reader.getNumberOfPages();
I was also in need to do the same. I want to share how I resolved this issue.
The Idea is, for the automatic generation of header footer, we set page event on PDFWriter like:
HeaderAndFooter event= new HeaderAndFooter(); //HeaderAndFooter is the implementation of PdfPageEventHelper class
writer.setPageEvent(event);// writer is the instance of PDFWriter
So, before the content of the last page, We can remove the event:
event=null;
writer.setPageEvent(event);
It works for me without any error or exception.