I am unable to generate a PDF from a DIV for emailing to a client while maintaining formatting and variables changed using Regex. Essentially, the PDF file sends as it should attached, but the formatting is messed up (i.e., break space, etc.) and the variables are showing up as {input1}, {input2}, etc, even after being generated.
I've tried multiple other answers on the site I found, including CakePHP and it doesn't work for me.
indexing.html: For some reason, I can't post HTML code. Basically it's just a Div with the id 'string1' with some text in between which includes {input1}.
*I used regex to replace {input1} with user input.
pdf.php:
require_once 'dompdf/autoload.inc.php';
use Dompdf\Dompdf;
class Pdf extends Dompdf{
public function __construct(){
parent::__construct();
}
}
?>
PHP:
$message = '';
$html= file_get_contents("indexing.html");
$dom = new DOMDocument;
$dom->loadHTML($html);
$div = $dom->getElementById('string1');
$result = $dom->saveHTML($div);
if(isset($_POST["action"]))
{
include('pdf.php');
$file_name = md5(rand()) . '.pdf';
$html_code = '<link rel="stylesheet" href="bootstrap.min.css">';
$pdf = new Pdf();
$pdf->load_html($result);
$pdf->render();
$file = $pdf->output();
file_put_contents($file_name, $file);
require 'class/class.phpmailer.php';
$mail = new PHPMailer();
#$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = ''; // Specify main and backup SMTP servers
#$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = ''; // SMTP username
$mail->Password = ''; // SMTP password
#$mail->SMTPSecure = 'SSL'; // Enable SSL
$mail->Port = 587; // TCP port to connect to
$mail->setFrom("", "");
$mail->addAddress("");
$mail->isHTML(true);
$mail->AddAttachment($file_name); //Adds an attachment from a path on the filesystem
$mail->Subject = 'Generate Legal Document'; //Sets the Subject of the message
$mail->Body = 'Please see attached PDF File.'; //An HTML or plain text message body
if($mail->Send()) //Send an Email.
Return true on success or false on error
{
$message = '<label class="text-success">Sent successfully...
</label>';
}
unlink($file_name);
header("Location: indexing.html");
}
The PDF file sends as it should attached, but the formatting is messed up (i.e., break space, etc.) and the variables are showing up as {input1}, {input2}, etc, even after being generated...