iTextSharp移除线路

本文关键字:线路 iTextSharp | 更新日期: 2023-09-27 18:20:01

如何使用iTextSharp从pdf文件中删除"线条"形状?

我尝试:

var shape = page.GetAsStream(PdfName.LINE); //return null
var resources = PdfReader.GetPdfObject(page.Get(PdfName.RESOURCES)) as PdfDictionary; //return dictonary
var resShape = resources.GetAsStream(PdfName.LINE); //return null
PdfReader.KillIndirect(shape);
PdfReader.KillIndirect(resShape);

我做错了什么?

Thx!

iTextSharp移除线路

类似这样的东西:

 PdfDictionary pg = reader.GetPageN(1);
        PdfArray annotsArray = pg.GetAsArray(PdfName.ANNOTS);
        if (annotsArray != null)
        {
            for (int k = 0; k < annotsArray.Size; k++)
            {
                PdfDictionary annot = (PdfDictionary) PdfReader.GetPdfObject(annotsArray[k]);
                if(annot.GetAsName(PdfName.SUBTYPE).ToString() =="/Line")
                {
                    annotsArray.Remove(k);
                }
            }
        }