Iwan Bagus Setyawan P
Iwan Bagus Setyawan P

Reputation: 31

MPDF Failed to Render HTML in Code Igniter

I am developing my simple apps with Code Igniter v 2.2 and latest MPDF for converting my view into PDF. I am already follow this link for tutorial Using MPDF with CI

And I am failed to get the PDF output. :D

I thought the WriteHTML()function failed to render my view. Here's my code for this one

$this->load->library('m_pdf');
$pdf = $this->m_pdf->load();
$html = $this->load->view('cetak', true);
$pdf->WriteHTML($html);

But when I change the $html variable into HTML tag like this, it works.

$html = " <!DOCTYPE html>
      <html lang='en'>
      <head>
      <meta charset='utf-8'>
      <meta http-equiv='X-UA-Compatible' content='IE edge'>
      <meta name='viewport' content='width = device-width, initial-scale = 1'>
      <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
      <meta name='description' content=''>
      <meta name='author' content=''>
      <link rel='icon' href='../../favicon.ico'>

      <title>Home</title>

      <!-- Bootstrap core CSS -->
      <link href='http://127.0.0.1:666/ticketing/assets/css/paper_bootstrap.css' rel='stylesheet'>

      <!-- Custom styles for this template -->
      <link href='http://127.0.0.1:666/ticketing/assets/css/jumbotron-narrow.css' rel='stylesheet'>

      </head>

      <body>
      <div class='container'>
      <div class='header clearfix'>
      <nav>
      <ul class='nav nav-pills pull-right'>
      <li role='presentation' class='active'><a href='#'>Home</a></li>
      <li role='presentation'><a href='#'>Logout</a></li>
      </ul>
      </nav>
      <h3 class='text-muted'>King Jim Indonesia</h3>
      </div>

      <!-- Columns start at 50% wide on mobile and bump up to 33.3% wide on desktop -->
      <strong>Execute time : {elapsed_time} seconds</strong>
      <a href='http://127.0.0.1:666/ticketing/index.php/welcome/cetak/2015/3'>Cetak</a>
      <div class='row'>
      <div class='col-md-4' style='border: 1px solid #e1e1e8; margin-bottom: 5px;'>
      <table style='width: 100%; color: #0060f1'>
      <tr><td colspan='2' class='text-center' style='text-decoration: underline;'><strong>PT. KING JIM INDONESIA</strong></td></tr>
      <tr><td colspan='2' class='text-center' style='text-decoration: underline;'><strong>KUPON MAKAN</strong></td></tr>
      <tr><td colspan='2' class='text-center' style='text-decoration: underline;'><strong>juni, 2015</strong></td></tr>
      <tr>
      <td class='text-left'><h2 style='margin-top: 0px; margin-bottom: 0px; color: #0060f1'>12</h2></td>
      <td class='text-right'><h3 style='margin-top: 0px; margin-bottom: 0px; color: #144691'>212</h3></td>
      </tr>
      <tr><td colspan='2' style='font-size: 13px; font-style: italic'>1. Kupon ini hanya berlaku sesuai bulan & tanggal</td></tr>
      <tr><td colspan='2' style='font-size: 13px; font-style: italic'>2. Tidak dapat diuangkan</td></tr>
      </table>
      </div>
      <?php
      }
      ?>
      </div>
      <?php
      }
      ?>
      </div> <!-- /container -->
      </body>
      </html>";

Can anybody tell me where is my mistakes. Regards.

Upvotes: 0

Views: 2575

Answers (2)

Tpojka
Tpojka

Reputation: 7111

You missed to get string from view. It's because you passed true to second parameter. Second parameter should be blank or null and third parameter need to be set to boolean to get string:

$html = $this->load->view('cetak', '', true);

Try this way.

Upvotes: 2

tsg
tsg

Reputation: 205

You have your html in double quotes. Try using single quotes. All of your single quotes will either need to be escaped or changed to double quotes.

Upvotes: 0

Related Questions