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');
Related
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 احمد علي
In my Laravel project I created a page to upload the files and I use the $file of laravel it works fine for some system only but for some system it shows an error as shown in image below.
Function I am using to upload files in model
public function add_document_sub_cert($req)
{
$subcontractor_id = $req['subcontractor_id'];
$reference_id = $req['reference_id'];
$files = $req->file("uploaded_doc0");
$i = 0;
foreach($files as $file){
$i++;
$ext = $file->guessClientExtension();
$name = $file->getClientOriginalName();
$file_name_1 = str_replace(".".$ext,"",$name);
$path = $file->storeAs('subcontractor/','avc'.$i.'.jpg');
if($path){
$document = new Document();
$document->doc_name = 'avc.jpg';
$document->module = 'subcontractor';
$document->reference_id = $reference_id;
$document->save();
}
}
}
Your error says that you didn't specify a filename. I see that your variable $file_name_1 is never used. Haven't you forgotten to use it somewhere?
Without knowing how your class Document works, it's impossible to tell you exactly where is the bug.
Recently I'd tried with a dompdf. But after converting my file to pdf $this->event_registration();is not working. How can I deal with this issue . ?
My code:
$data['info'] = $this->reg_model->getInfo();
$id = $data['info']->id;
$file = $data['info']->Register_num;
$data['ed_info'] = $this->reg_model->getEdInfo($id);
$this->load->view('info.html',$data);
$html = $this->output->get_output();
// Load library
$this->load->library('dompdf_generate');
// Convert to PDF
$this->dompdf->load_html($html);
$this->dompdf->render();
$this->dompdf->stream($file.".pdf");
$this->event_registration();
I have a site where there is member registration. All data will be saved but I get only this error:
Could not move the file "/tmp/phpa4pH3I" to "/home/sporter/public_html/someonect.org/uploads\membersImages/33921.jpg" ()
My code is like this
public function store(){
// dd(Input::all());
$validator = Validator::make(Input::all(), Members::$rules);
if($validator->passes()):
$first_name = Input::get('mem_firstName');
$last_name = Input::get('mem_lastName');
$email = Input::get('mem_email');
$image = Input::get('mem_image');
$phone = Input::get('mem_phone');
$occupation = Input::get('mem_occupation');
$citizen = Input::get('mem_citizen');
$address = Input::get('mem_address');
$destinationPathImage = str_replace('PROJECT\\', '', base_path().'\uploads\membersImages\\') ;
//Generating a random name
$randomName = rand(11111,99999);
//Renaming the image
$ImageName = $randomName.'.'.'jpg'; // renameing image
$imagePath = $destinationPathImage.$ImageName;
Members::create([
'first_name'=>$first_name,
'last_name'=>$last_name,
'email'=>$email,
'image'=>$imagePath,
'phone'=>$phone,
'occupation' => $occupation,
'citizen' => $citizen,
'address'=>$address
]);
...
I don't understrand clearly your str_replace part, but if you setup your url in config properly, you don't need this.
I'm using this kind of upload for an image:
if($request->hasFile('mem_image')) {
$file = $request->file('mem_image');
$ext = $request->file('mem_image')->getClientOriginalExtension();
$filename = rand(11111,99999). '.' . $ext;
$file->move('./uploads/', $filename);
$member->mem_image = '/uploads/' . $filename;
$member->save();
}
In case, your uploads directory is in your public folder.
If your script have permission for writing in target folder. The problem can be only in path. Check what contain in variable $destinationPathImage. It must be correct and exists path. In your error message I see problem with slashes.
also think that it's be cool to check exists of destination folder and file exists before save to database record with path of file.
You're not using the proper slashes.
Replace \uploads\membersImages\\ with /uploads/membersImages/.
If it still not working, please double check the permissions in that folder using the is_writable php function. However, have in mind that the is_writable function is not working properly on windows platforms.
I am currently trying to convert an ODT to PDF using OO silently from PHP. Here is the code for that:
function MakePropertyValue($name, $value,$osm){
$oStruct = $osm->Bridge_GetStruct("com.sun.star.beans.PropertyValue");
$oStruct->Name = $name;
$oStruct->Value = $value;
return $oStruct;
}
function odt2pdf($doc_url, $output_url){
$osm = new COM("com.sun.star.ServiceManager") or die ("Please be sure that OpenOffice.org is installed.\n");
$args = array(MakePropertyValue("Hidden",true,$osm));
$oDesktop = $osm->createInstance("com.sun.star.frame.Desktop");
$oWriterDoc = $oDesktop->loadComponentFromURL($doc_url,"_blank", 0, $args);
$aFilterData = array();
$aFilterData [0] = $osm->Bridge_GetStruct("com.sun.star.beans.PropertyValue");
$aFilterData [0]->Name = "SelectPdfVersion";
$aFilterData [0]->Value = 1;
$obj = $osm->Bridge_GetValueObject();
$obj->set("[]com.sun.star.beans.PropertyValue",$aFilterData );
$storePDF = array();
$storePDF[0] = $osm->Bridge_GetStruct("com.sun.star.beans.PropertyValue");
$storePDF[0]->Name = "FilterName";
$storePDF[0]->Value = "writer_pdf_Export";
$storePDF[1] = $osm->Bridge_GetStruct("com.sun.star.beans.PropertyValue");
$storePDF[1]->Name = "FilterData";
$storePDF[1]->Value = $obj;
$oWriterDoc->storeToURL($output_url,$storePDF);
$oWriterDoc->close(true);
}
$output_dir = "C:/wamp/www/cert/pdf/";
$doc_file = "C:/wamp/www/cert/output2.odt";
$pdf_file = "output2.pdf";
$output_file = $output_dir . $pdf_file;
$doc_file = "file:///" . $doc_file;
$output_file = "file:///" . $output_file;
odt2pdf($doc_file,$output_file);
I have managed to get it to convert to PDF/A-1a as can be seen, however it still does not preserve the fonts being used. If I convert this from within the GUI in Open Office, then the fonts are kept. What's wrong?
UPDATE: I decided to stop converting to PDF and do a silent print of the odt to the printer with Open Office using exec() in PHP.
As an additional note, make sure to switch off Font substitution on the printer driver to prevent any font substitution when printing to a PostScript printer.
Try by first converting the ODT to HTML ( to maintain formatting ) by using this library
https://gist.github.com/1918801
and later use this FPDF library to convert from html to pdf
I guess FPDF wont support so easily to convert from html so there is a plugin for that FPDF
here is the link for the plugin
plugin for FPDF to convert from HTML