public override void OnObjectDataAdding(ObjectDataAddingEventArgs e) { base.OnObjectDataAdding(e); //If data is added to an image if (e.PdfObjectType == typeof(PdfImageShape)) { //Check image size (if larger than 1 MB) if (e.Data.Length > 0x100000) { //Cancel object data adding and display a message e.Cancel = true; e.CancelMessage = "Maximum image size is 1 MB."; } } else { throw new ArgumentException("PdfObjectType unsupported."); } }