# HTML to PDF how can i convert into PDF?

**URL:** <https://discourse.cakephp.org/t/html-to-pdf-how-can-i-convert-into-pdf/5897>\
**Category:** Need Help\
**Created:** [April 4, 2019, 2:13pm UTC](https://discourse.cakephp.org/t/html-to-pdf-how-can-i-convert-into-pdf/5897 "2019-04-04T14:13:56Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![spadeX](https://avatars.discourse-cdn.com/v4/letter/s/919ad9/32.png) [@spadeX](https://discourse.cakephp.org/u/spadeX)\
**Post date:** [April 4, 2019, 2:13pm UTC](https://discourse.cakephp.org/t/html-to-pdf-how-can-i-convert-into-pdf/5897/1 "2019-04-04T14:13:56Z")

</div>

Well, i have used [friendsofcake/](https://packagist.org/packages/friendsofcake/)cakepdf .This plugin used but i have design one certificate which is in html and css format when i call the function to convert pdf it will show the separate parts of certificate. css will not apply after the pdf conversion. how can resolve this type problem …Please suggest some solution

---

<div class="post-metadata">

**Author:** ![dakota](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/dakota/32/1421_2.png) [@dakota](https://discourse.cakephp.org/u/dakota)\
**Post date:** [April 7, 2019, 5:53pm UTC](https://discourse.cakephp.org/t/html-to-pdf-how-can-i-convert-into-pdf/5897/2 "2019-04-07T17:53:22Z")

</div>

Which engine are you using? Can you post some example code of what you’ve tried?

---

<div class="post-metadata">

**Author:** ![spadeX](https://avatars.discourse-cdn.com/v4/letter/s/919ad9/32.png) [@spadeX](https://discourse.cakephp.org/u/spadeX)\
**Post date:** [April 8, 2019, 2:58am UTC](https://discourse.cakephp.org/t/html-to-pdf-how-can-i-convert-into-pdf/5897/3 "2019-04-08T02:58:23Z")

</div>

Thanks for reply post.I have solved this problem, & i have used wkhtmltopdf engine.i have not to set default layout in pdf folder so the css will not to set to my acutal pdf.

---

<div class="post-metadata">

**Author:** ![spadeX](https://avatars.discourse-cdn.com/v4/letter/s/919ad9/32.png) [@spadeX](https://discourse.cakephp.org/u/spadeX)\
**Post date:** [April 9, 2019, 6:09am UTC](https://discourse.cakephp.org/t/html-to-pdf-how-can-i-convert-into-pdf/5897/4 "2019-04-09T06:09:13Z")

</div>

This is my Controller function …

```auto
public function exportpdf()
        {
            $invoice = $this->Countries->find();
            $this->viewBuilder()->setClassName('CakePdf.Pdf');
            $this->viewBuilder()->options([
                'pdfConfig' => [
                    'orientation' => 'portrait',
                    'filename' => 'certificate_'
                ],
                
            ]);
            $this->set('invoice', $invoice);
        }
/////////////////////////////////// this is bootstrap.php setup ////

Configure::write('CakePdf', [
    'engine' => [
        'className' => 'CakePdf.WkHtmlToPdf',
        'binary' => '/usr/bin/wkhtmltopdf', //LINUX
        //'binary' => 'C:\PROGRA~1\wkhtmltopdf\bin\wkhtmltopdf.exe', //WINDOWS
        'options' => [
            'print-media-type' => true,
            'outline' => true,
            'dpi' => 96
        ]
    ],
    'pageSize' => 'Letter',
]); 

```

But when i call the function it’s was long run but not any output.

---

<div class="post-metadata">

**Author:** ![spadeX](https://avatars.discourse-cdn.com/v4/letter/s/919ad9/32.png) [@spadeX](https://discourse.cakephp.org/u/spadeX)\
**Post date:** [April 24, 2019, 11:58am UTC](https://discourse.cakephp.org/t/html-to-pdf-how-can-i-convert-into-pdf/5897/5 "2019-04-24T11:58:31Z")

</div>

I have got an error `failed to load Failed to load PDF document`. i have check git error posting same issue. but my app have no errors. but getting this error.

---

<div class="post-metadata">

**Author:** ![FullmetalChocobo](https://avatars.discourse-cdn.com/v4/letter/f/7cd45c/32.png) [@FullmetalChocobo](https://discourse.cakephp.org/u/FullmetalChocobo)\
**Post date:** [May 25, 2019, 7:37am UTC](https://discourse.cakephp.org/t/html-to-pdf-how-can-i-convert-into-pdf/5897/6 "2019-05-25T07:37:43Z")

</div>

I have always ran into permission issues when I get PDF generation errors. Try pushing the file to a very public location (/app/tmp/ or /tmp) and ensure permissions are 777 for the directory, just as a test. Sometimes www-data is trying to write the pdf, but it doesn’t have write permissions for /usr/bin/…

---

<div class="post-metadata">

**Author:** ![dakota](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/dakota/32/1421_2.png) [@dakota](https://discourse.cakephp.org/u/dakota)\
**Post date:** [July 23, 2019, 8:10am UTC](https://discourse.cakephp.org/t/html-to-pdf-how-can-i-convert-into-pdf/5897/8 "2019-07-23T08:10:14Z")

</div>

Open the file in a text editor (Like VSCode), often that error means the there is a PHP error/warning in the PDF file.

---

<div class="post-metadata">

**Author:** ![spadeX](https://avatars.discourse-cdn.com/v4/letter/s/919ad9/32.png) [@spadeX](https://discourse.cakephp.org/u/spadeX)\
**Post date:** [August 3, 2019, 5:49am UTC](https://discourse.cakephp.org/t/html-to-pdf-how-can-i-convert-into-pdf/5897/9 "2019-08-03T05:49:58Z")

</div>

This Problem solved by myself. same solution used for find issue. Thank You for great time.

---

<div class="post-metadata">

**Author:** ![AARTHI](https://avatars.discourse-cdn.com/v4/letter/a/e5b9ba/32.png) [@AARTHI](https://discourse.cakephp.org/u/AARTHI)\
**Post date:** [August 9, 2019, 10:45am UTC](https://discourse.cakephp.org/t/html-to-pdf-how-can-i-convert-into-pdf/5897/10 "2019-08-09T10:45:18Z")

</div>

i didnt have “WkHtmlToPdf”…then what i have to do please tell for me

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [August 9, 2019, 5:57pm UTC](https://discourse.cakephp.org/t/html-to-pdf-how-can-i-convert-into-pdf/5897/11 "2019-08-09T17:57:28Z")

</div>

Is installing WkHtmlToPdf an option for you?

---

<div class="post-metadata">

**Author:** ![AARTHI](https://avatars.discourse-cdn.com/v4/letter/a/e5b9ba/32.png) [@AARTHI](https://discourse.cakephp.org/u/AARTHI)\
**Post date:** [August 12, 2019, 7:38am UTC](https://discourse.cakephp.org/t/html-to-pdf-how-can-i-convert-into-pdf/5897/12 "2019-08-12T07:38:41Z")

</div>

yah… i got it through tcpdf engine

---

<div class="post-metadata">

**Author:** ![spadeX](https://avatars.discourse-cdn.com/v4/letter/s/919ad9/32.png) [@spadeX](https://discourse.cakephp.org/u/spadeX)\
**Post date:** [August 12, 2019, 11:33am UTC](https://discourse.cakephp.org/t/html-to-pdf-how-can-i-convert-into-pdf/5897/13 "2019-08-12T11:33:40Z")

</div>

You need to install [friendsofcake/](https://packagist.org/packages/friendsofcake/)cakepdf package. well your problem is solved by the way
