John Davidson

php - TCPDF outdenting/negative-indent issue

0 comments
Message:


For some reason, when writing content to columns with TCPDF, I am often coming across an issue where the first line in each column will be negatively indented. You can see this here (on the lines beginning "odio. Sed eleifend..." and "iaculis. Proin eget augue..."):



Oddly enough, this often doesn't occur with the first column.


I have tried minifying the html source (in order to rule out issues rendering whitespace), changing the font, changing the font-size, etc. None of which has worked.


The code itself is quite simple:




<?php

// add a new page
$this->AddPage();

// disable existing columns
$this->resetColumns();

// set columns
$this->setEqualColumns( 4, 40 );

// set font
$this->SetFont( 'helvetica', '', 7 );

// write content
$this->writeHTML( $footnotes_content, true, false, true, true, 'L' );

?>


My Answer:
One possible solution to this issue is to manually add an indent to the content that is being written to the columns. You can do this by adding a non-breaking space character at the beginning of each line in the content. This will force TCPDF to treat the first line as if it has an indent, which should prevent the negative indent issue from occurring.

Here is an example of how you can modify your code to add a non-breaking space character at the beginning of each line in the content:

php

// add a new page
$this->AddPage();

// disable existing columns
$this->resetColumns();

// set columns
$this->setEqualColumns( 4, 40 );

// set font
$this->SetFont( 'helvetica', '', 7 );

// add non-breaking space character to prevent negative indent
$footnotes_content = preg_replace('/^/m', ' ', $footnotes_content);

// write content
$this->writeHTML( $footnotes_content, true, false, true, true, 'L' );

?>


By adding the non-breaking space character at the beginning of each line in the content, you should be able to prevent the negative indent issue from occurring in TCPDF.

Rate this post

3 of 5 based on 7426 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us