1
Мне нужно скрыть текст, добавив новый слой поверх текста, который мне нужно скрыть.Скрытие текста в формате PDF путем добавления дополнительного слоя
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();
}
}
Проблема с подходом выше, заключается в том, что слой успешно добавлен с черным цветом. Поэтому вместо текста у меня есть красивая черная линия над текстом. Но если я установил pCont.SetColorFill(BaseColor.BLACK)
в WHITE, текст по-прежнему отображается. Как я могу решить эту проблему?
привет .... я тоже хочу реализовать ту же логику сокрытия текста. Я пробовал ваш код, но ссылался на класс LocTextExtractionStrategy Strategy = new LocTextExtractionStrategy(); не найден ..... вы бы поделились своим кодом со мной? – Mahesh