PDF 문서 수정 솔루션

무료 크로스 플랫폼 앱 및 API를 사용하여 PDF 문서에서 콘텐츠 검색 및 제거

PDF 파일을 수정하는 방법

PDF 파일을 편집하기 위해 모든 플랫폼에서 기능이 풍부하고 강력하며 사용하기 쉬운 문서 조작 API인 Aspose.PDF API를 사용합니다.NuGet 패키지 관리자를 열고 Aspose.pdf를 검색하여 설치합니다.패키지 관리자 콘솔에서 다음 명령을 사용할 수도 있습니다.

PDF 문서 수정하기


사용자 환경에서 코드를 테스트하려면 Aspose.PDF 라이브러리 가 필요합니다.

1.문서 인스턴스와 함께 PDF를 로드합니다. 1.검색어를 인수로 사용하여 TextFragmentAbsorber 객체를 생성합니다. 1.검색 옵션을 설정합니다. 1.각 프래그먼트 컬렉션을 반복해서 편집하세요. 1.PDF 파일을 저장합니다.

PDF 수정 - C#.


    Document doc = new Document(dataDir + "test.pdf");

    TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber(searchTerm);
    TextSearchOptions textSearchOptions = new TextSearchOptions(true);
    textFragmentAbsorber.TextSearchOptions = textSearchOptions;

    doc.Pages.Accept(textFragmentAbsorber);
    TextFragmentCollection textFragmentCollection = textFragmentAbsorber.TextFragments;
    foreach (TextFragment textFragment in textFragmentCollection)
{
    Page page = textFragment.Page;
    Rectangle annotationRectangle = textFragment.Rectangle;

    Annotations.RedactionAnnotation annot = new Annotations.RedactionAnnotation(page, annotationRectangle);
    annot.FillColor = Color.Black;
    doc.Pages[textFragment.Page.Number].Annotations.Add(annot, true);
    annot.Redact();
}
    doc.Save(dataDir + "output.pdf");