Domanda

Devo nascondere un testo aggiungendo un nuovo livello sul testo che devo nascondere.

public void ReplacePDFText(string strSearch, StringComparison scCase, string strSource, string strDest)
{
    PdfContentByte pCont = null;

    if (File.Exists(strSource)) {
        PdfReader pdfFileReader = new PdfReader(strSource);
        using (PdfStamper psStamp = new PdfStamper(pdfFileReader, new FileStream(strDest, FileMode.Create))) {
            for (int intCurrPage = 1; intCurrPage <= pdfFileReader.NumberOfPages; intCurrPage++) {
                LocTextExtractionStrategy Strategy = new LocTextExtractionStrategy();
                pCont = psStamp.GetUnderContent(intCurrPage);
                Strategy.UndercontentCharacterSpacing = pCont.CharacterSpacing;
                Strategy.UndercontentHorizontalScaling = pCont.HorizontalScaling;

                string currText = PdfTextExtractor.GetTextFromPage(pdfFileReader, intCurrPage, Strategy);
                List<iTextSharp.text.Rectangle> lstMatches = Strategy.GetTextLocations(strSearch, scCase);

                PdfLayer pdLayer = default(PdfLayer);
                pdLayer = new PdfLayer("over", psStamp.Writer);
                pCont.SetColorFill(BaseColor.BLACK);
                foreach (Rectangle rctRect in lstMatches) {
                    pCont.Rectangle(rctRect.Left, rctRect.Bottom, rctRect.Width, rctRect.Height);
                    pCont.Fill();
                }
            }
        }
        pdfFileReader.Close();
    }
}

Il problema con l'approccio sopra è che lo strato viene aggiunto con successo con il colore nero. Quindi, invece del testo, ho una bella linea nera sul testo. Ma se imposto il pCont.SetColorFill(BaseColor.BLACK) A White, il testo è ancora visualizzato. Come posso superare questo problema?

È stato utile?

Soluzione

Invece di:

pCont = psStamp.GetUnderContent(intCurrPage);

Uso:

pCont = psStamp.GetOverContent(intCurrPage);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top