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
Login to view the files attached to this post.