'iText7 Convert PDF to image while maintaining the highlighting
I am using iText7(C#) and am looking for a way to convert a pdf page to image leave the highlighting. The goal is to create a rendered image (not searchable) of the pdf.
I have tried with this code but without success
using (PdfWriter pdfWriter = new PdfWriter(destinationFilename, new WriterProperties().SetPdfVersion(PdfVersion.PDF_2_0)).SetSmartMode(true))
using (PdfReader pdfReader = new PdfReader(sourceFilename))
using (PdfDocument pdfSource = new PdfDocument(pdfReader))
using (PdfDocument pdfDestination = new PdfDocument(pdfWriter))
using (Document document = new Document(pdfDestination))
{
int pages = pdfSource.GetNumberOfPages();
for (int i = 1; i <= pages; i++)
{
PdfPage page = pdfSource.GetPage(i);
PdfFormXObject pdfFormXObject = page.CopyAsFormXObject(pdfDestination);
iText.Layout.Element.Image image = new iText.Layout.Element.Image(pdfFormXObject);
document.Add(image);
}
}
Do you have any idea how to do this?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|