Tcpdf multiple bookmarks on single page - php

Is it possible to have PDF with multiple Bookmarks on one page? I have a page with multipe tables, and each table need to be bookmarked. These tables may increase and go on next page.

The documentation supports explains how to do this here.
The syntax is as follows:
// Bookmark($txt, $level=0, $y=-1, $page='', $style='', $color=array(0,0,0))
$pdf->AddPage();
$pdf->Bookmark('Paragraph 1.1', 1, 0, '', '', array(0,0,0));
$pdf->Cell(0, 10, 'Paragraph 1.1', 0, 1, 'L');
$pdf->Bookmark('Paragraph 1.2', 1, 0, '', '', array(0,0,0));
$pdf->Cell(0, 10, 'Paragraph 1.2', 0, 1, 'L');

Related

Tcpdf writeHTMLCell without overlapping boxes

I am creating a pdf with text images (1 image per page), and I need to add some boxes to the left and/or right of the image explaining some expressions from the image (using specific Y coordinates)
the problem is that sometimes the expressions are on the same row, and if I use the same Y coordinate when using writeHTMLCell or any other method that uses the Y as parameter, they will overlap
My question is .. is there a way of adding multiple boxes, without them overlapping?
$pdf->writeHTMLCell(50, 0, '', '10', 'First box', 1, 1, 0, true, 'J');
$pdf->writeHTMLCell(50, 0, '', '20', 'Second box', 1, 1, 0, true, 'J');
$pdf->writeHTMLCell(50, 0, '', '21', 'Third box', 1, 1, 0, true, 'J');
$pdf->writeHTMLCell(50, 0, '', '35', 'Fourth box box', 1, 1, 0, true, 'J');
$pdf->writeHTMLCell(50, 0, '', '38', 'Fifth box box', 1, 1, 0, true, 'J');

How to add a custom paper size on FPDF?

I am using FPDF to create a document. My problem is the paper size requirement is 8.5 by 13 inches. Is there a way to add a custom page size. I tried searching still no avail. When I used 'Legal' the printing is warped.
$pdf = new myPDF('P','in',[8.5,13]);
$pdf->AddPage('P', 'Legal', 0);
$pdf->SetMargins('15', '20', '15');
$pdf->SetFont('Arial', 'B', 12);
$pdf->Ln(5);
$pdf->Cell(0, 5, 'PAGE 1', 0, 1, 'C');
$pdf->AddPage('P', 'Legal', 0);
$pdf->Cell(0, 5, 'PAGE ', 0, 1, 'C');
As the documentation says, when you create the instance the 3rd parameter may be an array that specifies the width and height. So you may use:
$pdf = new myPDF('P','in',[8.5,13]);

FPDF Put Header + Styling on Auto Page Break Pages

I'm using $pdf->SetAutoPageBreak(true); to auto break long outputs over multiple pages but I have some styling that I would like to apply to the auto-created pages:
// HEADER ------------------------------------------------------------------
$pdf->SetTextColor( $headerColour[0], $headerColour[1], $headerColour[2] );
$pdf->SetFont( 'Arial', '', 17 );
$pdf->Cell( 0, 15, $reportName, 0, 0, 'C' );
$pdf->Ln( 16 );
$pdf->SetLineWidth(7);
$pdf->SetDrawColor($col_r, $col_g, $col_b);
$pdf->Line(0, 0, 0, 300);
$pdf->SetLineWidth(0.5);
$pdf->Line(20, 26, 210-20, 26);
$pdf->SetTextColor( 0,0,0 );
$pdf->SetFont( 'Arial', 'B', 24 );
$pdf->Cell( 0, 15, 'Results', 0, 0, 'C' );
$pdf->Line(20, 40, 210-20, 40);
$pdf->Ln( 16 );
$pdf->Write( 6, $file ); // This is about 3 pages long worth of text
This adds a header-style block to the top of the page as well as a border on the left hand side all the way down the page. How can I replicate this on each page when the data is too big?
You can create extend class to automatically create the header.
Please check the example at http://www.fpdf.org/en/tutorial/tuto2.htm OR FPDF Tutorial for more information for the others sample.

Radio button groups generated with TcPDF cutting off in adobe reader

I'm using TcPDF to generate a PDF file with radio button groups in it.
When one of these crosses over to the next page the labels remain but the radio button itself disappears. This only happens in Adobe Reader and not in any of my other readers like Firefox / Chrome / Foxit.
$this->ln(5);
$this->MultiCell(0, 5, '4. Question1', 1, 'L', 1, 1);
$this->Ln(3);
$val[$answers['v4']] = true;
$this->radio('v4', $val['good_verygood']);
$this->Cell(50, 0, 'Good/very good', 0, 0, 'L', 0);
$this->Cell(150, 0, '(= luxe)', 0, 1, 'L', 0);
$this->radio('v4', $val['above_average']);
$this->Cell(50, 0, 'Above average', 0, 0, 'L', 0);
$this->Cell(150, 0, '(= modernised)', 0, 1, 'L', 0);
$this->radio('v4', $val['average']);
$this->Cell(50, 0, 'Average', 0, 0, 'L', 0);
$this->Cell(150, 0, '(= on par)', 0, 1, 'L', 0);
$this->radio('v4', $val['moderate']);
$this->Cell(50, 0, 'Moderate', 0, 0, 'L', 0);
$this->Cell(150, 0, '(= not on par)', 0, 1, 'L', 0);
$this->radio('v4', $val['bad']);
$this->Cell(50, 0, 'Bad', 0, 0, 'L', 0);
$this->Cell(150, 0, '(= Needs short term maintenance)', 0, 1, 'L', 0);
$val[$answers['v4']] = false;
I've fixed one of these PDF's quickly by just adding a new page on the one question this happened
$this->addPage();
But now there are dozens of occurences in multiple PDF's.
I've found a solution.
Although I do not know why only Adobe has this problem and only if the group of buttons is on a page break, the problem is the name of the radio button.
In my example the buttons are all named v4.
If you name them v4.1 through v4.5 or other unique names, the PDF renders correctly.

TCPDF font spacing too wide

I have this code that has worked in the past:
$pdf = new TCPDF('L', 'In', 'LETTER', true);
$pdf->SetPrintHeader(false);
$pdf->SetPrintFooter(false);
$pdf->SetFont('Times','B',11);
$pdf->AddPage();
$pdf->SetLeftMargin(0.5);
$pdf->SetLineWidth(.04);
$pdf->Rect(.5, .5, 10, 7.5);
$pdf->SetLineWidth(.01);
$pdf->Rect(.55, .55, 9.89, 7.39);
$pdf->setFont('Times', 'BI', 31);
$pdf->SetXY(0.5,0.9);
$pdf->Cell( 9.75, 0.5, 'Certificate of Completion',0,1,'C');
$pdf->setFont('Helvetica', 'B', 11);
$pdf->SetXY(0.5,1.75);
$pdf->Cell( 9.75, 0.2, 'Course Work or Training in Infection Control',0,1,'C');
$pdf->Cell( 9.75, 0.2, 'Approved by', 0, 1, 'C');
$pdf->Cell( 9.75, 0.2, 'The New York State Department of Health &', 0, 1, 'C');
$pdf->Cell( 9.75, 0.2, 'The New York State Department of Education', 0, 1, 'C');
Now the output looks like this:
I tried adding this:
$pdf->setFontSpacing(100);
but the script failed to execute.
What is wrong?
The version of TCPDF on the site was old.
I updated to the latest version and the problem went away.

Categories