Home > Net >  Spaces in Html using Html2pdf with Codeigniter
Spaces in Html using Html2pdf with Codeigniter

Time:01-24

I am using html2pdf library within Codeigniter

When I put spaces in html code I cannot write to the file.

When I remove spaces in html code I can write to the file because there is no spaces in the html code

I would like to use the view file within Codeigniter but it is the same problem

$this->html2pdf->html($this->load->view('tableaubord/tableaubord_read', '', true))

(I use visual studio code as IDE)

Example:

This can be written to the file

$this->html2pdf->html('<html><head><title>Page Title</title></head><body><h1>This is a Heading</h1> <p>This is a paragraph.</p></body></html>');
$this->html2pdf->create('save')

This cannot be written to the file !

    $this->html2pdf->html('<html>
                            <head>
                              <title>Page Title</title>
                            </head>
                              <body><h1>This is a Heading</h1> 
                               <p>This is a paragraph.</p>
                             </body>
                           </html>');

    $this->html2pdf->create('save')

CodePudding user response:

It is not about the spaces, but about the line breaks: Try to "sanitize" the view output into a string without line breaks

$html = $this->load->view('tableaubord/tableaubord_read', '', true);
$html = str_replace(array("\n", "\r"), '', $html);
// if needed remove whitespace between tags like:
$html = preg_replace('/\>\s \</m', '><', $html);
$this->html2pdf->html($html);
$this->html2pdf->create('save')

php sandbox

  •  Tags:  
  • Related