tcpdf - bug causing incorrect indentation following a line break

Are you familiar with how to adjust text alignment after a line break using tcpdf?

With tcpdf 6.2.13 and the writeHTML method, I am attempting to achieve perfectly left-aligned text. However, whenever the line is too long, the following line gets shifted to the left as seen in the image and code below.

https://i.sstatic.net/eka9x.png

<table border="0" cellspacing="0" cellpadding="4">
    <tr>
        <td>
            My Company Equipement<br>
            France
        </td>
        <td bgcolor="green" cellpadding="0">
            <b>Delivery Address</b>
            <br>
            <br>
            Team Adamon FIGHTING ACADEMY
            38 chemin de Tomasenea<br>
            Zone de Berrouetta<br>
            26000 URRUGNE<br>
            France
        </td>
        <td align="left" style="margin:0;padding:0;text-indent: 0;">
            <b>Delivery Address</b>
            <br>
            <br>
            Team Adamon FIGHTING ACADEMY
            38 chemin de Tomasenea<br>
            Zone de Berrouetta<br>
            26000 URRUGNE<br>
            France
        </td>
    </tr>
</table>
<p>
    Team Adamon FIGHTING ACADEMY
    Team Adamon FIGHTING ACADEMY
    Team Adamon FIGHTING ACADEMY
    Team Adamon FIGHTING ACADEMY
    <br>
    Team Adamon FIGHTING ACADEMY<br>
    Team Adamon FIGHTING ACADEMY<br>
</p>

I could manually add <br> tags based on word count, but do you know of a more elegant solution?

Answer №1

It appears that TCPDF is displaying the whitespace.

<td>
     Line 
</td>

will result in this unintended indentation, whereas

<td>Line 
</td>

will not. Additionally, eliminate any extra spaces after <br /> tags and within the opening <p> tag and its content.

EDIT: Disregard previous recommendation to switch to writeHTMLCell(), instead utilize writeHTML() with the $cell parameter set to true and exclude cellpadding settings.

Answer №2

Yesterday, I encountered the same issue.

According to @Matvey Andreyev, TCPDF distinguishes between

<td>
foo
<td>

and

<td>foo</td>

To solve this problem, you can wrap your td value in a <div> tag to ensure consistent indentation of lines

The following solution should do the trick:

<td><div>first line<br />second line<br /> third line</div></td>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What are the best ways to ensure a website is responsive in a vertical

When designing a responsive webpage, I encountered an issue with the body element not properly expanding the content vertically. Despite enlarging the web content horizontally, the body failed to adjust its height accordingly, resulting in unwanted black a ...

Making Explorer 11 wrap width with Flexbox

After implementing a simple code using flexbox, everything seemed to be working flawlessly on Firefox, Safari, Chrome, Edge, and Opera, but encountered issues with IE11. The problem arises with responsive frames containing images and text within a specific ...

Unexpected server error encountered during navigation of php pages

I am using PHP to retrieve data from a MySQL table and display it in an HTML table. Each row in the table has a 'remove' button that triggers a PHP script (remove.php) to delete the corresponding row from the database table and return to admin.ph ...

Using an Ember color picker to dynamically change SCSS variables

Is there a way to allow an admin to change the skin of one of my websites by selecting a color from a palette that will update a universal SASS variable? I am aware of methods to dynamically change CSS using jQuery, but I specifically want to modify the S ...

Excessive margin-left values for CSS div positioning are simply outlandish

http://jsfiddle.net/SVJaK/1338/ I attempted to create a small space between the green divs and my right div in this fiddle. I had to specify a very large pixel margin-left value to achieve that slight gap. Can someone explain why? Even though the gap is a ...

Finding the span that contains numerical values within text using regular expressions in XPath

Currently, my code is utilizing //span[text()='1'] | //span[text()='2'] | //span[text()='3'], but its appearance is not quite optimal. I am interested in learning a more elegant approach to achieve the same result. For insta ...

Creating a personalized LinkedIn share button through POST requests: here's how

I am interested in using my own image for the LinkedIn share button. After referencing a previous post on this topic: How to make a custom LinkedIn share button It was mentioned that: In order to create a custom Share button for LinkedIn, POST calls need ...

What could be the reason for the presence of three pixels of white space below this particular table

My table is supposed to have a fixed height of 146px, but there seems to be an extra row of three pixels at the bottom. I've tried various methods to remove any unwanted spacing or padding, but nothing has worked so far. The only solution I found was ...

Discrepancies in media screen queries displaying on inspection tools compared to actual device

I've done some research online but I'm still struggling with this issue. Despite creating media screen queries and setting the viewport for iPhone 7 plus, the website does not display correctly on my device. When I inspect it using Chrome, every ...

Having trouble with CSS margins behaving unexpectedly

Could someone please explain why I am unable to add margin-top/bottom or padding-top/bottom to this "a" tag? I am trying to center "Konoha" in the header box. html{ background-color: white } body{ width: 88.5%; height: 1200px; margin: 0 auto; borde ...

A single click causes the entire row of cards to extend seamlessly

The cards on this tab were generated using a loop and the data is sourced from a database. When I click on the "Show More" button, the entire visible column expands along with it. The expansion does not reveal the content immediately; instead, the content ...

Using Angular's ngIf directive to dynamically add the selected attribute to an option based on a specific string

I need to dynamically set the selected attribute for an option in a select drop-down list. Here is an example of what I want to achieve: <select name="gcodeProfile"> <option value="HT Translucent F WF 500 um.gcode.profile& ...

A guide on styling JSON key values within HTML

I need help organizing my JSON Document on an HTML page. Here is the JavaScript code I am using: xmlhttp.onreadystatechange = function () { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { // Optionally, here you can update ...

Experiencing problems with the CSS on the Login page and have yet to find a solution

Description:- I encountered an issue with my HTML login page where I used an image for the username and password. Everything worked fine when I manually typed in the username and password, but when I selected the username from the auto-fill suggestions pop ...

Is it possible to retrieve the complete file path in a form?

My goal is to retrieve a file using an input element of type "file". This element is located within a partial view, and I need to send it to the controller or request it there using "Request.Form["inputFile"];". However, this method only provides me with t ...

The show more/show less link for a long jQuery paragraph is malfunctioning

I encountered an issue while coding where the "read more" link works correctly, but the "show less" link does not. Despite my efforts, I cannot seem to identify the error. Within this code snippet, there is an anchor tag with class="show-less" that I am u ...

Is there a way to create a "navigate to" button directly from the text within a <p> element?

Within my HTML, there is a <p> tag which dynamically receives a link value from a JavaScript function. The link could be anything from www.google.com to youtube or instagram. How can I utilize the "copytoclipboard" library to copy this link to clipbo ...

Is it possible to relocate an iframe outside the body of a post in Blogger?

For my blog posts, I have a goal of relocating the first iframe used outside of the post body and into a custom div called #myvideos. Some blog templates, such as this example, have already achieved this by moving a video out of the post body. I would like ...

Using CSS to filter the contents of an input field in Bootstrap 3

Is there a way to restrict the input field to only accept numbers? I attempted to use type='number', but non-numeric values can still be entered. How can I prevent users from inputting non-numbers? <input type="number" style="background-colo ...

Why does the appearance of my PHP spreadsheet change when I attempt to print it?

After using a CSS stylesheet to position my textboxes correctly, I noticed that in Chrome everything appeared fine. However, when attempting to print the site (Ctrl+P), each sentence and textbox shifted. How can I ensure they remain in place? <!-- #cap ...