ObjectDisposedException thrown from Save() method

HI

I use the following code (fragment) to convert a PDF to PDF/A-1b:

using (var doc = new Document(inputStream))
{
	doc.Convert(logFileName, PdfFormat.PDF_A_1B, ConvertErrorAction.Delete);
	
	var optimizationOptions = new Document.OptimizationOptions()
	{
	  AllowReusePageContent = true,
	  LinkDuplcateStreams = true,
	  RemoveUnusedObjects = true,
	  RemoveUnusedStreams = true,
	  CompressImages = true,
	  ImageQuality = 80
	};
	doc.OptimizeResources(optimizationOptions);
	
	PdfSaveOptions options = new PdfSaveOptions {WarningHandler = handler};
	doc.Save(outputStream, options);
}

With the attached document the Save method throws an ObjectDisposedException, but if all optimization options are turned off this code works fine

Demo.pdf (119.4 KB)

best regards
Alex

@Alexander_Winkelmeye

Thank you for contacting support.

I would like to share with you that, the specified exception is being thrown because a PDF/A compliant PDF document can not be optimized. So, please optimize the document first and then convert it to a PDF/A document, as in the modified code snippet below:

        using (var doc = new Document(inputStream))
        {
            var optimizationOptions = new Document.OptimizationOptions()
            {
                AllowReusePageContent = true,
                LinkDuplcateStreams = true,
                RemoveUnusedObjects = true,
                RemoveUnusedStreams = true,
                CompressImages = true,
                ImageQuality = 80
            };
            doc.OptimizeResources(optimizationOptions);

            doc.Convert(logFileName, PdfFormat.PDF_A_1B, ConvertErrorAction.Delete);

            PdfSaveOptions options = new PdfSaveOptions { WarningHandler = handler };
            doc.Save(outputStream, options);
        }

I hope this will be helpful. Please let us know if you need any further assistance.