Edit PDF Programmatically in C# and Replace Form Field Value

Hi Team!

I have a pdf that contains form fields that are filled with some text. I want to Edit PDF Programmatically in C# and when I replace some of the form field value with the following character ‘\u2588’ an exception occurs.

Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
at #=zNDa3OtYUjlyMhd2pwb9AhuMCp9n0nQRSBdnsDaku5bSI7oWXUGW30WaPjgT3CrtBu8HVOhM2rky_.#=zyUkd1wE=(String #=zIdcywiY=, #=zv5h22hZBZa0Qt9X$mg9EMezdGpMCvc$6egjsC0s= #=zwaXgzNE=, #=zNDa3OtYUjlyMhd2pwb9AhhzUR7IEv8sXBcDYzazss5chKEx8WvqOLwY= #=zD2UO8PAzv3OY, Boolean #=zZ6xpyqo=, Boolean #=zPUmLQlY=, #=zcWI4kWkSlHDJrILbyVXAIte_j_$621h_Sw==& #=z1BM9KaA=, #=ztYWYwnALNhuNwST_2qf1gVsyoxW9eiXHbU__MyPU2vN1& #=zaCufT$OVi_3i, String& #=zPPm$XBk42nQ7)
at #=zKXTBi68KtkGWk6EKjkT0wj8tQ_uSqa_aKHBRqdKfB_ys34WLOdyNNVo=.#=z2_C0Phc=(#=zNDa3OtYUjlyMhd2pwb9AhuMCp9n0nQRSBdnsDaku5bRbDEK3kIGU561IzWZ4BpqxGgdupt2YIWxvQ1URLQ==[] #=zlp1NjRP1ZmXBtneBCUh$OWl9eb09, String #=zIdcywiY=, #=zv5h22hZBZa0Qt9X$mg9EMezdGpMCvc$6egjsC0s= #=zwaXgzNE=, #=zNDa3OtYUjlyMhd2pwb9AhhzUR7IEv8sXBcDYzazss5chKEx8WvqOLwY= #=zD2UO8PAzv3OY, Boolean #=zZ6xpyqo=, Boolean #=zPUmLQlY=, #=zcWI4kWkSlHDJrILbyVXAIte_j_$621h_Sw==& #=zieqULy0=, #=ztYWYwnALNhuNwST_2qf1gVsyoxW9eiXHbU__MyPU2vN1& #=zaCufT$OVi_3i, String& #=zPPm$XBk42nQ7)
at #=zKXTBi68KtkGWk6EKjkT0wj8tQ_uSqa_aKHBRqdKfB_ys34WLOdyNNVo=.#=z2VElbhKHvQeg(String #=zDv4Qs2U=, #=zv5h22hZBZa0Qt9X$mg9EMezdGpMCvc$6egjsC0s= #=zwaXgzNE=, #=zcWI4kWkSlHDJrILbyVXAIte_j_$621h_Sw==& #=zeawT4bI=, #=ztYWYwnALNhuNwST_2qf1gVsyoxW9eiXHbU__MyPU2vN1& #=zaCufT$OVi_3i, String& #=zOTUZTFs=)
at Aspose.Pdf.Forms.TextBoxField.#=ztqSzaWK$nwEA(#=z7SZOMuUrdIUo #=zk5X7628=, Annotation #=zvR3G1wg=)
at Aspose.Pdf.Annotations.WidgetAnnotation.#=zB4XVKO8=(Annotation #=zvR3G1wg=)
at Aspose.Pdf.Forms.Field.#=zFnEjeF0=(String #=zK0PB78E=)
at Aspose.Pdf.Forms.Field.set_Value(String value)
at Aspose.Pdf.Forms.TextBoxField.set_Value(String value)

  • OS: Ubuntu 20.04.2 LTS
  • Aspose.Pdf version: 21.7.0
  • .Net Core 3.1 project

Sample file: form.pdf (73.6 KB)
.NET Core Project to edit PDF programmatically: PdfFormProject.zip (1.5 KB)

@erdeiga

Could you please confirm if msttcorefonts and libgdiplus packages are installed and updated in your system? We will further look into details of the issue and share our feedback with you.

@asad.ali
Yes, both are already installed.
image.png (30.0 KB)

@asad.ali

I have an other pdf that is contains text form fields and there is an exception if I want to change the fields value.

TextForm.pdf (8.2 KB)

