I use dompdf to generate a PDF file, Then I send it using PHPmailer. But the issue is that the file name of the generated PDF name is not correct.
Here is the code:
//PDF from dompdf
$pdf = $dompdf->output();
//PHPmailer confiurgation
$mail->IsSMTP();
$mail->CharSet = 'UTF-8';
//PDF name
$name = 'محمد احمد علي';
$pdfName = str_replace(" ", "_", $name); //Replace spaces with _
$pdfName .= ".pdf";
//Attach PDF
$mail->AddStringAttachment($pdf, $pdfName);
The PDf name should be محمد_احمد_علي.pdf in this case. But it's _احمد_علي.pdf
I tried:
$encoding = 'base64';
$type = 'application/pdf';
$mail->AddStringAttachment($pdf, $pdfName, $encoding, $type);
Also:
$mail->Encoding = "base64";
But no success.
I don't see that there is an issue with the string name, As when I run the following code:
$name = 'محمد علي احمد';
$name = str_replace(' ', "_", $name);
echo $name . '.pdf';
I get the expected result.
How to solve this issue?
Update
I just tried:
$dompdf->stream($filename);
To download the PDF without sending it. And it's the same result, So I don't know where the issue is coming from.
New Update
In case this happens to anyone in the future.
I found out why this is happening. Dompdf is using basename() on the file name. And with my Arabic name that function makes it go wrong like that.
It's really sad how programming languages and libraries are ignoring RTL languages like Arabic.
So running this code:
echo basename('محمد احمد علي');
Would return احمد علي
Related
I have a form on a website that customers fill. When user filles the form and clicks submit data is sent to a pdf(invoice) I've already created and certain spots in pdf are filled with that data. I did this using PDFTK library:
public function generate($data)
{
$filename = date("d-m-Y-His") . ".pdf";
$pdf = new Pdf('./form.pdf');
$pdf->fillForm($data)
->flatten()
->saveAs('./completed/' . $filename);
$path = './completed/' .$filename;
return $path;
}
The problem is, i dont know how to send this filled pdf via PHPMailer library, as pdf is recquired to be a string in order to work with phpmailer.
$pdf = new GeneratePDF;
$response = $pdf->generate($data);
$email = new PHPMailer();
$email->SetFrom('you#example.com', 'Your Name');
$email->Subject = 'Test';
$email->Body = 'Test';
$email->AddAddress( 'mail exmp' );
$email->AddAttachment( $response , 'NameOfFile.pdf' );
$email->Send();
And how to actually save file in cpanel server, as when i do this it doesnt work on a server.
pdf is recquired to be a string in order to work with phpmailer
This is not true. addAttachment() requires that you pass in a path to a local file on disk, so you could do:
$email->addAttachment(generate(), 'NameOfFile.pdf');
You can pass in a binary string using addStringAttachment(), but that's not what you're asking for here.
Similar question has been asked previously but it didn't solve my problem so i am asking here again. Actually i am uploading base64 image file to php server and i have to save it there. I tried every suggested help but nothing works for me. my code
// here is my base64 code for image
data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgFBgcGBQgHBgcJCAgJDBMMDAsLDBgREg4THBgdHRsYGxofIywlHyEqIRobJjQnKi4vMTIxHiU2OjYwOiwwMTD/2wBDAQgJCQwKDBcMDBcwIBsgMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDD/wAARCAC1ALUDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwDwOJN77fWrf9my+Q0rMu1a7HTfB9k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VRPUjogZ2QtanBlZyB2MS4wICh1c2luZyBJSkcgSlBFRyB2OTApLCBxdW... ";
// above the example of image base64 file
// and server side code in php, i have posted base64 to php
$img_part = explode(";base64,",$_POST['base64']);
$img_type_aux = explode("image/",$img_part[0]);
$ext = $img_type_aux[1];
$image_base64 = base64_decode($img_part[1]);
// i have tried all possible code like here $name = random_value+$ext
file_put_contents($name,$image_base64); // didn't work then i used str_replace
$image_base64 = str_replace(' ','+',$image_base64);
file_put_contents($name,$image_base64); // i also didn't work
$fp = fopen($name,"wb");
fwrite($fp,$image_base64); // i also didn;t work
fclose($fp);
please someone help me,
Use this function This will work.
function convertBase64toimage($image_string){
$name='test_with_new_image.jpeg';
$folderPath=$_SERVER['DOCUMENT_ROOT'] . "/test/";
$img_part = explode(";base64,",$image_string);
$img_type_aux = explode("image/",$img_part[0]);
$ext = $img_type_aux[1];
$image_base64 = base64_decode($img_part[1]);
$file = $folderPath .$name;
file_put_contents($file,$image_base64);
}
$string='data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgFBgcGBQgHBgcJCAgJDBMMDAsLDBgREg4THBgdHRsYGxofIywlHyEqIRobJjQnKi4vMTIxHiU2OjYwOiwwMTD/2wBDAQgJCQwKDBcMDBcwIBsgMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDD/wAARCAC1ALUDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8Q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hYTFt2B1xgY/Ou3C4h8xcD2IoorFrU06Gv4c+5P/vD+tbHIOQcZ5IoorSOxm9xQoYE+nauP8f+NE8G2Ul0NMW8Zc8ed5ecf8BNFFBKPI7/APaJ12Z8aXo2nWif9Ni8x/QqP0rCv/i7431Byv8Aa62qn+G2gRP1wT+tFFTM1gkZ0viDX75tt7rl/Kf+upH6CnQqZP8AXSyy/wC+5NFFYSOqCRa/1f3adiiis0bMh3fX86kFw69DRRVszuPzR/yzoooARQcfeNFFFID/2Q==';
$a=convertBase64toimage($string);
And output of the code
I am sorry this might be a foolish question, but I am trying to download pdf files, and everything find just the name of pdf
my controller
$abstract = Project::find($A_ID);
$pdf = PDF::loadView('Abstracts.pdf', compact('abstract'));
return $pdf->download('abstract.pdf'); //name of the pdf
what I am trying to do is to change the ('abstract.pdf') to ($abstract->A_Title)
The issue with ($abstract->A_Title) it doesn't have .pdf extension, and I have been trying to add it with no results
use concatenation (.)operator here
for example :
$name = "title";
$extension = ".pdf";
$fileName = $name . $extenstion;
$fileName output should be title.pdf
$abstract = Project::find($A_ID);
$pdf = PDF::loadView($abstract->A_Title.'.pdf', compact('abstract'));
return $pdf->download($abstract->A_Title.'.pdf'); //name of the pdf
You can use PHP concatenation,
$abstract = Project::find($A_ID);
$pdf = PDF::loadView($abstract->A_Title.'.pdf', compact('abstract'));
return $pdf->download($abstract->A_Title.'.pdf');
I'm using mPDF to generate PDF's when a button is clicked and the i save them inside a folder. I am looking for a way to add the PDF to an attachment using PHPmailer. Here is what I've tried:
$dir = $_SERVER['DOCUMENT_ROOT'].dirname($_SERVER['PHP_SELF']);
$pdfexist = $dir."/classes/pdf/feestructure_".$student['rollno'].".pdf";
$mail = new PHPMailer;
$mail->isSMTP();
$mail->From="xyz#abc.com";
$mail->FromName="xyz";
$mail->addAddress("xyz#abc.com");
//echo $email."<br/>";
$mail->addAddress("xyz#abc.com");
$mail->addAddress("xyz#abc.com");
$mail->Subject = 'XYZ';
$pdfstring = $pdfexist;
$mail->AddStringAttachment($pdfstring, "feestructure_".$roll.".pdf", $encoding = 'base64', $type = 'application/pdf');
The size of my generated pdf is 13k but its showing 1 k in mail attachment.help me guys.
Here is the output from mpdf:
$mpdf->WriteHTML(file_get_contents("$dir/feestructure_pdf.php?rollno=$rollno"));
$pdfname="feestructure_".$rollno.".pdf";
$mpdf->Output("classes/pdf/".$pdfname,"F");
Your $pdfexists / $pdfstring variable contains a file path, not binary PDF data, so you should be using AddAttachment(), not AddstringAttachment(). AddAttachment attaches files (like your PDF), AddStringAttachment attaches strings, like what you might get back from a web call or a database.
$mail->AddAttachment($pdfstring, "feestructure_".$roll.".pdf", $encoding = 'base64', $type = 'application/pdf');
I have to modify the uploaded .doc or .docx file in php. I googled but i only found how to read that. I want the word file as it is and put text at the bottom of that MS Word file at run time. How is this possible anyone know please reply or give me example script.
Thanks,
I'm the developer of PHPWord. You can use the PHPWord_Template Class to open an existing DOCX File and then replace some text marks with your individual text.
Alternatively you can open the DOCX file with the ZipArchive extension and then read/write every xml File (document.xml, header.xml, footer.xml, ...) you want. This method is nothing else than the PHPWord_Template class. ;)
You can use PHPWord.
I have same requirement for Edit .doc or .docx file using php and i have find solution for it.
And i have write post on It :: http://www.onlinecode.org/update-docx-file-using-php/
if($zip_val->open($full_path) == true)
{
// In the Open XML Wordprocessing format content is stored.
// In the document.xml file located in the word directory.
$key_file_name = 'word/document.xml';
$message = $zip_val->getFromName($key_file_name);
$timestamp = date('d-M-Y H:i:s');
// this data Replace the placeholders with actual values
$message = str_replace("client_full_name", "onlinecode org", $message);
$message = str_replace("client_email_address", "ingo#onlinecode.org", $message);
$message = str_replace("date_today", $timestamp, $message);
$message = str_replace("client_website", "www.onlinecode.org", $message);
$message = str_replace("client_mobile_number", "+1999999999", $message);
//Replace the content with the new content created above.
$zip_val->addFromString($key_file_name, $message);
$zip_val->close();
}
You only replace the predefined variables.
In the following code
https://github.com/PHPOffice/PHPWord
I also did this problem in phpword using the following code
if(!file_exists('file/word.docx')){
$templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor('demo.docx');
$templateProcessor->setValue('name', 'Akbarali');
$templateProcessor->setValue('time','13.02.2021');
$templateProcessor->setValue('month', 'January');
$templateProcessor->setValue('state','Uzbekistan');
$templateProcessor->saveAs('file/word.docx');
}
This will change the words in the demo.docx file. The new file is then saved in the word.docx file folder.
you can define variables in the form of ${name} in the demo word file.
that is, ${name}, ${time}, ${month} and ${state}
In this post we will show you How to update docx file using php, hear for How to update docx file using php we will give you demo and example for implement.
Hear we will show you how to Edit .doc or .docx file using php. Hear we use “client_full_name”, “client_email_address”, “date_today”, “client_website”, “client_mobile_number” in .doc or .docx files
$template_file_name = 'template.docx';
$rand_no = rand(111111, 999999);
$fileName = "results_" . $rand_no . ".docx";
$folder = "results_";
$full_path = $folder . '/' . $fileName;
try
{
if (!file_exists($folder))
{
mkdir($folder);
}
//Copy the Template file to the Result Directory
copy($template_file_name, $full_path);
// add calss Zip Archive
$zip_val = new ZipArchive;
//Docx file is nothing but a zip file. Open this Zip File
if($zip_val->open($full_path) == true)
{
// In the Open XML Wordprocessing format content is stored.
// In the document.xml file located in the word directory.
$key_file_name = 'word/document.xml';
$message = $zip_val->getFromName($key_file_name);
$timestamp = date('d-M-Y H:i:s');
// this data Replace the placeholders with actual values
$message = str_replace("client_full_name", "onlinecode org", $message);
$message = str_replace("client_email_address", "ingo#onlinecode", $message);
$message = str_replace("date_today", $timestamp, $message);
$message = str_replace("client_website", "www.onlinecode", $message);
$message = str_replace("client_mobile_number", "+1999999999", $message);
//Replace the content with the new content created above.
$zip_val->addFromString($key_file_name, $message);
$zip_val->close();
}
}
catch (Exception $exc)
{
$error_message = "Error creating the Word Document";
var_dump($exc);
}
Try having a look at http://www.tinybutstrong.com/ as it can create and edit Word documents, we use it in a mail merge style for generating invoices in doc and pdf.
Some of these answers dont contain the full steps so here is what ive done:
Create your word document. With in this document anything you want to replace with PHPWORD mark it like this -> ${variable_name} so for example ${value1}
$file = "docs/input/word/source.docx";
$output_file = "docs/input/word/modified.docx";
$PHPWord = new \PhpOffice\PhpWord\PhpWord();
$document = $PHPWord->loadTemplate($file);
$document->setValue('value1', 'Enter Your Text Here');
$document->saveAs($output_file);