Laravel Streamed Response From Azure (Multiple Files) - php

I've been working on this setup but I cannot save the downloaded streamed response to my zip file. I am using ZipArchive package and currently when I use return on the one with the yellow arrow. It returns the correct pdf but when I try to put it in the zip folder. It doesn't recognize it as a pdf file and return null. I need to save multiple pdf file in the add Zip File but right now I'm trying with only one pdf for now.

Got it. What I did is convert it to a raw pdf file and read it using AddFromString.

Related

Zip file download system laravel

I'm using Laravel 8
I've uploaded a zip file then want to download it. But here is a problem. After file download, it's not extracting.
Here is my code for download zip file:
$product = Product::where('id',1)->first();
$file = $product->main_file;
return response()->download($file,'filename.zip');
But, if I manually copy this zip file from my project then extract it, it's extracting fine.
Or, if I doing this: return Redirect()->to($file); It also downloads the file and extracts well without any problem. But, it's not a proper way to download. Isn't it?
So, What can I do now?
if you're trying to download via a link try this:
Download
but file name should be saved somewhere.

Laravel - edit pdf with FPDF with a soruce file from s3

Im working on a Laravel backend and I need to edit a PDF file allocated in a s3 bucket. When I try opening the PDF with $pdf->setSourceFile($url) I get an error saying Given stream is not seekable!
I can get the file contents using Storage::disk(ENV('FILESYSTEM'))->url($url);, and return it to the front end and that works fine, so I know the path and the permissions are correct. I would like to the content to the setSourceFile($contents) method, intead of the url. is there any way to do this?
By the way, Im using the Laravel filesystem
Edit: I have tried copying the file from s3 to the server and then open it with PDF. I couldn't reach it, but I don't think that's a good way to do it.
First of all: You cannot edit a PDF document with FPDI
As the error message says, the source stream needs to be seekable which seems not be the case with the stream wrapper you're currently using.
You should download the file and create a reader instance of it:
$pdf->setSourceFile(StreamReader::createByString($pdfString));

CloudConvert via Laravel wrapper: converted file not saved on local disk

I'm trying out a Laravel wrapper for CloudConvert, so I'm using one of the examples from GitHub to check the basic file conversion. My code is the following:
$path = storage_path('app');
CloudConvert::file($path.'/test.jpg')->to($path.'/test.pdf');
so basically I want to convert test.jpg file to test.pdf. Both source and output files should be taken from/saved under storage/app.
Thing is, the conversion takes place but the output file is not being saved under the specified path (nor anywhere in the project). I know the conversion is successful, because I can see it in my CloudConvert account, and I can download the PDF after conversion from CloudConvert directly.
What am I doing wrong? Why isn't the output file stored?
I also tried to change the destination path to use public directory - no luck.

ZendService\LiveDocx returns zip file instead of docx

I'm using the ZendService\LiveDocx library, but when I run this on our stage server (Linux) and request the format to be docx, it returns me back a zip file rather than the actual document. The zip file consists of XML files describing the document. If I request the format to be PDF it works fine. This works fine in my local development environment (Windows 7) when I try to generate a docx document.
Any ideas why the LiveDocx service would return a zip file instead of the actual document?
The zip file consists of XML files describing the document.
That's how .docx files work.
A .docx in fact is a zip file, so you can simply rename them according to your needs.
You can try this by taking a "good looking" docx file and rename it to .zip, then extract.
The solution for your problem is to rename the file from .zip to .docx before exposing to the user as a download.

PHP - Grab PDF with URL that does not have the .pdf extension

I'm using Filepicker.io to upload PDFs to my application. I have all those URLs and now I am trying to merge some of those PDFs using the PDF Tool Kit PHP library. It was not working for me so I ran some tests using the "file_exists" on PHP and it kept returning false.
I think this has to do with the fact that the URL does not have a ".pdf" extension at the end. This is what they look like: "https://www.filepicker.io/api/file/LCvbgpqEQLGwt8bfnqc1"
Does anyone know how I can pull the PDF using PHP in order to merge those files using the PDF Toolkit Library?
Thanks!
Alain F.
file_exists doesn't work with URLs, only with local files. Instead download the file to the temp dir using the copy command.
If the file can't be downloaded, the copy command will return false.
$exists = copy('https://www.filepicker.io/api/file/LCvbgpqEQLGwt8bfnqc1', '/tmp/example.pdf');
if (!$exists) throw new Exception("PDF could not be downloaded");
Use the downloaded file in the PDF Tool Kit.
EDIT: This does not solve this particular problem but does address the theory that it didn't work because "the URL does not have a ".pdf" extension at the end."
You can add things to the end of the filepicker URL with a trailing +
The following urls are equivalent:
https://www.filepicker.io/api/file/LCvbgpqEQLGwt8bfnqc1
https://www.filepicker.io/api/file/LCvbgpqEQLGwt8bfnqc1+name.pdf

Categories