title: iTextSharp : How to add 2 sentence in 1 line and adjust width of cells from datagridview?
body: <p>I have a winform that enables user to key in via DataGridView and then converts the data into a PDF document.</p>
  
  <p>However I am having trouble with the format of the Table where the Cells are not formatted correctly based on Width Size.</p>
  
  <p>I have tried setting my DataGridView cells width into type "Fill" but it does not change the outcome when converted into a PDF.</p>
  
  <p>Besides that , can we actually use iTextSharp to insert 2 different sentences in 1 Line.</p>
  
  <pre><code>Paragraph b1 = new Paragraph("OWNER NAME: " + "                                      " + "Property Name: ");
  
  Paragraph b2 = new Paragraph("Property Name: " + "\n");
  </code></pre>
  
  <p>is there a way to combine b1 and b2?</p>
  
  <p>Outcome should be as per picture.</p>
  
  <p>Property name should be on the far right on the same line as "Owner Name".
  And cells width should be based on Column Size configured in DataGridView</p>
  
  <p><a href="https://i.stack.imgur.com/08Ksp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/08Ksp.png" alt="ITARF"></a></p>
  
  <p>EDIT 1 :</p>
  
  <p>Adding my DataGridView conversion to PDF code below -</p>
  
  <pre><code>private void Button1_Click(object sender, EventArgs e)
  {
          PdfPTable pdfTable = new PdfPTable(dataGridView1.ColumnCount);
          //pdfTable.DefaultCell.Padding = 10;
          pdfTable.WidthPercentage = 100;
          pdfTable.HorizontalAlignment = Element.ALIGN_LEFT;
          pdfTable.DefaultCell.BorderWidth = 1;
  
          //Adding Header row from DGV to PDFTable
          foreach (DataGridViewColumn column in dataGridView1.Columns)
          {
              PdfPCell cell = new PdfPCell(new Phrase(column.HeaderText));
              //cell.BackgroundColor = new iTextSharp.text.Color(240, 240, 240);
              pdfTable.AddCell(cell);
          }
  
          //Adding DataRow from DGV to PDFTable
          foreach (DataGridViewRow row in dataGridView1.Rows)
          {
              foreach (DataGridViewCell cell in row.Cells)
              {
                  try
                  {
                      pdfTable.AddCell(cell.Value.ToString());
                  }
                  catch { }
              }
          }
  
          //PDFVariablesForPathAndNaming
          int filecount = 0;
          int i;
          string path = pathtofile1;
  
          for (i = 0; File.Exists(path + @"YTLHPITARF_" + i + DateTime.Now.ToString("yyyyMMdd") + ".pdf"); i++)
          {
              filecount = i + 1;
          }
  
          string fileLoc = path + @"YTLHPITARF_" + filecount + DateTime.Now.ToString("yyyyMMdd") + ".pdf";
          var filename = Path.GetFileName(fileLoc);
          string pathtofile2 = pathtofile1 + filename;
  
          //ToBeUsedInDataBase
          dName = filename;
  
          //Start of PDF Creation
          Document document = new Document(iTextSharp.text.PageSize.A4.Rotate());
          PdfWriter.GetInstance(document, new FileStream(fileLoc, FileMode.Create));
          document.Open();
  
          //FontSizeAndFormat
          iTextSharp.text.Font head1 = FontFactory.GetFont("Arial", 14, iTextSharp.text.Font.BOLD);
          iTextSharp.text.Font head2 = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.NORMAL);
          iTextSharp.text.Font head3 = FontFactory.GetFont("Arial", 10, iTextSharp.text.Font.NORMAL);
          iTextSharp.text.Font bold1 = FontFactory.GetFont("Arial", 12, iTextSharp.text.Font.BOLD);
  
          Paragraph a1 = new Paragraph("ASSET RETURN FORM", head1);
          Paragraph a2 = new Paragraph("(due to Staff resign / Outlet close / Repair)" + "\n\n", head2);
  
          Paragraph b1 = new Paragraph("OWNER NAME: ", head3);
          b1 = new Paragraph();
          b1.Add(new Chunk("OWNER NAME: ", head3));
          iTextSharp.text.TabSettings tab = new TabSettings();
          b1.Add(Chunk.TABBING);
          b1.Add(Chunk.TABBING);
          b1.Add(Chunk.TABBING);
          b1.Add(Chunk.TABBING);
          b1.Add(Chunk.TABBING);
          b1.Add(Chunk.TABBING);
          b1.Add(Chunk.TABBING);
          b1.Add(Chunk.TABBING);
          b1.Add(Chunk.TABBING);
          b1.Add(Chunk.TABBING);
          b1.Add(Chunk.TABBING);
          b1.Add(Chunk.TABBING);
          b1.Add(Chunk.TABBING);
          b1.Add(Chunk.TABBING);
          b1.Add(Chunk.TABBING);
          b1.Add(Chunk.TABBING);
          b1.Add(new Chunk("Property Name: ", head3));
  
          Paragraph c1 = new Paragraph("SUBMITTED BY: "+ "\n\n" + "\n", head3);
          Paragraph d1 = new Paragraph("NAME: ", head3);
          Paragraph e1 = new Paragraph("DATE: " + DateTime.Today.ToString("yyyyMMdd"), head3);
  
          //Paragraph Alignment
          a1.Alignment = Element.ALIGN_CENTER;
          a2.Alignment = Element.ALIGN_CENTER;
  
          //Paragraph Insertion
          document.Add(a1);
          document.Add(a2);
          document.Add(b1);
          pdfTable.SpacingBefore = 3f;
          document.Add(pdfTable);
          document.Add(c1);
          document.Add(d1);
          document.Add(e1);
          //document.Add(f1);
          //document.Add(g1);
  
          //CloseCreationOfPDF
          document.Close();
  
          //OpenCreatedPDF
          System.Diagnostics.Process.Start(pathtofile2);
  }
  </code></pre>