Guzzle 6 - Use a .pdf generate by a .php page - php

I a controller which use an external page in charge of
generating a pdf with the help of the FPDF class.
To see if the generation is working on the server, I told to FPDF to save the file, then ask the browser to display the pdf.
Guzzle do his job, he call the page, the pdf is save and the content of the page download.
The pdf save is not corrupted and work perfectly.
The response is a pdf window showing a 'failed to load PDF document' error.
I'm using laravel, there's my controller :
$response = $client->request('POST','http://.../x.php', [
'form_params' => [...]
]);
return $response;

Laravel doesn't use PSR-7 for Request/Response, so you have to convert Guzzle's response to Laravel's one.

Related

Laravel storage::download(path_to_file) not working as required with .doc/.docx

I am trying to Storage::download(file_path) but with pdf file type it showing pdf file in postman, however with .doc/.docx it is returning some garbage value. I want to return doc file like pdf, below is attached pdf and doc postman response:

Ajax download fpdf in codeigniter not working

Expected requirement - when user clicks button ajax will be call to controller where pdf will generate and generated pdf will gets downloaded on user's system.
Actual Scene - i able to create pdf using fpdf file and saved in folder and used force download function but nothing happend.
here's my code:
Controller :
$this->load->helper('download');
$this->load->library('myfpdf');
$this->load->view('pdf/namewise_report',[]);
$link = base_url().'uploads/pdfs/namewise.pdf';
force_download($link, NULL);
pdf/namewise_report.php (last line)
$this->myfpdf->Output('uploads/pdfs/namewise.pdf', "F");
is there anything to add in ajax success response

Invalid characters when call output method with custom fonts in dompdf php

I use laravel dompdf to create PDF files. What I'm trying to do is create pdf file, upload it to storage and then download it. there's specific endpoint, when user call it all these actions happen.
// fetch data for pdf
$pdfData = $this->getData();
// creates pdf from html
$pdf = PDF::loadView('pdf.example', [
'items' => $pdfData
])->setPaper('a4', 'landscape');
// upload file to storage
Storage::put("/my-path", $pdf->output());
// download file
return $pdf->download("file.pdf");
In html(from which pdf's been created) I have custom fonts(load them with #font-face). the issue is that after calling output method $pdf->output() the characters in pdf are invalid
BUT, if I don't call $pdf->output() characters are shown properly(with my custom fonts). so the issue happens only when I use custom fonts and then call $pdf->output(). any idea how to fix it?
I already saw this solution but it doesn't help, also there's no load_font.php in this package

CakePHP read PDF generated and send it as bytes

In my webapp, I can generate pdf file from multiple odt files using gedooo on demand when the user go to this url: http://{base_url}/models/generer/{doc_id}, the modelsController generate the pdf and launch the download on the navigator.
Now I have to send to a distant application by webservice the content of pdf (like an attachment in email) from a model. The problem is to execute the pdf generation and integrate it in my request without store it on the server as file. I tried to do something like:
$pdf = new File('http://{base_url}/models/generer/{doc_id}');
$content = $pdf->read();
And I get an error. I am out of ideas, I need your help.
You can not transmit PDF (binary file).
if you want to transmit it in webservice, you have to convert it to base64
$file = file_get_contents('http://{base_url}/models/generer/{doc_id}');
$filedata = base64_encode($file);
now you can send this data in webservice
echo json_encode(array('file'=>$filedata));
I found the solution!
$this->requestAction($url);
that write the file in the folder of my webapp and
$content = file_get_contents($local_url)

Render a View without loading in the browser - cakephp

I am wondering if it is possible to render an action's view without loading in the browser?
I'm using a cakephp component that used mPDF to generate PDF files. The component works well if you load the action and view in a browser but when I want to generate and save the pdf to the drive it doesn't seem to kick in, I'm assuming it's because the view isn't loaded property.
The component I am using is: https://github.com/segy/Mpdf
So basically I have a function called mail_merge which generates a pdf using the mentioned component, I need to call the mail_merge function from another function within the same controller to generate the pdf but without loading in the browser.
Thanks
UPDATE:
I worked out how to set the view as a variable and then write it to the pdf in the function.
ADDED THIS:
// RENDER THE VIEW AND SET AS A VARIABLE TO WRITE THE HTML
// --------------------------------------------------------------------------->
$response = $this->render('mail_merge');
$thebody = $response->body();
$this->Mpdf->WriteHTML($thebody);
Unfortunately my PDF still won't generate so I guess the issue is something else.
Try this way:
$response = $this->render('mail_merge');
$thebody = $response->body();
$this->Mpdf->WriteHTML($thebody);
$this->Mpdf->Output('filename.pdf');

Categories