System.NullReferenceException: Object reference not set to an instance of an object.
at #=zKXTBi68KtkGWk6EKjkT0wj8tQ_uSqa_aKHBRqdKfB_ys34WLOdyNNVo=.#=zUIgNvEQ=(#=ztYWYwnALNhuNwST_2qf1gVsyoxW9eiXHbU__MyPU2vN1 #=zaCufT$OVi_3i)
at #=zrqioYeoeEV9SrAkxSuXwley7geLMj1x2rlquHOWAM0sRmOqjCmwqaa5cyCe6PjAyJ$Fw3kZYNaUt.#=zyUkd1wE=(String #=zIdcywiY=, #=zv5h22hZBZa0Qt9X$mg9EMezdGpMCvc$6egjsC0s= #=zwaXgzNE=, #=zNDa3OtYUjlyMhd2pwb9AhhzUR7IEv8sXBcDYzazss5chKEx8WvqOLwY= #=zD2UO8PAzv3OY, Boolean #=zZ6xpyqo=, Boolean #=zPUmLQlY=, #=zcWI4kWkSlHDJrILbyVXAIte_j_$621h_Sw==& #=z1BM9KaA=, #=ztYWYwnALNhuNwST_2qf1gVsyoxW9eiXHbU__MyPU2vN1& #=zaCufT$OVi_3i, String& #=zPPm$XBk42nQ7)
at #=zKXTBi68KtkGWk6EKjkT0wj8tQ_uSqa_aKHBRqdKfB_ys34WLOdyNNVo=.#=z2_C0Phc=(#=zNDa3OtYUjlyMhd2pwb9AhuMCp9n0nQRSBdnsDaku5bRbDEK3kIGU561IzWZ4BpqxGgdupt2YIWxvQ1URLQ==[] #=zlp1NjRP1ZmXBtneBCUh$OWl9eb09, String #=zIdcywiY=, #=zv5h22hZBZa0Qt9X$mg9EMezdGpMCvc$6egjsC0s= #=zwaXgzNE=, #=zNDa3OtYUjlyMhd2pwb9AhhzUR7IEv8sXBcDYzazss5chKEx8WvqOLwY= #=zD2UO8PAzv3OY, Boolean #=zZ6xpyqo=, Boolean #=zPUmLQlY=, #=zcWI4kWkSlHDJrILbyVXAIte_j_$621h_Sw==& #=zieqULy0=, #=ztYWYwnALNhuNwST_2qf1gVsyoxW9eiXHbU__MyPU2vN1& #=zaCufT$OVi_3i, String& #=zPPm$XBk42nQ7)
at #=zKXTBi68KtkGWk6EKjkT0wj8tQ_uSqa_aKHBRqdKfB_ys34WLOdyNNVo=.#=z2VElbhKHvQeg(String #=zDv4Qs2U=, #=zv5h22hZBZa0Qt9X$mg9EMezdGpMCvc$6egjsC0s= #=zwaXgzNE=, #=zcWI4kWkSlHDJrILbyVXAIte_j_$621h_Sw==& #=zeawT4bI=, #=ztYWYwnALNhuNwST_2qf1gVsyoxW9eiXHbU__MyPU2vN1& #=zaCufT$OVi_3i, String& #=zOTUZTFs=)
at Aspose.Pdf.Forms.TextBoxField.#=ztqSzaWK$nwEA(#=z7SZOMuUrdIUo #=zk5X7628=, Annotation #=zvR3G1wg=)
at Aspose.Pdf.Annotations.WidgetAnnotation.#=zB4XVKO8=(Annotation #=zvR3G1wg=)
at Aspose.Pdf.Forms.Field.#=zFnEjeF0=(String #=zK0PB78E=)
at Aspose.Pdf.Forms.Field.set_Value(String value)
at Aspose.Pdf.Forms.TextBoxField.set_Value(String value)

@erdeiga

Please share the sample code snippet as well that you are using to edit PDF programmatically in C#. We will log an investigation ticket and share the ID with you.

@asad.ali

Here is a sample project: PdfForm.zip (1.5 KB)

  • OS: Ubuntu 20.04.2 LTS
  • Aspose.Pdf version: 21.7.0
  • .Net Core 3.1 project

@erdeiga

We have logged an issue as PDFNET-50368 in our issue tracking system for the sake of correction. We will look into its details and keep you posted with the status of its correction. Please be patient and spare us some time.

We are sorry for the inconvenience.

Hello Support!
Do you have any updates on this issue?

@lorbanops

We are afraid that earlier logged issue could not get rectified due to other pending issues in the queue logged prior to it. However, we have recorded your concerns and will surely inform you once we have updates in this regard. Please spare us some time.

We are sorry for the inconvenience.