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.
Related
I need to draw a horizontal dotted line in pdf using TCPDF. I tried:
$style = array('width' => 0.1, 'cap' => 'butt', 'join' => 'miter', 'dash' => 1, 'color' => array(0, 0, 0));
$pdf->Line(5, 50, 100, 50, $style);
I used the dash parameter. When I set it to 1 it draws short dashes, but I need dots. I did not find an explanation of the style parameters or any manual on the internet.
Please use the below code for the draw horizontal dotted line in pdf using TCPDF and apply a style to it.
<?php
require_once('tcpdf.php');
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// disable header and footer
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
// set font
$pdf->SetFont('helvetica', '', 10);
// add a page
$pdf->AddPage();
//set 'width' => 0.1, 'dash' => '1,1,1,1' as per your requirement
$style = array('width' => 0.5, 'dash' => '2,2,2,2', 'phase' => 0, 'color' => array(255, 0, 0));
// Line
$pdf->Text(5, 4, 'Line examples');
$pdf->Line(5, 20, 200, 20, $style);
//Close and output PDF document
$pdf->Output('line_example.pdf', 'I');
I hope this helps!
You can have dots, if you want to.
Just set the cap to round in the style properties:
$style = array('width' => 0.5, 'cap => 'round', 'dash' => '2,2,2,2', 'phase' => 0, 'color' => array(255, 0, 0));
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]);
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.
I'm trying to add some barcodes programmatically in a pdf file but I think I'm not understanding something correctly regarding positioning.Here's my code
$pdf = new TCPDF("L", "mm", array(80, 40), true, 'UTF-8', false);
$pdf->SetMargins(3, 3, 3);
// remove default header/footer
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
$pdf->setFontSubsetting(true);
$pdf->SetFont('freeserif', '', 12);
foreach ($barcodes as $barcode){
$pdf->AddPage();
$x = $pdf->GetX();
$y = $pdf->GetY();
$style = array(
'border' => true,
'hpadding' => 'auto',
'vpadding' => 'auto',
'fgcolor' => array(0,0,0),
'bgcolor' => false, //array(255,255,255),
'text' => true,
'font' => 'helvetica',
'fontsize' => 8,
'stretchtext' => 4
);
//$pdf->Cell(30, 1, 'EAN 13', 0, 1);
$pdf->write1DBarcode($barcode, 'EAN13', '5', '6', '60', 14, 0.4, $style, 'N');
}
The result I get is like the image or in any way not even close to outputting the barcode where I'd like it to be and I have no clue why. I'd appreciate any help
if i use
$pdf->write1DBarcode($barcode, 'EAN13', '5', '5', '60', 14, 0.4, $style, 'N');
There is no empty pdf page but the barcode is still really high. I'd like it to go like 1/3 from top around 14mm that's why I was trying to fiddle with the y variable in write1DBarcode
After lots of fiddling around I found it.
Adding
$pdf->SetAutoPageBreak(TRUE, 0);
Made the autobreak behave correctly
My guess is that a bottom margin set by default that was messing around the alignment vertically that can't be set using $pdf->SetMargins. In any case problem solved for me. Thanks for trying to help
Use Below code
<?php $params = $pdf->serializeTCPDFtagParameters(array('5027010247321', 'C39', '', '', 80, 30, 0.4, array('position'=>'S', 'border'=>true, 'padding'=>4, 'fgcolor'=>array(0,0,0), 'bgcolor'=>array(255,255,255), 'text'=>true, 'font'=>'helvetica', 'fontsize'=>8, 'stretchtext'=>4), 'N'));
?>
And paste these below line where you want tcpdf baarcode
<tcpdf method="write1DBarcode" params="<?php echo $params; ?>" />
Visit [https://www.youtube.com/watch?v=flXFPbKRmUo][2]
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');