![](/img/trans.png)
[英]How to edit named destination in PDF file using iTextSharp with C#?
[英]Edit PDF text using C#
如何找到然后隐藏(或删除)特定的文本短语?
例如,我创建了一个 PDF 文件,其中包含各种数据,例如图像、表格、文本等。
现在,我想在文件中提到的任何地方找到一个像“Hello World”这样的特定短语,并以某种方式隐藏它,或者 - 更好的是 - 从 PDF 中删除它。
删除这句话后终于得到了PDF。
我试过iTextSharp
和Spire
,但找不到任何iTextSharp
东西。
尝试使用以下代码片段使用 Spire.PDF 隐藏 PDF 上的特定文本短语。
using Spire.Pdf;
using Spire.Pdf.General.Find;
using System.Drawing;
namespace HideText
{
class Program
{
static void Main(string[] args)
{
//load PDF file
PdfDocument doc = new PdfDocument();
doc.LoadFromFile(@"C:\Users\Administrator\Desktop\Example.pdf");
//find all results where "Hello World" appears
PdfTextFind[] finds = null;
foreach (PdfPageBase page in doc.Pages)
{
finds = page.FindText("Hello World").Finds;
}
//cover the specific result with white background color
finds[0].ApplyRecoverString("", Color.White, false);
//save to file
doc.SaveToFile("output.pdf");
}
}
}
此处的以下代码段可让您找到并涂黑 pdf 文档中的文本:
PdfDocument pdf = new PdfDocument(new PdfReader(SRC), new PdfWriter(DEST));
ICleanupStrategy cleanupStrategy = new RegexBasedCleanupStrategy(new Regex(@"Alice", RegexOptions.IgnoreCase)).SetRedactionColor(ColorConstants.PINK);
PdfAutoSweep autoSweep = new PdfAutoSweep(cleanupStrategy);
autoSweep.CleanUp(pdf);
pdf.Close();
注意许可证。 如果您不购买许可证,则它是 AGPL。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.