0

So I'm trying to create a PDF invoice for a garage and I have the below currently (I know the variables are missing but they had personnel info in for the testing on localhost as well as some of the blank text in cells). So anyway a few things!

I want the Work and the corresponding amount on the same line which I have done some research on and it still wont work as I don't fully understand it, is someone able to help on how it works so I can implement it?

The idea is to create the invoice saving it to a SQL database, which I have done, with the added option to either print the document straight out or send via e-mail to the customer is it possible to Save the PDF to send as an attach through PHPMailer(Which I will be getting to grips with soon!). Or print straight from this?

Ideally wouldn't want to PDF to clog up after creating.

Any help would be greatly appreciated, need anything give me a shout!

<?php
require ('fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();


$pdf->SetFont('Arial','',24);

//Cell (Width, height, text, border, end line, 'align')
$pdf->Cell(189,25,'Cheshire West Vehicle Ltd Invoice', 0,1, 'C');

$pdf->SetFont('Arial','',14);
//CWV & Customer Address
$pdf->Cell(65,5,'',0,0);
$pdf->Cell(124, 5, $firstname.' '.$lastname, 0, 1, 'R');
$pdf->Cell(40,5,'',0,0);
$pdf->Cell(149 ,5, $housenumber.', '.$postcode, 0 ,1, 'R');
$pdf->Cell(30,5,'',0,0);
$pdf->Cell(159,5,$contactnumber,0,1,'R');
$pdf->Cell(30,5,'',0,0);
$pdf->Cell(159,5,$email,0,1,'R');


//Date
$pdf->SetFont('Arial','',12);
$pdf->Cell(189,15,$date,0,1,'R');

$pdf->SetFont('Arial','',13);

//Vehicle Stuff
$pdf->Cell(12,15,'VRM: ',0,0);
$pdf->Cell(29,15,$vrm,0,0,'C');
$pdf->Cell(13,15,'Make: ',0,0);
$pdf->Cell(35,15,$make,0,0,'C');
$pdf->Cell(14,15,'Model: ',0,0);
$pdf->Cell(44,15,$model,0,0,'C');
$pdf->Cell(18,15,'Mileage: ',0,0);
$pdf->Cell(24,15,$mileage,0,1,'C');

//Work
$pdf->Cell(149,5,'Work Carried Out',1,0,'C');
$pdf->Cell(40,5,'Amount',1,0,'C');
$pdf->Cell(0,5,'',0,1);

$pdf->MultiCell(189,25,$work1,1,'C',false);
$pdf->MultiCell(40,25,$amount1,1,1);
$pdf->MultiCell(189,25,$work2,1,'C',false);
$pdf->MultiCell(40,25,$amount2,1,1);
$pdf->MultiCell(189,25,$work3,1,'C',false);
$pdf->Cell(40,25,$amount3,1,1);

//Other
$pdf->Cell(189,5,'Other Details',1,'C');
$pdf->MultiCell(189,25,$other,1,'C',false);
$pdf->Output();
?>
Mattex
  • 11
  • 3

1 Answers1

0

Yes. If you look at the docs for tcpdf, you'll see there are options for output, including one (S) that returns the PDF data directly as a string, rather than writing it to a file. You can pass this raw data directly into PHPMailer's addStringAttachment() method, like this:

$pdfdata = $pdf->Output('name.pdf', 'S');
$mail->addStringAttachment($pdfdata, 'name.pdf');

It will get its encoding and MIME type set automatically.

In other news, the tcpdf docs are hopeless to navigate.

Synchro
  • 35,538
  • 15
  • 81
  • 104