Comments (6)
You need to refact your format method to something like:
public function format($response)
{
$pdf = Yii::$app->html2pdf->convert($response->data);
$response->setDownloadHeaders('test.pdf', $mimeType = 'application/pdf', $inline = true);
$response->content = file_get_contents($pdf->name);
}
from html2pdf.
I think that you forgot the return statement:
return $pdf->send($file, $options = ['mimeType' => 'application/pdf', 'inline'=> false]);
from html2pdf.
Hmm I forgot to mention that i use the class in a response formatter which i have created by myself.
I use this in my controller to get a "export to pdf" possibility for each action by only setting the response formatter when e.g. ?export = pdf is used as a query.
And there is the problem that $pdf->send only works if the file isn't deleted.
something like this:
namespace app\formatter;
use Yii;
use yii\base\Component;
use yii\web\Response;
use yii\web\ResponseFormatterInterface;
class TestResponseFormatter extends Component implements ResponseFormatterInterface
{
public function format($response)
{
//$pdf = Yii::$app->html2pdf->convert('some test');
$pdf = Yii::$app->html2pdf->convert($response->data);
$pdf->send('test.pdf', $options = ['inline'=> true]);
}
}
which that i could render a view in my action and just set the response format. And the html code is used as input for the pdf.
Yii::$app->response->format = 'html2pdf';
in config:
'response' => [
'formatters' => [
'html2pdf' => [
'class' => 'eurescom\formatter\TestResponseFormatter',
],
of course if is save the file (make a copy) i could send it.
I see that this only happens if i use the html2pdf class like above and not directly in the action.
It would be good if there was a possibility to set if the files should be deleted automatically or manually.
I also see no possibility to use my own Tempfile class and just replace the destructor.
from html2pdf.
It's clear now. You are misusing the ResponseFormatterInterface
.
The format method is suitable to format the response, not send it.
from html2pdf.
you are right. if i send the contents of the file and set the appropriate headers myself it works.
I don't know why i came to the solution to use the send function and why it is working if the file isn't deleted by the destructor.
from html2pdf.
You're welcome ;)
from html2pdf.
Related Issues (17)
- The filename, directory name, or volume label syntax is incorrect. HOT 1
- why do not display image? i use xvfb-run wxhtmltopdf HOT 1
- Getting unknown property: yii\web\Application::html2Pdf HOT 1
- Mpdf\MpdfException: Temporary files directory is not writable HOT 1
- Exit with code 1 due to network error: ContentNotFoundError HOT 1
- Mpdf fontDir should merge existing fontDir HOT 2
- PDF is being sent empty HOT 1
- Svg Graph to pdf HOT 3
- Error: Text file busy HOT 1
- Feature Request: extend Manager to support cli arguments HOT 2
- Convert Page of Yii2 site HOT 1
- wkhtmltopdf is not recognized as an internal or external command HOT 2
- Mpdf 7.* is not supported HOT 1
- wkhtmltopdf: command not found` HOT 1
- One remark about wkhtmltopdf and options HOT 1
- wrong parameter pageSize is documentation for wkhtmltopdf used HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from html2pdf.