Compliance Format PDF_A_3B get's lost!

i want to delete only the embedded files of a pdf. when saving the original Format (PDF_A_3B) get lost.
After that i tried conversion to PDF_A_3B and get a System.NullReferenceException at saving the pdf.
So what i´m doing wrong?

here is my snippet:
SetAsposeLicense();

            var path = Path.GetDirectoryName(pdfFullName);
            var tempfile = Path.ChangeExtension(Path.GetFileName(Path.GetTempFileName()), ".PDF");
            var tempFileFullname = Path.Combine(path, tempfile);
            if (File.Exists(tempFileFullname)) File.Delete(tempFileFullname);

            var document = new Document(pdfFullName); //pdfFullName is PDF_A_3B
            document.EmbeddedFiles.Delete();
            **document.Save(tempFileFullname); // compliance Format PDF_A_3B get's lost!**

            var doc = new Document(tempFileFullname);
            var ok = false;
            using (var pdfConversionLogOutputStream = new MemoryStream())
            {
                ok = doc.Convert(pdfConversionLogOutputStream, PdfFormat.PDF_A_3B, ConvertErrorAction.Delete);
            }
            var tmpfileName2 = Path.ChangeExtension(Path.GetFileName(Path.GetTempFileName()), ".PDF");
            var tempfile2 = Path.Combine(path, tmpfileName2);
            if (File.Exists(tempfile2)) File.Delete(tempfile2);
     
            doc.OptimizeResources();
            doc.OptimizeSize = true;
            doc.Optimize();
            **doc.Save(tempfile2); //=> System.NullReferenceException**

            document.Dispose();
            doc.Dispose();

@herbee

Would you please share a sample PDF document for our reference? We will test the scenario in our environment and address it accordingly.

here is a sample pdf:

ZUGFeRD_1p0_BASIC_Einfach.pdf (85.8 KB)

@herbee

// C# Code
var convertDoc = new Document(dataDir + "ZUGFeRD_1p0_BASIC_Einfach.pdf");
convertDoc.EmbeddedFiles.Delete();
convertDoc.Save(dataDir + "FilesDeleted.pdf");
var doc = new Document(dataDir + "FilesDeleted.pdf");
var ok = false;
using (var pdfConversionLogOutputStream = new MemoryStream())
{
 ok = doc.Convert(pdfConversionLogOutputStream, PdfFormat.PDF_A_3B, ConvertErrorAction.Delete);
 doc.OptimizeResources();
 doc.OptimizeSize = true;
 doc.Optimize();
 doc.Save(dataDir + "newConverted.pdf");
}

We tested using above code and 22.4 version of the API and could not notice the exception. Please check the attached output PDF for your kind reference: newConverted.pdf (70.8 KB)

getting same exception at : doc.Save(dataDir + “newConverted.pdf”);
tried Versions 22.4, 22.5

System.NullReferenceException
HResult=0x80004003
Nachricht = Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
Quelle = Aspose.PDF
Stapelüberwachung:
bei #=zGyxORLh2fl0iHKVnbclgzv_wh3i82uSOAFdesEKbrphX.#=zuISwyTDfcqnJ5ndDExx0o14=()

@herbee

It seems strange. Did you try to exact same code? Please try to verify if all Windows Fonts are installed correctly in your system. In case issue still happens, please share the sample console application for our reference along with the complete information of Stack Trace so that we can further proceed to assist you accordingly. Also, please share the complete information of your environment i.e. OS Version and Name, .NET Framework Version, etc.

i commented the following line: //doc.OptimizeResources(); then the doc.Save worked.

@herbee

But we were able to generate the PDF using this method as well that is why we asked for other information so that we can try to determine the cause of error at your end.