Flatten PDF in PDFKit

I am opening a PDF doc and adding various annotations to it stamp, text etc . Once I fill those annotations I need to flatten the PDF but I don't find a direct way to do it.

How can we flatten a PDF with annotations?

Thanks
Answered by chrischute in 639440022
I recently faced this problem and solved it by
  1. Converting each page of the PDF to a rasterized image (of sufficiently high resolution)

  2. Creating a new PDF whose pages consist of the images created in step 1.

Code here
Accepted Answer
I recently faced this problem and solved it by
  1. Converting each page of the PDF to a rasterized image (of sufficiently high resolution)

  2. Creating a new PDF whose pages consist of the images created in step 1.

Code here

The provided solution was working well on OS version 12.x , since I Updated to Ventura 13.x flattening is failed. Black font of the original document is reduced and become white. Please
Check the attachment.

Flatten PDF in PDFKit
 
 
Q