There are several examples of removing or resizeing images using itextsharp on the net, but i'm unable to find exemples of removing inline images.
I´m using the following code to remove XObject images:
PdfWriter writer = st.Writer;
PdfDictionary pg = reader.GetPageN(1);
PdfDictionary res = (PdfDictionary)PdfReader.GetPdfObject(pg.Get(PdfName.RESOURCES));
PdfDictionary xobj = (PdfDictionary)PdfReader.GetPdfObject(res.Get(PdfName.XOBJECT));
if (xobj != null)
{
foreach (PdfName name in xobj.Keys)
{
PdfObject obj = xobj.Get(name);
if (obj.IsDictionary())
{
PdfDictionary tg = (PdfDictionary)PdfReader.GetPdfObject(obj);
PdfName type = (PdfName)PdfReader.GetPdfObject(tg.Get(PdfName.SUBTYPE));
//PdfName type = (PdfName)PdfReader.GetPdfObject(tg.Get(PdfName.SUBTYPE));
if (PdfName.IMAGE.Equals(type))
{
int xrefIdx = ((PRIndirectReference)obj).Number;
PdfObject pdfObj = reader.GetPdfObject(xrefIdx);
PdfStream str = (PdfStream)(pdfObj);
byte[] bytes = PdfReader.GetStreamBytesRaw((PRStream)str);
iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance((PRIndirectReference)obj);
string filter = tg.Get(PdfName.FILTER).ToString();
if (filter == "/DCTDecode")
{
PdfReader.KillIndirect(obj);
Stream stBrasao2 = File.OpenRead(pasta_recurso + "brasao.jpg");
iTextSharp.text.Image img2 = iTextSharp.text.Image.GetInstance(stBrasao2);
writer.AddDirectImageSimple(img2, (PRIndirectReference)obj);
break;
}
}
}
}
}
Is there any way to adapt this to remove inline images rather than XObject images?
Thanks.