ステートでテキストの置換

カスタム TextState でテキストの置換

  1. ソース PDF を PdfContentEditor ファサードにバインドしてください。
  2. 必要なカラーとフォントサイズで TextState を作成して構成してください。
  3. 置換テキストのスコープを ReplaceAll に設定してください。
  4. replaceText(...) を呼び出し、検索テキスト、置換テキスト、および設定済みの TextState を渡してください。
  5. 更新された PDF ドキュメントを保存してください。
public static void replaceTextWithState(Path inputFile, Path outputFile) {
    PdfContentEditor editor = new PdfContentEditor();
    try {
        editor.bindPdf(inputFile.toString());
        TextState textState = new TextState();
        textState.setForegroundColor(com.aspose.pdf.Color.getBlue());
        textState.setFontSize(14);
        editor.getReplaceTextStrategy().setReplaceScope(ReplaceTextStrategy.Scope.ReplaceAll);
        editor.replaceText("software", "SOFTWARE", textState);
        editor.save(outputFile.toString());
    } finally {
        editor.close();
    }
}