During tests on MacOs 14.6. i got a NullReference Exception below at different Fields during iterating the FormFields and set the Text.
System.NullReferenceException: Object reference not set to an instance of an object.
at spr읚.윻()
at spr읚.()
at Spire.Pdf.Graphics.PdfTrueTypeFont.얱()
at Spire.Pdf.Graphics.PdfTrueTypeFont.얱(spr큷 A_0)
at Spire.Pdf.Graphics.PdfTrueTypeFont..ctor(spr큷 A_0, Single A_1, Boolean A_2)
at Spire.Pdf.Widget.PdfStyledFieldWidget.얱(String A_0, Boolean& A_1)
at Spire.Pdf.Widget.PdfStyledFieldWidget.get_Font()
at Spire.Pdf.Widget.PdfStyledFieldWidget.GraphicsProperties..ctor(PdfStyledFieldWidget fieldWidget)
at Spire.Pdf.Widget.PdfStyledFieldWidget.GetGraphicsProperties(GraphicsProperties& graphicsProperties, PdfFieldWidgetItem widgetItem)
at Spire.Pdf.Widget.PdfTextBoxFieldWidget.얱(PdfCanvas A_0, PdfFieldWidgetItem A_1)
at Spire.Pdf.Widget.PdfTextBoxFieldWidget.얱(spr㫕 A_0)
at Spire.Pdf.Widget.PdfTextBoxFieldWidget.얱(String A_0)
at Spire.Pdf.Widget.PdfTextBoxFieldWidget.set_Text(String value)
at SignoMed.Pdf.FreeSpire.FormFill.FillFormFields(FileInfo inputPdf, FileInfo outputPdf, Dictionary`2 keyValuePairs, Dictionary`2 fieldKeyMapping, Boolean watermark) in /Users/enricoziehe/Projects/.......pdf/FreeSpire/FormFill.cs:line 62
this never happends on a Windows machine. So i gues this is a problem related to the environment.
the relevant code will be
- Code: Select all
for (int i = 0; i < pdfForm.FieldsWidget.List.Count; i++)
{
PdfField field = pdfForm.FieldsWidget.List[i] as PdfField;
if (field is PdfTextBoxFieldWidget)
{
PdfTextBoxFieldWidget textBox = (PdfTextBoxFieldWidget)field;
if (retVal.FirstOrDefault(x => x.PosX == textBox.Location.X && x.PosY == textBox.Location.Y && x.PageNr == document.Pages.IndexOf(field.Page)) == null)
{
retVal.Add(new FormEntry() { EntryType = FormEntryType.TextField, Name = textBox.Name, Contend = textBox.Text, PosX = textBox.Location.X, PosY = textBox.Location.Y, PageNr = document.Pages.IndexOf(field.Page),PageSize=field.Page.Size });
Debug.WriteLine($"processing TextBox {textBox.Name}");
if (keyValuePairs.ContainsKey(textBox.Name))
{
[color=#FF0000]textBox.Text = keyValuePairs[textBox.Name];[/color]
}
else if (useMaping)
{
if (fieldKeyMapping.ContainsKey(textBox.Name))
{
textBox.Text = keyValuePairs[fieldKeyMapping[textBox.Name]];
}
}
The red maked Line raises the exception. after 5-7 Fields to fill.
Has sombody souch problem ? How can i workaround ?
My Environment:
VS-Code
Version: 1.92.2
Commit: fee1edb8d6d72a0ddff41e5f71a671c23ed924b9
Datum: 2024-08-14T17:29:30.058Z
Electron: 30.1.2
ElectronBuildId: 9870757
Chromium: 124.0.6367.243
Node.js: 20.14.0
V8: 12.4.254.20-electron.0
Betriebssystem: Darwin arm64 23.6.0
Console App at .Net 8.0.7
<ItemGroup>
<PackageReference Include="FreeSpire.PDF" Version="10.2.0" />
<PackageReference Include="skiasharp" Version="2.88.7" />
<PackageReference Include="System.Drawing.Common" Version="8.0.6" />
</ItemGroup>