PDF Form Fields overlaps with pdf text

Hi Team, I am adding Form Field using formeditor.addfield , text form fields get added properly in PDF however at some places the form field gets overlap with other text on pdf.

I am using Aspose.pdf 11.8 version.

                    formEditor.AddField(DataUtil.GetInt32(drToken("FieldType")) _
                                        , DataUtil.GetString(drToken("TokenName")) & "_" & TokenCnt.ToString _
                                        , DataUtil.GetInt32(Page.Number) _
                                        , LLX _
                                        , LLY _
                                        , DataUtil.GetInt32(drToken("URX")) _
                                        , DataUtil.GetInt32(drToken("URY")))

Thank you

@asposeDp,

It seems that you are using very old version of API. It is always recommended to use the latest version of API as it contains new features and bug fixes reported by other customer. Please download the latest version of the API i.e. Aspose.PDF for .NET 18.6 and use it at your end. In case the issue persists, feel free to reach us along with sample input and out files and complete code snippet to reproduce the issue at our end.

Sample.pdf (307.1 KB)
TextField_Created_PDF.pdf (312.5 KB)
Overlapping_Text.png (20.6 KB)
dll_Properties.png (14.9 KB)
I tried using latest aspose.pdf however it did not worked. I have attached all files for your reference.
my code:
Dim absorber As New TextFragmentAbsorber(phrase:="<(?.*?)>>", textSearchOptions:=New TextSearchOptions(True))
pdfdocument.Pages.Accept(absorber)
If absorber.TextFragments.Count > 0 Then
'<<LSONEAMT_BS1>>
Dim InitialWidth As Int32 = 23
Dim SignatureWidth As Int32 = 80
Dim SignatureFieldHeight As Int32 = 13
Dim Offset As Int32 = 1

            CreateTokenTable()

            Dim formEditor As New Facades.FormEditor(pdfdocument)

            'Record the tokens 
            For Each fragment As TextFragment In absorber.TextFragments
                Tokenname = fragment.Text.ToUpper.Replace("<", "").Replace(">", "")
                AddTokenDimensions(Facades.FieldType.Text, Tokenname, fragment.Page.Number, fragment, DataUtil.GetInt32(IIf(fragment.Text.ToUpper.Contains("INITIAL"), InitialWidth, SignatureWidth)), SignatureFieldHeight)
                Dim isTokenValid = IsValidToken(Tokenname, valToken)
                AddTokensToDocTokensTable(isTokenValid, valToken)
            Next

            For Each fragment As TextFragment In absorber.TextFragments
                fragment.Text = String.Empty 'New String(" "c, fragment.Text.Length)
            Next

            'place tokens
            Dim dr() As DataRow
            Dim LLX As Int32, LLY As Int32
            Dim RowBottom As Int32
            For Each Page As Aspose.Pdf.Page In pdfdocument.Pages
                dr = dtSignTokens.Select("PageIndex=" & Page.Number, "LLY asc, LLX asc")
                If dr IsNot Nothing AndAlso dr.Count > 0 Then
                   
                    For Each drToken As DataRow In dr
                        LLX = DataUtil.GetInt32(drToken("LLX"))
                        LLY = DataUtil.GetInt32(drToken("LLY"))
                       

                        formEditor.AddField(DataUtil.GetInt32(drToken("FieldType")) _
                                            , DataUtil.GetString(drToken("TokenName")) & "_" & TokenCnt.ToString _
                                            , DataUtil.GetInt32(Page.Number) _
                                            , LLX _
                                            , LLY _
                                            , DataUtil.GetInt32(drToken("URX")) _
                                            , DataUtil.GetInt32(drToken("URY")))

                       
                        TokenCnt = TokenCnt + 1

                    Next
                End If
            Next
            formEditor.Save(_filepath)
        End If

Private Sub CreateTokenTable()
dtSignTokens = New DataTable
dtSignTokens.Columns.Add(“FieldType”, GetType(Int32))
dtSignTokens.Columns.Add(“TokenName”, GetType(String))
dtSignTokens.Columns.Add(“FieldWidth”, GetType(Int32))
dtSignTokens.Columns.Add(“FieldHeight”, GetType(Int32))
dtSignTokens.Columns.Add(“PageIndex”, GetType(Int32))
dtSignTokens.Columns.Add(“LLX”, GetType(Int32))
dtSignTokens.Columns.Add(“LLY”, GetType(Int32))
dtSignTokens.Columns.Add(“URX”, GetType(Int32))
dtSignTokens.Columns.Add(“URY”, GetType(Int32))
dtSignTokens.AcceptChanges()
End Sub
Private Sub AddTokenDimensions(FldType As Facades.FieldType, TokenName As String, PageIndex As Int32, TF As TextFragment, FieldWidth As Int32, FieldHeight As Int32)

        Dim dr As DataRow = dtSignTokens.NewRow
        dr("FieldType") = DataUtil.GetInt32(FldType)
        dr("TokenName") = TokenName
        dr("FieldWidth") = FieldWidth
        dr("FieldHeight") = FieldHeight
        dr("PageIndex") = PageIndex
        dr("LLX") = TF.Rectangle.LLX
        dr("LLY") = TF.Rectangle.LLY
        dr("URX") = TF.Rectangle.URX
        dr("URY") = TF.Rectangle.URY
        dtSignTokens.Rows.Add(dr)
        dtSignTokens.AcceptChanges()
    End Sub

