Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Mon Jun 27, 2022 12:49 pm

Hello,

I setup a little process to loop through a CSV file and generate PDF files using the data in the csv.
Everything works fine except the text in the generated PDF files is not aligned properly with the boxes in the PDF. If i remove the data and fill it manually the alignment is fine.

Am I missing a step or doing something wrong? Below is my code to autofill the PDF form and attached are the sample CSV file, PDF Form Template and a FreeSpire.PDF generated example showing the issue.

Code: Select all
Dim doc As PdfDocument = New PdfDocument()
        doc.LoadFromFile(Server.MapPath("~/templates/" + Label1.Text))
        Dim form As PdfFormWidget = CType(doc.Form, PdfFormWidget)
        Dim formWidgetCollection As PdfFormFieldWidgetCollection = form.FieldsWidget

        For i As Integer = 0 To GridView1.Rows.Count - 1

            Dim row As GridViewRow = GridView1.Rows(i)


            For ii As Integer = 0 To formWidgetCollection.Count - 1
                Dim field As PdfField = formWidgetCollection(ii)



                If TypeOf field Is PdfTextBoxFieldWidget Then

                    If field.Name = "TF001" Then
                        Dim textBoxField As PdfTextBoxFieldWidget = CType(field, PdfTextBoxFieldWidget)
                        textBoxField.Font = New PdfTrueTypeFont(Server.MapPath("~/bin/Arial.ttf"), 10.0F)
                        textBoxField.Text = row.Cells(0).Text


                    End If

                    If field.Name = "TF002" Then
                        Dim textBoxField As PdfTextBoxFieldWidget = CType(field, PdfTextBoxFieldWidget)
                        textBoxField.Font = New PdfTrueTypeFont(Server.MapPath("~/bin/Arial.ttf"), 10.0F)
                        textBoxField.Text = row.Cells(1).Text
                    End If

                    If field.Name = "TF003" Then
                        Dim textBoxField As PdfTextBoxFieldWidget = CType(field, PdfTextBoxFieldWidget)
                        textBoxField.Font = New PdfTrueTypeFont(Server.MapPath("~/bin/Arial.ttf"), 10.0F)
                        textBoxField.Text = row.Cells(2).Text
                    End If

                    If field.Name = "TF004" Then
                        Dim textBoxField As PdfTextBoxFieldWidget = CType(field, PdfTextBoxFieldWidget)
                        textBoxField.Font = New PdfTrueTypeFont(Server.MapPath("~/bin/Arial.ttf"), 10.0F)
                        textBoxField.Text = row.Cells(3).Text
                    End If

                    If field.Name = "TF005" Then
                        Dim textBoxField As PdfTextBoxFieldWidget = CType(field, PdfTextBoxFieldWidget)
                        textBoxField.Font = New PdfTrueTypeFont(Server.MapPath("~/bin/Arial.ttf"), 10.0F)
                        textBoxField.Text = row.Cells(4).Text
                    End If

                    If field.Name = "TF006" Then
                        Dim textBoxField As PdfTextBoxFieldWidget = CType(field, PdfTextBoxFieldWidget)
                        textBoxField.Font = New PdfTrueTypeFont(Server.MapPath("~/bin/Arial.ttf"), 10.0F)
                        textBoxField.Text = row.Cells(5).Text
                    End If

                    If field.Name = "TF007" Then
                        Dim textBoxField As PdfTextBoxFieldWidget = CType(field, PdfTextBoxFieldWidget)
                        textBoxField.Font = New PdfTrueTypeFont(Server.MapPath("~/bin/Arial.ttf"), 10.0F)
                        textBoxField.Text = row.Cells(6).Text
                    End If

                    If field.Name = "TF008" Then
                        Dim textBoxField As PdfTextBoxFieldWidget = CType(field, PdfTextBoxFieldWidget)
                        textBoxField.Font = New PdfTrueTypeFont(Server.MapPath("~/bin/Arial.ttf"), 10.0F)
                        textBoxField.Text = row.Cells(7).Text
                    End If

                    If field.Name = "TF009" Then
                        Dim textBoxField As PdfTextBoxFieldWidget = CType(field, PdfTextBoxFieldWidget)
                        textBoxField.Font = New PdfTrueTypeFont(Server.MapPath("~/bin/Arial.ttf"), 10.0F)
                        textBoxField.Text = row.Cells(8).Text
                    End If

                    If field.Name = "TF010" Then
                        Dim textBoxField As PdfTextBoxFieldWidget = CType(field, PdfTextBoxFieldWidget)
                        textBoxField.Font = New PdfTrueTypeFont(Server.MapPath("~/bin/Arial.ttf"), 10.0F)
                        textBoxField.Text = row.Cells(9).Text
                    End If

                    If field.Name = "TF011" Then
                        Dim textBoxField As PdfTextBoxFieldWidget = CType(field, PdfTextBoxFieldWidget)
                        textBoxField.Font = New PdfTrueTypeFont(Server.MapPath("~/bin/Arial.ttf"), 10.0F)
                        textBoxField.Text = row.Cells(10).Text
                    End If

                    If field.Name = "TF012" Then
                        Dim textBoxField As PdfTextBoxFieldWidget = CType(field, PdfTextBoxFieldWidget)
                        textBoxField.Font = New PdfTrueTypeFont(Server.MapPath("~/bin/Arial.ttf"), 10.0F)
                        textBoxField.Text = row.Cells(11).Text
                    End If

                    If field.Name = "TF013" Then
                        Dim textBoxField As PdfTextBoxFieldWidget = CType(field, PdfTextBoxFieldWidget)
                        textBoxField.Font = New PdfTrueTypeFont(Server.MapPath("~/bin/Arial.ttf"), 10.0F)
                        textBoxField.Text = row.Cells(12).Text
                    End If

                    If field.Name = "TF014" Then
                        Dim textBoxField As PdfTextBoxFieldWidget = CType(field, PdfTextBoxFieldWidget)
                        textBoxField.Font = New PdfTrueTypeFont(Server.MapPath("~/bin/Arial.ttf"), 10.0F)
                        textBoxField.Text = row.Cells(13).Text
                    End If
                End If
            Next

            doc.SaveToFile(Server.MapPath("~/pdf/" + row.Cells(1).Text + ".pdf"), FileFormat.PDF)
        Next
