We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

System.NullRefenceException when creating TextBoxField

Hey, I have posted issue here I don’t know where we’ll have more comfortable conversation.

I’m working on Linux Alpine system into Docker container. We are using Aspose.PDF 19.12
And trying to make a popup over text fragment (hovering of mouse should trigger to display it). Also
one of requirements is correct work in Goggle Chrome. We found that is the only way to get a solution.

`       var field = new TextBoxField(page, rect);
        field.PartialName = "richField_" + Guid.NewGuid();

        field.Characteristics.Border = Color.FromArgb(100, 104, 82);
        field.Characteristics.Background = Color.FromArgb(255, 255, 226);

        field.Border = new Border(field)
        {
            Style = BorderStyle.Solid
        }; 
        
        field.Flags |= AnnotationFlags.Hidden;

        field.Multiline = true;

        field.DefaultAppearance = new DefaultAppearance(Arial.FontName, 14, Color.Black);

        field.Value = "some text here";
        field.ReadOnly = true;`

Some documents throws NullReferenceException when I trying to edit them on line field.Value = "some text here";.

This is stack trace:

System.NullReferenceException: Object reference not set to an instance of an object.
   at #=zDwGbcB4GP$EtqQOcoR5PHQgAvB5rx0Ym5iSnCDo7WVe2.#=zgkm65jc=(#=zu24DCOrH$PlhJSXxRTH0iOE= #=zTwpRwts=, Boolean #=zt9wEeYbqIXr_, Boolean #=zGsWDMXA=, Boolean #=zgPLU00Q=)
   at #=zDwGbcB4GP$EtqQOcoR5PHQgAvB5rx0Ym5iSnCDo7WVe2.#=zGTnAb3Y9PFUslG1aXw==(#=zQ1QRfnYGY_Cf6TD93PUWH$jxnz8y1t0CDMeG_q0= #=zu1HvU98=, #=zu24DCOrH$PlhJSXxRTH0iOE= #=zTwpRwts=, Boolean #=zgPLU00Q=, String& #=zGba0mfQ=)
   at #=z6FZ0vcBBFfvzvhyPkNKS0DqC$XUWu4G4lxQdd3j0j4jYXAb4D$82BkE=.#=zoa1p39JZSdZI(String #=z7ppX2lY=, #=zQ1QRfnYGY_Cf6TD93PUWH$jxnz8y1t0CDMeG_q0= #=zu1HvU98=, #=zVAG$DdjlHTykOyjIWR019U8hU$Vju69fsA==& #=zlcc2Fm8=, #=zXXJGE6zwmDAguaHaPQVRo9KbuV7h6HXauJIoqXHGHZwm& #=zi2$EDyAUqVcB, String& #=zUfq9SVUIVubm)
   at Aspose.Pdf.Forms.TextBoxField.#=zwy2DxGsDrKE3(#=zE8BHI3k3B4g8 #=zj0KBaOc=, Annotation #=z8PqDbq0=)
   at Aspose.Pdf.Annotations.WidgetAnnotation.#=zIGPt4H4=(Annotation #=z8PqDbq0=)
   at Aspose.Pdf.Forms.Field.#=zx5fFGUg=(String #=z4MuNd_4=)
   at Aspose.Pdf.Forms.Field.set_Value(String value)
   at Aspose.Pdf.Forms.TextBoxField.set_Value(String value)
   at PdfEnriching.Services.Implementation.TextBoxFieldToolTipBuilder.SetUp(TextBoxField field, String value) in /builds/agent1/37/s/src/PdfEnriching/Services/Implementation/TextBoxFieldToolTipBuilder.cs:line 69
   at PdfEnriching.Services.Implementation.TextBoxFieldToolTipBuilder.Build(PageInfo pageInfo, Page page, Rectangle rectangle, Link link, Boolean mostRecent) in /builds/agent1/37/s/src/PdfEnriching/Services/Implementation/TextBoxFieldToolTipBuilder.cs:line 50
   at PdfEnriching.Services.Implementation.PdfEnrichingService.AddTooltip(Link link, Boolean mostRecent, ButtonField button, TextFragment fragment, Document document) in /builds/agent1/37/s/src/PdfEnriching/Services/Implementation/PdfEnrichingService.cs:line 398
   at PdfEnriching.Services.Implementation.PdfEnrichingService.EnrichPdfDocument(IEnrichingContext context, IEnumerable`1 links, Document document, CancellationToken cancellationToken) in /builds/agent1/37/s/src/PdfEnriching/Services/Implementation/PdfEnrichingService.cs:line 346
   at PdfEnriching.Services.Implementation.PdfEnrichingService.Enrich(IEnrichingContext context, LookupResult[] lookupResults, CancellationToken cancellationToken) in /builds/agent1/37/s/src/PdfEnriching/Services/Implementation/PdfEnrichingService.cs:line 197
   at PdfEnriching.Services.Implementation.PdfEnrichingService.DoWorkAsync(QueueInfo queueInfo, CancellationToken cancellationToken) in /builds/agent1/37/s/src/PdfEnriching/Services/Implementation/PdfEnrichingService.cs:line 83
   at IHS.Services.DocumentProcessing.Ticker.DocumentProcessingTicker.DoWorkAsync(CancellationToken cancellationToken)

this is Dockerfile I have

FROM mcr.microsoft.com/dotnet/core/aspnet:2.2
RUN apt-get update \
&& apt-get install -y --no-install-recommends libgdiplus libc6-dev libx11-dev libfontconfig1 fontconfig \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists /var/cache/apt/archives
# Copy fonts into system
COPY fonts/ /usr/share/fonts/truetype/msttcorefonts
# Refresh cache and rescan folders
RUN fc-cache -f -v

What is the root cause of the error? It seems like something with fonts. But I cannot understand because all code is obfuscated.

@fedorino.alex

Thanks for contacting support.

Would you kindly share if you are facing this issue only in Docker container? Please also share your complete code snippet along with sample PDF document so that we can test the scenario in our environment and address it accordingly.

Hey, thanks for reply, I will prepare container with small test project and we’ll try to reproduce my bug.

@fedorino.alex

Please take your time for further testing and in case issue still persists, please share requested details with us so that we can address it accordingly.

Hey all, there are updates on this bug.

We discovered that it happened sometimes and depends on text we set. So, main reason (as I understood) is unsupported characters, like (soft-hyphen, or non-breakable-hyphen instead of simple ‘-’).

So, we applied sanitization (replacing all possible hyphens to ‘-’ character) and it was helpful.

Incident is closed.

@fedorino.alex

It is nice to hear that your issue has been resolved. We also thank you for posting the workaround that you adopted to resolve the issue as it will help others facing similar issue. Please keep using our API and in case you face any issue, please let us know.