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.

Tue Sep 03, 2024 7:55 am

Hello, i have developed a .Net 8.0 Library that uses the Comunity Edition of Spire PDF to fill Form Text-Fields by Name of the Field.

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>

enny_dev
 
Posts: 1
Joined: Sat Mar 30, 2024 6:43 am

Wed Sep 04, 2024 8:47 am

Hello,

Thanks for your inquiry.
From your information, I learned that you are using our older free version. Our free version is only updated irregularly. Based on your situation, we recommend that you use our latest version(spir.pdf for. NET Version: 10.8.1) for testing as it has more fixes and optimizations. If the problem still persists after testing with the latest version, please provide us with your original input PDF document for investigation.You can upload here or send it to us via email( support@e-iceblue.com ). Thank you in advance.

Sincerely,
Amin
E-iceblue support team
User avatar

Amin.Gan
 
Posts: 277
Joined: Mon Jul 15, 2024 5:40 am

Return to Spire.PDF