Last edited by sbgmedia on Wed Jul 06, 2022 5:43 am, edited 1 time in total.

sbgmedia
 
Posts: 6
Joined: Sun Jun 26, 2022 1:05 pm

Tue Jun 28, 2022 8:47 am

Hello,

Thanks for your inquiry.

I have reproduced the issue by your PDF file and logged it in our bug tracking system with the ticket SPIREPDF-5298. If there is any update, I will notify you in time. Sorry for the inconvenience caused.
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Tue Jun 28, 2022 10:22 am

Thank you Andy for your response. Looking forward to the fix when available.

Regards,
Kareem

sbgmedia
 
Posts: 6
Joined: Sun Jun 26, 2022 1:05 pm

Wed Jul 06, 2022 5:50 am

Hi Andy,

I used another application to create the PDF form and tried it and the fields are a lot better aligned now, however one of the fields is not being imported into the form.
I am not sure what is causing that issue.

I have updated the attachments, for your reference.

sbgmedia
 
Posts: 6
Joined: Sun Jun 26, 2022 1:05 pm

Wed Jul 06, 2022 10:30 am

Hi Kareem,

I will forward the files to our dev team. Thanks for your feedback and sharing.
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Thu Jul 07, 2022 9:23 am

Hi Andy,

So I found out that i had a an incorrectly name field which was causing the missing text. I have fixed it and the form works fine, however I have another issue.
All the defined fields on the first page get filled out however the TFN field does not show. It is filled out and the content only shows when I click in the field. This is not a new issue. I noticed it has been there all along. I just did not notice it previously, as some of the entries i used for testing didn't have content for that specific field.
I am attaching the updated/fixed PDF form.

I tried to flatten the pdf to see if it appears then but I get a null exception, when i run the app.
I adding the following code right before the doc.save statement. Am I doing something wrong?

Code: Select all
doc.Form.IsFlatten = True

sbgmedia
 
Posts: 6
Joined: Sun Jun 26, 2022 1:05 pm

Tue Sep 20, 2022 10:08 am

Hello,

Thanks for your message.
Our latest Spire.PDF Pack(Hot Fix) Version:8.9.2 have included the fixing code of SPIREPDF-5298. Meanwhile, I used this version to test your updated file, the filled content could show correcttly when I directly open the file. I hava attached my result for your reference. And I used adobe version:19.021.20061.33636. Thus please download the new version to test and let us know your testing result. Look forward to your further response.

Sincerely,
Simple
E-iceblue support team
User avatar

Simple.Li
 
Posts: 248
Joined: Fri Jul 01, 2022 2:33 am

Return to Spire.PDF