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

Free Support Forum - aspose.com

NullReferenceException trying to set the value of a PDF Field

I am using Aspose.PDF version 20.3.0, for a product that runs on both Windows & Linux (Ubuntu via Docker container)

We have fillable PDFs in a document library, which we fill in form field values with answers to questions that we collect.
It works beautifully on Windows.
However, when we deploy to our Linux docker container, we are seeing null reference exceptions trying to set the value of text box form fields:

System.NullReferenceException: Object reference not set to an instance of an object.
at #=zKzeu6yEv9nebofO9$xNNnxVk59hmUl$dcwCk4i$5qbfH8yuPRlVnjLw=.#=zGfEiYyo=(#=zjejcm82eMFvKaImYz9FXZAHCevTxYX2e_yn5P5PRShcY #=zCduLOskwTWke)
at #=zZue$WINdUg3oHRscG064rtP7Z9oguOmGD1vjzK8dCOaRIVoJ5hLdZIkDgFba$d5r$zye7Td3wtmU.#=zOtSyB4Q=(String #=zgDhrh1s=, #=zAQxatDytNh8BOTUfBqM06kReyblV0WKVNDfKeNo= #=zaP2W_JE=, #=zYtDupo8XpnSo4yHeTWHilos0dK5UVcJEOpQzGFfqkIPBN8jGpDe$A8E= #=zNrheprBYdmGB, Boolean #=zswXRy1s=, Boolean #=zWApUTAI=, #=zaKRYDaRKfNUbWk69OrBg$Fr2lIxelkNDOw==& #=zR2hGbl4=, #=zjejcm82eMFvKaImYz9FXZAHCevTxYX2e_yn5P5PRShcY& #=zCduLOskwTWke, String& #=zTl$1FlfQhYcX)
at #=zKzeu6yEv9nebofO9$xNNnxVk59hmUl$dcwCk4i$5qbfH8yuPRlVnjLw=.#=zpt9hk4I=(#=zS9uC$025V4XeO$3YtdTDRdooP7MGlJB8sBbvhGPbYvDE57wg1GLicWR4DaRudWbnU0$_THZIy641Y8Dwjw==[] #=zjnKQOBqSQyW1U8FoGUH0puefS3Wa, String #=zgDhrh1s=, #=zAQxatDytNh8BOTUfBqM06kReyblV0WKVNDfKeNo= #=zaP2W_JE=, #=zYtDupo8XpnSo4yHeTWHilos0dK5UVcJEOpQzGFfqkIPBN8jGpDe$A8E= #=zNrheprBYdmGB, Boolean #=zswXRy1s=, Boolean #=zWApUTAI=, #=zaKRYDaRKfNUbWk69OrBg$Fr2lIxelkNDOw==& #=zSnssHX4=, #=zjejcm82eMFvKaImYz9FXZAHCevTxYX2e_yn5P5PRShcY& #=zCduLOskwTWke, String& #=zTl$1FlfQhYcX)
at #=zKzeu6yEv9nebofO9$xNNnxVk59hmUl$dcwCk4i$5qbfH8yuPRlVnjLw=.#=zX9fAAJ_6OosL(String #=z0l3XscY=, #=zAQxatDytNh8BOTUfBqM06kReyblV0WKVNDfKeNo= #=zaP2W_JE=, #=zaKRYDaRKfNUbWk69OrBg$Fr2lIxelkNDOw==& #=zVx_RAdQ=, #=zjejcm82eMFvKaImYz9FXZAHCevTxYX2e_yn5P5PRShcY& #=zCduLOskwTWke, String& #=z$Z$radA=)
at Aspose.Pdf.Forms.TextBoxField.#=zq_kIdDzn7aRY(#=zysJ3FsEpz_pB #=z98VMeT0=, Annotation #=zgs9ma0M=)
at Aspose.Pdf.Annotations.WidgetAnnotation.#=zPHGpUsU=(Annotation #=zgs9ma0M=)
at Aspose.Pdf.Forms.Field.#=z$L17Pb0=(String #=zcobXZv4=)
at Aspose.Pdf.Forms.Field.set_Value(String value)
at Aspose.Pdf.Forms.TextBoxField.set_Value(String value)

In our product, we also have GroupDocs.Conversion (also version 20.3.0).
For in our Dockerfile for building our linux docker container image, we have added a reference to SkiaSharp.NativeAssets.Linux, version 2.80.3

Lastly, we have resolved some previous issues that we have encountered with Aspose.PDF and GroupDocs.Conversion on linux, specifically with regards to fonts, by adding the fontconfig and fonts-liberation packages to our Dockerfile.

I’m thinking that the issue might be related to fonts, but I’m not entirely certain, given the obfustication in the stack trace.

Is there any way to get any further insight into what the error could be?

We can look into upgrading Aspose.PDF to a later version, although we do find we have issues with later versions and other features, so we have (for now) stabilized our product on the 20.3.0 release.

Thank you,
-Brian

@bpieslak

The issue seems related to missing fonts in the system. Can you please try to install msttcorefonts package along with the latest libgdiplus package and see if the issue still persists? Furthermore, we always recommend using the latest version of the API as it contains maximum enhancements and fixes. You can evaluate the latest version by using a 30-days temporary license and let us know what type of issue you face while using it. Please share a sample PDF and code snippet as well so that we can proceed to assist you accordingly.

thank you @asad.ali.

In our Dockerfile, we are installing:

RUN apt-get update \
    && apt-get install -y --allow-unauthenticated \
		locales locales-all \
		fontconfig \
        libc6-dev \
        libgdiplus \
		fonts-liberation \
        libx11-dev \
     && rm -rf /var/lib/apt/lists/* \
	 && fc-cache -f -v

That got us past the font issues we encountered previously.

We were using fonts-liberation instead of the msttcorefonts package, trying to avoid the added complexity of that MS package installation, and some of the additional steps required with the EULA.

We are licensed through 20.9.0 of Aspose.PDF and GroupDocs.Conversion, and when we had tried running those versions, we had encountered other issues, specifically with converting embedded images in Word documents into PDFs. So we had stabilized on 20.3.0

I will look to see if we can upgrade to a 30-day temporary license of the latest version of the APIs, and if that resolves the issue.

-Brian

@asad.ali - looking at the PDF that we are working with, it appears that the font for the field I am trying to set is defined as “Helvetica” font.

is there a way that we can handle the attempt to resolve the font and replace the font with something else if that font is not found?

what’s also strange is if I catch the exception in a try/catch statement, and I allow the code to continue executing, it appears that the value I set is correctly into that form field. In which case could this exception really just be noise for us, and not something we need to resolve?

-Brian

@bpieslak

We have improved some exception messages in the latest version of the API for a better understanding of the cause of the issue. Please try to use the latest version as well. Also, check if Helvetica font is present in the system? In case the issue still persists, please share your sample code snippet along with a sample PDF document. We will log an investigation ticket in our issue tracking system and share the ID with you.

Hello @bpieslak, I am receiving the same error as you mentioned, I went through the discussion that you guys had, but my issue is still not resolved, so just wanted an update from you guys @bpieslak and @asad.ali that did you have any solution for this.

-Pranav

@PranavJangada

We were unable to test the issue because the sample code and PDF document were not provided. Can you please provide the necessary files (sample PDF, docker file) along with the sample code snippet? We will test the scenario in our environment and address it accordingly.