문제

숨겨야 할 텍스트에 새 레이어를 추가하여 텍스트를 숨겨야합니다.

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) 흰색으로 텍스트가 여전히 표시됩니다. 이 문제를 어떻게 극복 할 수 있습니까?

도움이 되었습니까?

해결책

대신에:

pCont = psStamp.GetUnderContent(intCurrPage);

사용:

pCont = psStamp.GetOverContent(intCurrPage);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top