Flattening a PDF means multiple layers of the content will be merged into a single layer. However, the results vary from one service to another as what each service sees in the layers differs.
Basically, by flattening a PDF the image of the page of a PDF content is taken and replaced on that same page. This means the texts in that PDF will no longer be editable as they will become an image. Similarly, if there are any annotations, etc., they will become an image and no longer be editable or selectable.
https://www.sejda.com/flatten-pdf does this job by using the human interface. What is required is an API similar to this functionality so that applications can flatten the PDFs. Checked and confirmed with Sejda that they do not offer any API services even if it is on a paid basis.
Requesting anyone to share who knows any API service or .Net library that can flatten a PDF.