Question

J'ai besoin de cacher un texte en ajoutant un nouveau calque sur le texte que je dois cacher.

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();
    }
}

Le problème avec l'approche ci-dessus, c'est que la couche est ajoutée avec succès avec la couleur noire. Donc, au lieu du texte, j'ai une belle ligne noire sur le texte. Mais si je définis le pCont.SetColorFill(BaseColor.BLACK) Pour blanc, le texte s'affiche toujours. Comment puis-je surmonter ce problème?

Était-ce utile?

La solution

À la place de:

pCont = psStamp.GetUnderContent(intCurrPage);

Utilisation:

pCont = psStamp.GetOverContent(intCurrPage);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top