Does anyone know of a way to generate a pdf file form data posted to an access database using 6.0. or 6.1 in an after record added event.
I have sucessfully submitted my form data as Html style tables from one of my tables and able to send as email. What I would like to do is
take the form data generate a pdf file with the form data and attach to email either as FDF format or preferabley a pdf file and send in the after record added event.
It's very simple ! That what Im doing right now : I have a table that contains coupons : when I click on save the new entry it shows a pdf file with all the datas I have entered ( + some editing, formatting ). I choose to display the file but you can send it right away.
All you have to do is to download FPDF from FPDF.org (it's free and use only 1 pdf file). If you want also a premade (template) pdf file, as the background use FPDI (it's also free). here is a simple code I put on the after record events:
define('FPDF_FONTPATH','/var/www/vhosts/yourlinktoyourwebhost/httpdocs/fpdf/font/');
require_once('/var/www/vhosts/yourlinktoyourwebhost/httpdocs/fpdf/fpdf.php');
require_once('/var/www/vhosts/yourlinktoyourwebhost/httpdocs/fpdf/fpdi.php');
// initiate FPDI : i use a portrait a4 page
$pdf =& new FPDI('P','mm','A4');
// add a page
$pdf->AddPage();
// set the sourcefile the file reduction.pdf is a template : it's like an empty form made with word
$pdf->setSourceFile('/var/www/vhosts/yourlinktoyourpdftemplate/fpdf/reduction.pdf');
// import page 1
$tplIdx = $pdf->importPage(1);
// use the imported page and place it at point 1,1 and 210mm large ( a4 format)
$pdf->useTemplate($tplIdx, 1, 1, 210);
// this is because I print date on the document
$today = date("d/m/Y");
// now write some text above the imported page
$pdf->SetFont('Arial','B','8');
// the setxy is where you want to write the text here it's 51mm from right margin and 65mm from top
$pdf->SetXY(51, 65);
//here I print the date
$pdf->Write(0, $today);
//mise en forme // these are because I use french date dd/mm/YYYY not YYYY-mm-dd like phprunner does
$point="***";
$montantpdf=$point."".$values["montant"]."".$point;
$date1=$values["dateemission"];
$annee=substr($date1, -10, 4);
$mois=substr($date1, -5, 2);
$jour=$date1[strlen($date1)-2].$date1[strlen($date1)-1];
$dateemis=$jour . "/" . $mois . "/" . $annee;
$date2=$values["dateexpire"];
$annee2=substr($date2, -10, 4);
$mois2=substr($date2, -5, 2);
$jour2=$date2[strlen($date2)-2].$date2[strlen($date2)-1];
$dateexp=$jour2 . "/" . $mois2 . "/" . $annee2;
//message corps texte // This is a message to write on the letter
$pdf->text(26,72,"some text for customer");
// Those thing below are specfic to my template but it's simple to adapte
// whatever you want to write 1st numer is in mm from left, second is in mm from top, then you can print text or a variable ,
//in my example I use values from fields or formatted values from fields.
//bordereau client
$pdf->text(27,187,"nom");
$pdf->text(27,197,$values["numreduc"]);
$pdf->text(25,206,$dateemis);
$pdf->text(28,215,$dateexp);
$pdf->text(33,223,$montantpdf);
//ticket client :
$pdf->text(84,186,"nom");
$pdf->text(102,194,$values["numreduc"]);
$pdf->text(84,203,$dateemis);
$pdf->text(124,203,$dateexp);
$pdf->text(93,211,$montantpdf);
// bon interne
$pdf->text(89,249,"nom");
$pdf->text(89,259,$values["numreduc"]);
$pdf->text(86,268,$dateemis);
$pdf->text(135,268,$montantpdf);
$pdf->text(93,276,$dateexp);
// Here is the magic : the name is the name you want the file to have ( whatever ) the" I " means the result page is shown immediatly in t
//the browser with embedded pdf reader, you can put a "D" instead so the brower ask to save the file , or you can save the file on
//server with "F" (you muist specify full path before the file name and have chmod777 the directory).
// Now to email the result pdf file you can use phpmailer ( free) or use built in mail() command
//$mail = new PHPMailer();
//...
//$doc = $pdf->Output('', 'S');
//$mail->AddStringAttachment($doc, 'doc.pdf', 'base64', 'application/pdf');
//$mail->Send();
// the whole pdf is transfered as a big string, and phpmailer convert it (mime decoder) and attach it to the mail.
$pdf->Output('coupon.pdf', 'I');
hop this help <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=45935&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />