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 14, 2021 7:12 am

Good Morning E-IceBlue Support,

I am using Spire.PDF in .NET, currently testing its suitability for an upcoming commercial application.

I am satisfied so far with the SDK, but I am running into difficulty with the following;

Having spend considerable time looking for a fix, some support from your team would be helpful.
The application will take a source PDF (that contains widget fields), and create a new output PDF (with the fields)

An earlier problem that would not allow me to simply transfer the FieldsWidget collection directly in the new PDF was overcome by creating a new PDFField for each item.
The issue I am now facing is that for any fields with larger font sizes, although the field is created in the new document, the item is not displayed.

Font : Calibri (Size 26)

Please see the source code below;
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Parameters to this function
FieldWidgetItem = Widget Item from Source Document
FieldText = Text to be displayed on New Field
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Dim PageAnchor As PdfPageBase = {New Output PDF File}

AddField.DefaultValue = AddField.FullName.ToString
AddField.Bounds = FieldWidgetItem.Bounds
AddField.Text = ""
If Not IsNothing(FieldText) Then AddField.Text = FieldText

' Field Appearance Settings
AddField.Font = FieldWidgetItem.Font
AddField.HighlightMode = FieldWidgetItem.HighlightMode
AddField.ForeColor = FieldWidgetItem.ForeColor
AddField.BackColor = Color.Transparent
AddField.TextAlignment = FieldWidgetItem.TextAlignment
AddField.BorderWidth = 0
AddField.ReadOnly = True

PageAnchor.Document.Form.Fields.Add(AddField)


When I open the 'Output' PDF, the fields for the regular sizes display correctly.
But for the fields with the larger font sizes (in this case - Size 26) the text is not displayed.
When I open the Output File in Acrobat, and change the field font size to 25 and then back to 26 it displays fine.

It seems that the font is not being embedded into the PDF when I add the field to the document.

The collection 'UsedFonts' seems to be read only, and I am unable to find a way to manually embed the Calibri Font into the document.

Any thoughts would be appreciated on how to fix this issue.

Kind Regards,
Pete

spirepdfuser
 
Posts: 2
Joined: Mon Jun 14, 2021 6:56 am

Mon Jun 14, 2021 12:30 pm

Hi,

Thanks for your inquiry.
I did an initial test with our latest Spire.PDF Pack Version:7.6, but didn't reproduce your issue. The text with large size (26) could display correctly. Below is my full test code. If you were not using the latest version, please first give it a try. If the issue still happens on your side, please provide the following information for further investigation. You could attach them here or send to us via email ([email protected]). Thanks in advance.
1. Your source PDF and resultant PDF.
2. Your full testing code.
3. Your app type, such as console app (.NET Framework 4.7)
Code: Select all
 'Load source Pdf
 Dim input As String = "Test.pdf"
 Dim doc As New PdfDocument()
 doc.LoadFromFile(input)
 'Create a new Pdfdocument
 Dim pdf As PdfDocument = New PdfDocument()
 'Add a page
 Dim PageAnchor As PdfPageBase = pdf.Pages.Add()

 'Get pdf forms
 Dim formWidget As PdfFormWidget = TryCast(doc.Form, PdfFormWidget)

 For i As Integer = 0 To formWidget.FieldsWidget.List.Count - 1
     Dim field As PdfField = TryCast(formWidget.FieldsWidget.List(i), PdfField)
     If TypeOf field Is PdfTextBoxFieldWidget Then
         Dim textBoxField As PdfTextBoxFieldWidget = TryCast(field, PdfTextBoxFieldWidget)
         Dim FieldText = textBoxField.Text
         Dim AddField = New PdfTextBoxField(PageAnchor, "TextBox" + i.ToString())
         AddField.DefaultValue = AddField.FullName.ToString
         AddField.Bounds = textBoxField.Bounds
         AddField.Text = ""
         If Not IsNothing(FieldText) Then AddField.Text = FieldText
         AddField.Font = textBoxField.Font
         AddField.HighlightMode = textBoxField.HighlightMode
         AddField.ForeColor = textBoxField.ForeColor
         AddField.BackColor = Color.Transparent
         AddField.TextAlignment = textBoxField.TextAlignment
         AddField.BorderWidth = 0
         AddField.ReadOnly = True
         PageAnchor.Document.Form.Fields.Add(AddField)
     End If
 Next i
 'Save PDF document
 pdf.SaveToFile("result.pdf", FileFormat.PDF)
Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1385
Joined: Tue Sep 27, 2016 1:06 am

Mon Jun 14, 2021 6:45 pm

Dear Nina,
many thanks for such a prompt reply.

I have created a new Windows Form Visual Studio project, just containing the relevant code.
I am currently using Visual Basic in Visual Studio 2019, with the Spire.PDF package Version 7.6.1 installed.
It will eventually run within a Windows Service.

Please see the code below, and I have included the INPUT.pdf file for your review.
I have stripped the Invoice PDF back to just show the elements I am having issue with.
Source Code below;


The Calibri font is not used in the output file
and the same issue of the larger fonts not appearing in fields FIELD:AMOUNTNUMBER & FIELD:AMOUNTDECIMALCURRENCY remains.

There will be a requirement for Acrobat to be used, to create templates such as the Input file.
These seem to be stored in the Widgets class within Spire.PDF, and when trying to create the same Widget Class for the output file,
no text appears, which is why it has been needed to create PdfFields and add it this way.

Any thoughts or suggestions I would be most grateful.
It is probably a simple fix but I can't seem to spot it.

Regards,
Pete


Private Sub ButtonStart_Click(sender As Object, e As EventArgs) Handles ButtonStart.Click
' Visual Studio 2019
' ' Using Spire.PDF Version 7.6.1
' ' As per requirements, Acrobat is used to create the template file including
' the field items that appear in the pdf.

' Current Observations
' * All Fields in the input file are using the 'Calibri' Font
' But after execution of the code, the fields in the output file are 'Helvetica'
' * The fields contains the larger fonts that appear at the end of this routine,
' do not appear on the output pdf.

' Using Spire.PDF Version 7.6.1
Dim PathInputFile As String = "C:\Users\Peter\Desktop\SpirePDF Test\input.pdf"
Dim PathOutputFile As String = "C:\Users\Peter\Desktop\SpirePDF Test\output.pdf"

Dim InputFile As New Spire.Pdf.PdfDocument
Dim OutputFile As New Spire.Pdf.PdfDocument
InputFile.LoadFromFile(PathInputFile)
OutputFile.LoadFromFile(PathInputFile)

Dim InputFile_Widgets As Spire.Pdf.Widget.PdfFormWidget = InputFile.Form
Dim OutputFile_Widgets As Spire.Pdf.Widget.PdfFormWidget = OutputFile.Form

Dim Fields As New List(Of Object)
Dim WidgetItems_ToDelete As New List(Of Integer)

For Each WidgetItem In InputFile_Widgets.FieldsWidget.List
Fields.Add(WidgetItem)
WidgetItems_ToDelete.Add(InputFile_Widgets.FieldsWidget.List.IndexOf(WidgetItem))
Next
WidgetItems_ToDelete.Reverse()
For Each WidgetItem In WidgetItems_ToDelete
OutputFile_Widgets.FieldsWidget.RemoveAt(WidgetItem)
Next

' -----------------------------------------
' Add a number of fields to the output file
' -----------------------------------------
Dim FieldWidget As Spire.Pdf.Widget.PdfTextBoxFieldWidget = Nothing

FieldWidget = Fields.Find(Function(Widget As Spire.Pdf.Widget.PdfTextBoxFieldWidget) Widget.FullName = "FIELD:INVOICE")
If IsNothing(FieldWidget) Then End
AddField(OutputFile, FieldWidget, "INV123456", "FIELD:INVOICE")

FieldWidget = Fields.Find(Function(Widget As Spire.Pdf.Widget.PdfTextBoxFieldWidget) Widget.FullName = "FIELD:CUSTOMERNAME")
If IsNothing(FieldWidget) Then End
AddField(OutputFile, FieldWidget, "CUSTOMER NAME", "FIELD:CUSTOMERNAME")

FieldWidget = Fields.Find(Function(Widget As Spire.Pdf.Widget.PdfTextBoxFieldWidget) Widget.FullName = "FIELD:CUSTOMERADDRESS1")
If IsNothing(FieldWidget) Then End
AddField(OutputFile, FieldWidget, "CUSTOMER ADDRESS - LINE 1", "FIELD:CUSTOMERADDRESS1")

FieldWidget = Fields.Find(Function(Widget As Spire.Pdf.Widget.PdfTextBoxFieldWidget) Widget.FullName = "FIELD:CUSTOMERADDRESS2")
If IsNothing(FieldWidget) Then End
AddField(OutputFile, FieldWidget, "CUSTOMER ADDRESS - LINE 2", "FIELD:CUSTOMERADDRESS2")

FieldWidget = Fields.Find(Function(Widget As Spire.Pdf.Widget.PdfTextBoxFieldWidget) Widget.FullName = "FIELD:CUSTOMERADDRESS3")
If IsNothing(FieldWidget) Then End
AddField(OutputFile, FieldWidget, "CUSTOMER ADDRESS - LINE 3", "FIELD:CUSTOMERADDRESS3")

FieldWidget = Fields.Find(Function(Widget As Spire.Pdf.Widget.PdfTextBoxFieldWidget) Widget.FullName = "FIELD:CUSTOMERADDRESS4")
If IsNothing(FieldWidget) Then End
AddField(OutputFile, FieldWidget, "CUSTOMER ADDRESS - LINE 4", "FIELD:CUSTOMERADDRESS4")

FieldWidget = Fields.Find(Function(Widget As Spire.Pdf.Widget.PdfTextBoxFieldWidget) Widget.FullName = "FIELD:CUSTOMERADDRESS5")
If IsNothing(FieldWidget) Then End
AddField(OutputFile, FieldWidget, "CUSTOMER ADDRESS - LINE 5", "FIELD:CUSTOMERADDRESS5")

' INVOICE AMOUNT
FieldWidget = Fields.Find(Function(Widget As Spire.Pdf.Widget.PdfTextBoxFieldWidget) Widget.FullName = "FIELD:AMOUNTNUMBER")
If IsNothing(FieldWidget) Then End
AddField(OutputFile, FieldWidget, "10,000", "FIELD:AMOUNTNUMBER")

FieldWidget = Fields.Find(Function(Widget As Spire.Pdf.Widget.PdfTextBoxFieldWidget) Widget.FullName = "SHADOW:AMOUNTNUMBER")
If IsNothing(FieldWidget) Then End
AddField(OutputFile, FieldWidget, "10,000", "SHADOW:AMOUNTNUMBER")

FieldWidget = Fields.Find(Function(Widget As Spire.Pdf.Widget.PdfTextBoxFieldWidget) Widget.FullName = "FIELD:AMOUNTDECIMALCURRENCY")
If IsNothing(FieldWidget) Then End
AddField(OutputFile, FieldWidget, ".00 USD", "FIELD:AMOUNTDECIMALCURRENCY")

FieldWidget = Fields.Find(Function(Widget As Spire.Pdf.Widget.PdfTextBoxFieldWidget) Widget.FullName = "SHADOW:AMOUNTDECIMALCURRENCY")
If IsNothing(FieldWidget) Then End
AddField(OutputFile, FieldWidget, ".00 USD", "SHADOW:AMOUNTDECIMALCURRENCY")

OutputFile.SaveToFile(PathOutputFile)
End Sub

Private Sub AddField(ByRef OutputFile As PdfDocument, ByVal FieldWidget As Spire.Pdf.Widget.PdfTextBoxFieldWidget, ByVal FieldText As String, ByVal FieldName As String)
Dim PageAnchor As PdfPageBase = OutputFile.Pages(OutputFile.Pages.Count - 1)
Dim AddField = New Fields.PdfTextBoxField(PageAnchor, FieldName)
AddField.DefaultValue = AddField.FullName.ToString
With FieldWidget
AddField.Bounds = .Bounds
AddField.Text = ""
If Not IsNothing(FieldText) Then AddField.Text = FieldText
AddField.Font = .Font
AddField.HighlightMode = .HighlightMode
AddField.ForeColor = .ForeColor
AddField.BackColor = Color.Transparent
AddField.TextAlignment = .TextAlignment
AddField.BorderWidth = 0
AddField.ReadOnly = True
End With

PageAnchor.Document.Form.Fields.Add(AddField)
End Sub

spirepdfuser
 
Posts: 2
Joined: Mon Jun 14, 2021 6:56 am

Tue Jun 15, 2021 5:42 am

Hello Pete,

Thanks for your sharing.
I tested your case and did find that the text filled in for the fields “FIELD:AMOUNTNUMBER” and “FIELD:AMOUNTDECIMALCURRENCY” is not displayed correctly. I have logged the issue in our bug tracking system with the ticket SPIREPDF-4388. If there is any update, we will let you know. Apologize for the inconvenience caused.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Return to Spire.PDF

cron