Mastering the art of precise formatting and alignment in iTextSharp

I have implemented the following code to align two phrases/two columns within a table:

        table = new PdfPTable(2);
        table.TotalWidth = 450f;
        table.LockedWidth = true;
        float[] widths= new float[] { 100f, 350f };
        table.SetWidths(widths);
        table.WidthPercentage = 85;
        table.HorizontalAlignment = Element.ALIGN_LEFT;
        cell = new PdfPCell();
        cell = PhraseCell(new Phrase("Repair 2 - Tongue pig biltong picanha:", newfntbld), PdfPCell.ALIGN_LEFT);
        cell.PaddingTop = 12f;
        table.AddCell(cell);
        cell = PhraseCell(new Phrase("Ham beef ball tip, pastrami sausage ribeye meatloaf salami kielbasa. Ground round bresaola pastrami ham capicola pork belly, tri-tip drumstick. Beef hamburger pork loin bacon doner chuck shank strip steak ham hock meatloaf. Flank meatball swine frankfurter.", newlightfnt), PdfPCell.ALIGN_LEFT);
        cell.PaddingTop = 12f;
        cell.Border = 0;
        table.AddCell(cell);       

The current output I am getting can be viewed here.

However, my desired layout is as shown in this image: https://i.sstatic.net/XU7s2.png

Answer №1

Why force this format into a table when tables are not designed for this layout?

You could simply create it as a paragraph instead:

Create two phrases - one with bold font for "Repair 2 - Tongue pig biltong picanha - " and another with regular font for the remaining text. Then combine them to form a paragraph.

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

When the HTML is structured in such a way that the first text in a div element remains

Within a div, I have an h1 tag that I want to move down from the top of the div. Despite trying to add a top margin to the h1, it remains in place unless there is text in the '#contact' section, causing the h1 to drop down. Is there a way to acco ...

The CSS class names for Next.js have not been defined yet

Just getting started with next js and trying to use css modules for styling my nav component. However, I noticed that the classname I setup for the nav element is not showing up in the rendered DOM. Even though I can see the generated styles by webpack in ...

Transforming traditional HTML table layout to modern div structure

We are currently in the process of transitioning old pages from our previous website structure, which used tables, to our new layout based on DIVs. Our website is structured using a PHP include system with separate components for the header, body, and foot ...

The Conundrum of CSS versus Razor Views

Currently, I am developing a basic website using ASP.NET/MVC with Razor (.cshtml). As I am relatively new to CSS, I am interested in customizing the appearance and style of my site. After inspecting the source of the homepage, I find myself struggling to t ...

How can I adjust the font size of information retrieved from a JSON file using ng2-smart-table?

I recently tried using the following CSS code: :host /deep/ ng2-smart-table {font-size:22px;} However, despite implementing this code, I have not noticed any change in the font size. ...

Steps for Overwriting a File That Already Exists

I am currently developing a music player application that consists of two forms. The main area of the app is where you can play music, while the second form contains a CheckedListBox for selecting the MP3s you wish to listen to. Once I click a button, it s ...

Effortlessly arranging images in a row with React

QUERY I have a handful of PNG image files saved in the same folder as my React component and have successfully imported them. Now, I am looking for a best practice method to display all these images - let's assume there are 4 images - within their re ...

Is it possible to utilize an expression tree in C# to invoke a method that has an

Can anyone help with this problem? I am trying to utilize the Int32.TryParse(String numberStr, out Int32 result) method within an Expression tree, but I am uncertain about how to retrieve the parsed result. ...

Prevent a user from being able to highlight text in a text input field

I'm a little baffled as to why this isn't working as expected. The input I have is being masked successfully, but when the text is selected, it shows the actual value. To address this issue, I want to prevent users from highlighting the input t ...

What is the best way to align two divs horizontally using CSS?

.navbar { overflow: hidden; background-color: antiquewhite; position: absolute; top: 0; width: 100%; } .navbar a { float: right; display: block; color: Black; text-align: center; padding: 14px 16px; text-decoration: none; font-size ...

What is the reason for needing a page reload in Javascript or JQuery?

I'm curious why Javascript or jQuery require a page reload before applying certain effects. CSS updates in real-time, as demonstrated by the following example: This changes dynamically without needing to refresh the page @media all and (max-width:7 ...

Issues persist with Jquery draggable not functioning properly, part 2

Trying to implement draggable functionality with jQuery on an element, but encountering issues. Here is the code snippet: <html> <head> <link rel="stylesheet" href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.cs ...

I'm struggling to make background-image display properly in my CSS code

In my quest to enhance the appearance of my website, I've been grappling with getting the background-image property to cooperate in CSS for the past three days. It's frustrating because I've successfully implemented this feature before, but ...

Ways to incorporate React.js into HTML for showcasing a portfolio

Having difficulties rendering my code using React.js for my portfolio. I am attempting to showcase my projects with images and p tags containing project titles and my role. Additionally, I would like the React elements to be clickable, directing users to t ...

Utilize CSS to prioritize the image and ensure it is responsive

I'm utilizing the 'featurette' feature in bootstrap. Currently, the page displays text on the left and an image on the right. As you reduce the browser size, they stack on top of each other, with the text appearing above the image. How can I ...

JavaScript's jQuery selector retrieves a child element from one location and adds it to a different

Why does the Jquery children selector select the img element, extract it, remove it, and then append it to another div element? Shouldn't it create a copy of the element being appended? var $anchors = $("#imageGallery a"); var $overlay = $('&l ...

Mapping OracleTypes to .NET in Oracle databases

Can anyone help me with the mappings or Oracle equivalents for the different options in the .NET enum System.Data.OracleClient.OracleType? I understand most of them, but some like OracleType.Int32 and OracleType.Int16 are not clear to me. Are they referr ...

Unable to understand the reason behind why this is prohibited

Seeking some clarification on this issue. It felt like the most natural thing to do: public interface IJob { bool started { get; set; } } public interface IJobManager { void StartJob(IJob job); } public class ...

Unable to convert a list of objects to a list of custom objects

I currently have 3 different classes defined in my code: [Serializable] public class Classa { public list<Object> list {get; set;} } [Serializable] public class Classb { public string name {get; set;} public string nickname {get; set;} } [Se ...

Using Angular's flex-layout directive alongside the ngFor directive

I am a beginner when it comes to flex-layout and I'm currently facing an issue that I need help with. Here is the problem I am encountering: https://github.com/angular/flex-layout This is my ngFor loop: <div fxLayout.xs="column"> <country ...