Image causing issues in FPDF
-
Hey,
We want to attach a pdf generated from the posted data to the email send via cf7 after hitting submit. To achieve this we decided to use fpdf. The code in our functions.php looks like this (shortened):
add_action('wpcf7_before_send_mail', 'wpcf7_update_email_body'); function wpcf7_update_email_body($contact_form) { //import fpdf library $submission = WPCF7_Submission::get_instance(); if ( $submission ) { /* DEFINE CONSTANT AND GET FPDF CLASSES */ define ('FPDF_PATH',get_template_directory().'/inc/fpdf181/'); require(FPDF_PATH.'fpdf.php'); //get all the necessary data from the contact form $posted_data = $submission->get_posted_data(); $firm = $posted_data["kufirm"]; $name = $posted_data["kuname"]; $image = $posted_data["file-864"]; //create new pdf and fill it with dynamic content $pdf = new FPDF(); $pdf->AliasNbPages(); $pdf->AddPage('P','A4'); $pdf->SetFont('Arial','',12); $pdf->Cell(50,10,'My PDF',0,1,'L'); $pdf->Cell(95,10,'firm',1,1,'C'); $pdf->Cell(95,10,'client name',1,1,'C'); $pdf->Image($image,10,10,-300); $pdf->Output(FPDF_PATH.'test.pdf', 'F'); } } //add pdf created above to email attachments add_filter( 'wpcf7_mail_components', 'mycustom_wpcf7_mail_components' ); function mycustom_wpcf7_mail_components($components){ if (empty($components['attachments'])) { $components['attachments'] = array(FPDF_PATH .'test.pdf'); } return $components; }
It works perfectly fine as long as we comment
$pdf->Image($image,10,10,-300);
out. The image seems to create an issue that stops everything – the submit button keeps loading forever and no email is sent.Do you know why this is happening? Since we tried a lot we assume it’s a memory problem? How do you debug things like this in the first place?
Or is there a better way to generate a PDF?
Viewing 8 replies - 1 through 8 (of 8 total)
Viewing 8 replies - 1 through 8 (of 8 total)
- The topic ‘Image causing issues in FPDF’ is closed to new replies.