Error The object reference was not set to an object instance while saving pdf

Hi,

currently I am converting documents into PDF/a files. In some cases we receive an object reference error. The following shows this error.

The object reference was not set to an object instance.
at #=zBKlFZvyHx7FxSP3Q9_POqRQ3SOgflzSrzQ==.#=z5VupspQ=()
   at #=zZVJNRc4jX8BRMc8OxIh6zkTnoVxwI10g62Mfr$lZfk3absvbZZcIBFQ=.#=zc2WgxQQ= 
(#=zLp1QCJMCjlTckKpu7U$O4YRPrbrhyi5qaDbbPptzqbCb #=zx1gS_iLyaOl1, 
 #=zrDdklJFhB7bjk3SZNbiGpyEDwt1H9JoTaP4JZQY= #=zcjaeepo=)
    at (Object , Object[] )
    at #=qIZsV0jdsikgNaaW3UjYdc0ZTEsYJftDJfnM6mwisCG0=.#=z6gL$9Br$JtW$6bPLHrFatarnb8Hekuro 70OI$Dc=(MethodBase #=zw0qwi1Y=, Object #=ziVvwtA4=, Object[] #=zC42lIgs=, Boolean #=zsHpbiOE=)
    at #=qIZsV0jdsikgNaaW3UjYdc0ZTEsYJftDJfnM6mwisCG0=.#=zN7pMLLVfYSeEjU3t5rYWluJM9N2q(MethodBase #=zw0qwi1Y=, Boolean #=ziVvwtA4=)
    at #=qIZsV0jdsikgNaaW3UjYdc0ZTEsYJftDJfnM6mwisCG0=.#=zWVhwPsME7yYWyl1C5RS6f34=(#=qTBeYVOJMDNNiO1$48h7F7U3BSLI664MYjQsgysXAwA4= #=zw0qwi1Y=)
    at #=qIZsV0jdsikgNaaW3UjYdc0ZTEsYJftDJfnM6mwisCG0=.#=zuex84HDu1dXIpeXTEUdMiAs=(#=qIZsV0jdsikgNaaW3UjYdc0ZTEsYJftDJfnM6mwisCG0= #=zw0qwi1Y=, #=qTBeYVOJMDNNiO1$48h7F7U3BSLI664MYjQsgysXAwA4= #=ziVvwtA4=)
    at #=qIZsV0jdsikgNaaW3UjYdc0ZTEsYJftDJfnM6mwisCG0=.#=zMshOjaKeJZen5Jcx_mHz2Y5jeH6z0NcwhA==()
    at #=qIZsV0jdsikgNaaW3UjYdc0ZTEsYJftDJfnM6mwisCG0=.#=zo6IOV$5Igv_8Vk5C$dfWCKU=(Boolean #=zw0qwi1Y=)
    at #=qIZsV0jdsikgNaaW3UjYdc0ZTEsYJftDJfnM6mwisCG0=.#=z1oLsyQJ0Q0GKKe5j1Ib7Q43$mQvB(Object #=zw0qwi1Y=)
    at #=qIZsV0jdsikgNaaW3UjYdc0ZTEsYJftDJfnM6mwisCG0=.#=zYxlCnMyCN2SknNhndw==()
    at #=qIZsV0jdsikgNaaW3UjYdc0ZTEsYJftDJfnM6mwisCG0=.#=zznGL9YwFQ4B9kS8r0d$hmb8SJpu3BKqQlg==(Object #=zw0qwi1Y=, UInt32 #=ziVvwtA4=)
    at #=qIZsV0jdsikgNaaW3UjYdc0ZTEsYJftDJfnM6mwisCG0=.#=zo6IOV$5Igv_8Vk5C$dfWCKU=(Boolean #=zw0qwi1Y=)
    at #=qIZsV0jdsikgNaaW3UjYdc0ZTEsYJftDJfnM6mwisCG0=.#=z0Za8YmFnmI33eslf9cjf5cyiL98vTFjd0g==()
    at #=qIZsV0jdsikgNaaW3UjYdc0ZTEsYJftDJfnM6mwisCG0=.#=zAzO3Nq_ITZMfirF6SlW9BiSJLkr1Bstakw==(Object[] #=zw0qwi1Y=, Type[] #=ziVvwtA4=, Type[] #=zC42lIgs=, Object[] #=zsHpbiOE=)
    at #=qIZsV0jdsikgNaaW3UjYdc0ZTEsYJftDJfnM6mwisCG0=.#=zjIH4BtjiWpr9Pi1MAxqvtEcF7Xnps35aLuE34ak=(Stream #=zw0qwi1Y=, String #=ziVvwtA4=, Object[] #=zC42lIgs=, Type[] #=zsHpbiOE=, Type[] #=z4V2kXC8=, Object[] #=zhcritWg=)
    at #=qIZsV0jdsikgNaaW3UjYdc0ZTEsYJftDJfnM6mwisCG0=.#=z4qGrRAIMj29v_xZi1Nl$GOj2OeJUYGpXqAmNqBHNI3r_(Stream #=zw0qwi1Y=, String #=ziVvwtA4=, Object[] #=zC42lIgs=)
    at #=qIZsV0jdsikgNaaW3UjYdc0ZTEsYJftDJfnM6mwisCG0=.#=zwcTEKH6VKJGOQs9I1SYbu7j0Sjwa(Stream #=zw0qwi1Y=, String #=ziVvwtA4=, Object[] #=zC42lIgs=)
    at #=zwKj7NZIHVS4dR_mJXQsRw6jLvP_1wvNvdw==.#=zc2WgxQQ=()
    at #=zRMDfbZHK_wlhekNnFpqjrYOHqsIz_wxn0Q==.#=zc2WgxQQ=(Stream #=zY_lFexs=)
    at #=z2V3s1OhqLwELpwyCTckAviWoVubQ.#=zc2WgxQQ=(Stream #=zY_lFexs=)
    at Aspose.Pdf.Document.#=zxMYTEhincwT4(Stream #=z5sDS6dk=, SaveOptions #=zzg8jzGl1n$rn)
    at Aspose.Pdf.Document.Save(Stream output)

This error occurs trying to convert the following files:
Research-and-Development-Priorities-for-American-Leadership-in-Wireless-Communications-Report-May-2019.pdf
Open-Knowledge-Network-Workshop-Report-2018.pdf
NITRD_TTS-SmartGrid_Workshop_2011.pdf
NITRD-Connecting-Securing-Communities-Federal-Guide-2018.pdf
national_ai_rd_strategic_plan.pdf
July2017QuarterlyUpdate.pdf

object_reference_error.zip (4.0 MB)

These are open source PDF files from https://catalog.data.gov/dataset

Our code:

var options = new PdfFormatConversionOptions(PdfFormat.PDF_A_2B);
options.ConvertSoftMaskAction = ConvertSoftMaskAction.ConvertToStencilMask;
options.ExcludeFontsStrategy = PdfFormatConversionOptions.RemoveFontsStrategy.SubsetFonts | PdfFormatConversionOptions.RemoveFontsStrategy.RemoveDuplicatedFonts;
options.ErrorAction = ConvertErrorAction.None;
options.OptimizeFileSize = true;

byte[] pdfDoc;
convertDoc.Flatten();
using (var memoryStream = new MemoryStream())
{
    options.LogStream = memoryStream;
    convertDoc.Validate(options);
    // CheckErrors(memoryStream);
}

using (var memoryStream = new MemoryStream())
{
    options.LogStream = memoryStream;
    convertDoc.Convert(options);
    // CheckErrors(memoryStream);
}

using (var strmOut = new MemoryStream())
{
    convertDoc.Save(strmOut);
    pdfDoc = strmOut.ToArray();
}

I would appreciate any help on the matter.

@Verus2020

We were able to notice the same issue in our environment while testing the scenario with 21.7 version of the API. Hence, following tickets have been logged for rectification in our issue tracking system against your PDF files:

  • PDFNET-50277 (NITRD_TTS-SmartGrid_Workshop_2011.pdf)
  • PDFNET-50278 (Open-Knowledge-Network-Workshop-Report-2018.pdf)
  • PDFNET-50279 (NITRD-Connecting-Securing-Communities-Federal-Guide-2018.pdf)
  • PDFNET-50280 (Research-and-Development-Priorities-for-American-Leadership-in-Wireless-Communications-Report-May-2019.pdf)
  • PDFNET-50281 (July2017QuarterlyUpdate.pdf)
  • PDFNET-50282 (national_ai_rd_strategic_plan.pdf)

We will further look into details of the tickets and let you know as soon as they are resolved. Please be patient and spare us some time.

We are sorry for the inconvenience.

The issues you have found earlier (filed as PDFNET-50280,PDFNET-50281,PDFNET-50282,PDFNET-50277,PDFNET-50278,PDFNET-50279) have been fixed in Aspose.PDF for .NET 21.12.