# I need help ? ctp to html string

**URL:** <https://discourse.cakephp.org/t/i-need-help-ctp-to-html-string/6932>\
**Category:** Need Help\
**Created:** [November 28, 2019, 6:43am UTC](https://discourse.cakephp.org/t/i-need-help-ctp-to-html-string/6932 "2019-11-28T06:43:59Z")\
**Posts on this page:** 5\
**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:** [November 28, 2019, 6:43am UTC](https://discourse.cakephp.org/t/i-need-help-ctp-to-html-string/6932/1 "2019-11-28T06:43:59Z")

</div>

I have generate invoice in ctp. and i want that generate html to my function to create pdf. My Question How to convert .ctp file to html string. Please any suggestion.

---

<div class="post-metadata">

**Author:** ![Graziel](https://avatars.discourse-cdn.com/v4/letter/g/71c47a/32.png) [@Graziel](https://discourse.cakephp.org/u/Graziel)\
**Post date:** [November 28, 2019, 7:30am UTC](https://discourse.cakephp.org/t/i-need-help-ctp-to-html-string/6932/2 "2019-11-28T07:30:33Z")

</div>

```auto
$this->viewBuilder()
     ->setTemplatePath('Example');
            
$renderedHtml = (string)$this->render('hello', 'layout');

```

will give you renderd html of `Example/hello.ctp` with `layout` layout

---

<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:** [December 28, 2019, 6:37am UTC](https://discourse.cakephp.org/t/i-need-help-ctp-to-html-string/6932/3 "2019-12-28T06:37:41Z")

</div>

Thanks, that was really helpful.

---

<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:** [January 1, 2020, 4:30pm UTC](https://discourse.cakephp.org/t/i-need-help-ctp-to-html-string/6932/4 "2020-01-01T16:30:45Z")

</div>

You could/should just use [CakePDF](https://github.com/friendsofcake/cakepdf) which will do it for you

---

<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:** [January 2, 2020, 9:19am UTC](https://discourse.cakephp.org/t/i-need-help-ctp-to-html-string/6932/5 "2020-01-02T09:19:46Z")

</div>

Yes Sir, This works perfectly. 😊
