I am working with iText to generate PDF. It is working fine in the editor(windows) but when i running the andriod build it throws the following exception.
2026/06/01 12:45:41.669 29785 29810 Error Unity NullReferenceException: Object reference not set to an instance of an object.
2026/06/01 12:45:41.669 29785 29810 Error Unity at iText.Commons.Utils.DIContainer.GetInstance[T] () [0x00000] in <00000000000000000000000000000000>:0
2026/06/01 12:45:41.669 29785 29810 Error Unity at iText.Kernel.Pdf.PdfPagesTree..ctor (iText.Kernel.Pdf.PdfCatalog pdfCatalog) [0x00000] in <00000000000000000000000000000000>:0
2026/06/01 12:45:41.669 29785 29810 Error Unity at iText.Kernel.Pdf.PdfCatalog..ctor (iText.Kernel.Pdf.PdfDictionary pdfObject) [0x00000] in <00000000000000000000000000000000>:0
2026/06/01 12:45:41.669 29785 29810 Error Unity at iText.Kernel.Pdf.PdfDocument.Open (iText.Kernel.Pdf.PdfVersion newPdfVersion) [0x00000] in <00000000000000000000000000000000>:0
2026/06/01 12:45:41.669 29785 29810 Error Unity at iText.Kernel.Pdf.PdfDocument..ctor (iText.Kernel.Pdf.PdfWriter writer) [0x00000] in <00000000000000000000000000000000>:0
2026/06/01 12:45:41.669 29785 29810 Error Unity at PdfGenerator.CreatePdfFromImages (System.Collections.Generic.List`1[T] imagePaths, System.String pdfFileName, System.String ouputPath) [0x00000] in <00000000000000000000000000000000>:0
2026/06/01 12:45:41.669 29785 29810 Error Unity
Here is my part of pdf generation code. I can confirm that pdfdocument log is not appearing
Debug.Log("=====PDF GENERATION STARTED=====");
// 1. Initialize PDF writer and PDF document
PdfWriter writer = new PdfWriter(savePath);
Debug.Log("PDF Writer initialized at: " + savePath);
System.Runtime.CompilerServices.RuntimeHelpers
.RunClassConstructor(typeof(iText.Commons.Utils.DIContainer).TypeHandle);
Debug.Log("DIContainer cctor forced");
PdfDocument pdfDoc = new PdfDocument(writer);
Debug.Log("PDF Document created successfully.");
// 2. Initialize layout Document (Defaults to A4)
Document document = new Document(pdfDoc, PageSize.A4);
Debug.Log("Layout Document initialized with A4 page size.");
// 2. Instantiate your custom handler
HeaderFooterHandler handler = new HeaderFooterHandler();