我学到的是,屏幕截图方法实际上是不可能的。因此,我所做的是使用这里使用FPDF规定的方法:https://wordpress.org/support/topic/convert-pdf-file
最后一篇文章很有启发性。这种方法的问题是,它对表单没有条件,因此需要为此添加一些if语句。此外,我正在使用CF7签名插件,因此需要一种处理该图像的方法。我还介绍了一种将PDF转换为BLOB并将其导入DFDB数据库的方法:
function wpcf7_update_email_body($contact_form) {
if ( $contact_form->id == 77 ) { //Number of the page for the form you are sending a PDF on.
$submission = WPCF7_Submission::get_instance();
if ( $submission ) {
/* DEFINE CONSTANT AND GET FPDF CLASSES */
define (\'FPDF_PATH\',get_template_directory().\'/fpdf/\'); // MAKE SURE THIS POINTS TO THE DIRECTORY IN YOUR THEME FOLDER THAT HAS FPDF.PHP
require(FPDF_PATH.\'fpdf.php\');
$posted_data = $submission->get_posted_data();
// SAVE FORM FIELD DATA AS VARIABLES
$name = $posted_data["your-name"];
$email = $posted_data["your-email"];
$subject = $posted_data["your-subject"];
$message = $posted_data["your-message"];
$signature = $posted_data["signature-113"];
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont(\'Arial\',\'B\',16);
$pdf->Write(5,$name . "\\n\\n" . $email . "\\n\\n" . $subject . "\\n\\n" . $message . "\\n\\n");
$pdf->Image($signature,60,30,90,0,\'PNG\'); // The signiture file image
$pdf->Output(FPDF_PATH.\'test.pdf\', \'F\'); // OUTPUT THE NEW PDF INTO THE SAME DIRECTORY DEFINED ABOVE
}
}
}
add_action(\'wpcf7_before_send_mail\', \'wpcf7_update_email_body\');
function mycustom_wpcf7_mail_components($components = null, $form = null){
global $wpdb;
$current_user = wp_get_current_user();
$username = $current_user->user_login;
$file_id = array_sum(explode(\' \', microtime()));
if ($form->id == 77) { //Number of the CF7 form (not the page id) you are sending a PDF on.
$form_id = $form->id;
$post = get_post($form_id);
$formtitle = $post->post_title;
$ip = getenv("REMOTE_ADDR");
if (empty($components[\'attachments\'])) {
$filename = \'test.pdf\'; // the full name and extention of the file as in the $pdf->Output variable above
$filepath = FPDF_PATH .$filename;
$components[\'attachments\'] = $filepath; // ATTACH THE NEW PDF THAT WAS SAVED ABOVE
// Insert file into CFDB -- Get file contents.
$tmpfile = fopen($filepath, "r");
$contents = fread($tmpfile, filesize($filepath));
// Insert the rows into CFDB.
$wpdb->insert(wp_cf7dbplugin_submits, array(
\'submit_time\' => $file_id,
\'form_name\' => $formtitle,
\'field_name\' => \'\', // Optional description
\'field_value\' => $filename,
\'field_order\' => 0,
\'file\' => $contents, //the binary contents of the file
), array(\'%f\', \'%s\', \'%s\', \'%s\', \'%d\', \'%s\'));
$wpdb->insert(wp_cf7dbplugin_submits, array(
\'submit_time\' => $file_id,
\'form_name\' => $formtitle,
\'field_name\' => \'Submitted Login\',
\'field_value\' => $username,
\'field_order\' => 9999,
\'file\' => NULL,
), array(\'%f\', \'%s\', \'%s\', \'%s\', \'%d\', \'%s\'));
$wpdb->insert(wp_cf7dbplugin_submits, array(
\'submit_time\' => $file_id,
\'form_name\' => $formtitle,
\'field_name\' => \'Submitted From\',
\'field_value\' => $ip,
\'field_order\' => 10000,
\'file\' => NULL,
), array(\'%f\', \'%s\', \'%s\', \'%s\', \'%d\', \'%s\'));
}
return $components;
} else {
return $components;
}
}
add_filter( \'wpcf7_mail_components\', \'mycustom_wpcf7_mail_components\',10,3 );
这一切都很好。格式等都在FPDF网站上进行了解释。