@asposeDp,

There are unknown methods and objects in your code, e.g. IsValidToken, AddTokensToDocTokensTable and DataUtil. Please send us the complete code, so that we could replicate this issue in our environment. Your response is awaited.

Thank you Imran for looking into this, below is my code without unknown methods

   Private dtSignTokens As DataTable

    Private Sub ReplacePDFSignTokens(ByRef pdfdocument As Aspose.Pdf.Document)
        'get the tokens from all pages
        Dim TokenCnt As Int64 = 1
        Dim Tokenname, valToken As String
        Dim absorber As New TextFragmentAbsorber(phrase:="\<(?<token>.*?)\>>", textSearchOptions:=New TextSearchOptions(True))
        pdfdocument.Pages.Accept(absorber)

       
        If absorber.TextFragments.Count > 0 Then
            '<<LSONEAMT_BS1>>
            Dim InitialWidth As Int32 = 23
            Dim SignatureWidth As Int32 = 80
            Dim SignatureFieldHeight As Int32 = 13
            Dim Offset As Int32 = 1

            CreateTokenTable()

            Dim formEditor As New Facades.FormEditor(pdfdocument)


            'Record the tokens 
            For Each fragment As TextFragment In absorber.TextFragments
                Tokenname = fragment.Text.ToUpper.Replace("<", "").Replace(">", "")
                AddTokenDimensions(Facades.FieldType.Text, Tokenname, fragment.Page.Number, fragment, InitialWidth, SignatureFieldHeight)
            Next

            For Each fragment As TextFragment In absorber.TextFragments
                fragment.Text = String.Empty
            Next

            'place tokens
            Dim dr() As DataRow
            Dim LLX As Int32, LLY As Int32
            Dim RowBottom As Int32
            For Each Page As Aspose.Pdf.Page In pdfdocument.Pages
                dr = dtSignTokens.Select("PageIndex=" & Page.Number, "LLY asc, LLX asc")
                If dr IsNot Nothing AndAlso dr.Count > 0 Then
                    

                    For Each drToken As DataRow In dr
                        LLX = CInt(drToken("LLX"))
                        LLY = CInt(drToken("LLY"))
                     

                        formEditor.AddField(CInt(drToken("FieldType")) _
                                            , CStr(drToken("TokenName")) & "_" & TokenCnt.ToString _
                                            , CInt(Page.Number) _
                                            , LLX _
                                            , LLY _
                                            , CInt(drToken("URX")) _
                                            , CInt(drToken("URY")))

                        TokenCnt = TokenCnt + 1

                    Next
                End If
            Next
            formEditor.Save(_filepath)
        End If


    End Sub
    Private Sub CreateTokenTable()
        dtSignTokens = New DataTable
        dtSignTokens.Columns.Add("FieldType", GetType(Int32))
        dtSignTokens.Columns.Add("TokenName", GetType(String))
        dtSignTokens.Columns.Add("FieldWidth", GetType(Int32))
        dtSignTokens.Columns.Add("FieldHeight", GetType(Int32))
        dtSignTokens.Columns.Add("PageIndex", GetType(Int32))
        dtSignTokens.Columns.Add("LLX", GetType(Int32))
        dtSignTokens.Columns.Add("LLY", GetType(Int32))
        dtSignTokens.Columns.Add("URX", GetType(Int32))
        dtSignTokens.Columns.Add("URY", GetType(Int32))
        dtSignTokens.AcceptChanges()
    End Sub
    Private Sub AddTokenDimensions(FldType As Facades.FieldType, TokenName As String, PageIndex As Int32, TF As TextFragment, FieldWidth As Int32, FieldHeight As Int32)

        Dim dr As DataRow = dtSignTokens.NewRow
        dr("FieldType") = CInt(FldType)
        dr("TokenName") = TokenName
        dr("FieldWidth") = FieldWidth
        dr("FieldHeight") = FieldHeight
        dr("PageIndex") = PageIndex
        dr("LLX") = TF.Rectangle.LLX
        dr("LLY") = TF.Rectangle.LLY
        dr("URX") = TF.Rectangle.URX
        dr("URY") = TF.Rectangle.URY
        dtSignTokens.Rows.Add(dr)
        dtSignTokens.AcceptChanges()
    End Sub

@asposeDp,

We managed to replicate the problem of overlapping text in our environment. An enhancement has been logged under the ticket ID PDFNET-44872 in our issue tracking system. We have linked your post to this ticket and will keep you informed regarding any available updates.

Thank you. I am waiting for this fix to be available.

@asposeDp,

Sure, we will notify you once it is fixed.

Hi Imran,

Any progress on this issue ?
Could you please let know, when this will be available ?

Thank you

@asposeDp

Thanks for your inquiry.

I am afraid that earlier logged issue is not yet resolved due to large number of pending issues in the queue. Please note that the issue was logged under free support model having low priority and it will be investigated/resolved on first come first serve basis. As soon as we have some significant update regarding its resolution, we will inform you.

Furthermore, you may also check our paid support model where issues are resolved on priority basis in case your issue is urgent.

We are sorry for the inconvenience.