mikehaertl / phpwkhtmltopdf

A slim PHP wrapper around wkhtmltopdf with an easy to use and clean OOP interface
MIT License
1.6k stars 238 forks source link

Added tmpDelete option to avoid delete tmp files #375

Closed eusonlito closed 3 years ago

eusonlito commented 3 years ago

This new option tmpDelete allow to retain tmp HTML files after PDF is generated.

mikehaertl commented 3 years ago

Hmm, can you give me a use case?

The temp files will not be deleted as long as you have a reference to your Pdf variable somewhere in your code. So why is this useful?

eusonlito commented 3 years ago

For testing. I can execute the render one time, get the command with $pdf->getCommand() and execute it in terminal multiple times with previously pregenerated HTML files.

mikehaertl commented 3 years ago

That sounds like a very special case to me and I don't think we need an additional option for this.

If you want to keep the created temp files for HTML it should work if you create them outside of the library and pass them to addPage(). Then you can also set whatever options you want there (and reuse them).

eusonlito commented 3 years ago

I have used a lot this feature on multiple proyects (edited vendor package manually).

Currently I have used with headers and footers rendering problem. Using a single option is a lot of more easy than write code, test and undo code.

My code is something similar to:

    /**
     * @return string
     */
    public function contents(): string
    {
        return Pdf::fromHtml($this->html(), [
            'tmpDelete' => false,
            'margin-top' => '19',
            'margin-bottom' => '10',
            'header-html' => view('user.profile.pdf.header')->render(),
        ])->toString();
    }

    /**
     * @return string
     */
    public function html(): string
    {
        return view('user.profile.pdf.detail', [
            'user' => $this->user,
        ])->render();
    }

Anyway, thanks, I always can use my fork :)

mikehaertl commented 3 years ago

Ok. I still think it's very specific to your project and I also showed a workaround.

Thanks für the suggestion anyway.