title: Difference in absolute positioning of Text in iText5 and iText7
body: <p>I am trying to migrate from <code>iText5</code> to <code>iText7</code>, but there has been an issue with absolute positioning of texts. It seems that there's a quite a bit of offset in the relative positions of same texts even after giving exact same measurements to iText5 and iText7.</p>
  
  <p>Here is the code that shows the problem:</p>
  
  <pre><code>using iText.Kernel.Geom;
  using iText.Kernel.Pdf;
  using iText.Layout;
  using iText.Layout.Element;
  using System;
  using System.Collections.Generic;
  using System.IO;
  using System.Linq;
  using System.Threading.Tasks;
  using iTextSharp.text;
  using iTextSharp.text.pdf;
  using iText.Kernel.Font;
  
  namespace ConsoleApplication1
  {
      static class Program
      {
          static void Main(string[] args)
          {
              //using iText7
              var folder = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
              var fileName = "iText7.pdf";
              var workingName = "iText5.pdf";
              var finalPath = System.IO.Path.Combine(folder, fileName);
              var WorkingFile = System.IO.Path.Combine(folder, workingName);
  
  
              var pdfWriter = new iText.Kernel.Pdf.PdfWriter(finalPath);
              var pdfDoc = new iText.Kernel.Pdf.PdfDocument(pdfWriter);
              var doc = new iText.Layout.Document(pdfDoc, new iText.Kernel.Geom.PageSize(620.986F, 813.543F));
  
              var font = PdfFontFactory.CreateRegisteredFont("HELVETICA", BaseFont.CP1252, false);
  
  
              doc.SetMargins(0, 0, 0, 0);
  
              doc.PutText(new iText.Layout.Element.Paragraph("TESTLINE").SetFont(font), ConvertCoords(189, 10));
              doc.Flush();
              doc.Close();
  
              //using iText5
              using (var FS = new FileStream(WorkingFile, FileMode.Create, FileAccess.Write, FileShare.None))
              {
                  using (var Doc = new iTextSharp.text.Document(new iTextSharp.text.Rectangle(620.986F, 813.543F), 0, 0, 0, 0))
                  {
                      using (var Writer = iTextSharp.text.pdf.PdfWriter.GetInstance(Doc, FS))
                      {
                          Doc.Open();
                          Doc.NewPage();
                          var pcb = Writer.DirectContent;
                          pcb.BeginText();
  
                          //var font = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false);
                          var fontbold = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, false);                        
  
                          pcb.SetFontAndSize(fontbold, 12);
                          pcb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "TESTLINE", (float)ConvertCoords(189, 10).GetX(), (float)ConvertCoords(189, 10).GetY(), 0);
  
                          pcb.EndText();
                          Writer.Flush();
                          Doc.Close();
                      }
  
                  }
              }
  
  
  
          }
  
          private static void PutText(this iText.Layout.Document doc, iText.Layout.Element.Paragraph text, Point coords,
                                      iText.Layout.Properties.TextAlignment horizontalalign = iText.Layout.Properties.TextAlignment.LEFT,
                                      iText.Layout.Properties.VerticalAlignment verticalalign = iText.Layout.Properties.VerticalAlignment.TOP)
          {
  
              doc.ShowTextAligned(text, (float)coords.GetX(), (float)coords.GetY(), horizontalalign, verticalalign);
          }
  
          //Converts mm to Point
          private static Point ConvertCoords(float a, float b)
          {
              return new Point(a * 2.834265, (287 - b) * 2.834645669291);
          }
      }
  }
  </code></pre>
  
  <p>I am using C#. Could anyone be kind enough to solve this problem? Otherwise, I'd have to undertake a Herculean task to remeasure all the forms.</p>
  
  <p>EDIT:</p>
  
  <p>As per the suggestion, I corrected the oversight of using two different page sizes. I have edited my code above. However, the problem still persists.</p>