このチュートリアルでは、C# Low Code API を使用して PDF のテキストに取り消し線を引く方法 について説明します。.NET ベースの Cloud SDK を使用して、C# Low Code API を使用して PDF のテキストに自動的に取り消し線を引く方法 を学習します。API で公開されているメソッドを使用してさまざまなパラメータを設定し、取り消し線を引くプロセスをカスタマイズする方法を説明します。
前提条件
ダウンロード Aspose.PDF Cloud SDK for Dotnet to strikeout text in a PDF file
テキストを取り消すための上記のSDKを使用してC#プロジェクトをセットアップします
C# REST インターフェイスを使用して Adobe PDF で取り消し線を引く手順
- テキストを取り消すためのAPIキーとアプリケーションSIDを設定してPdfApiクラスオブジェクトを構成します
- StrikeOutAnnotationオブジェクトを作成し、テキストの周囲の四角形と取り消し線の色を設定します。
- 注釈の変更日と作成日を必要に応じて設定します
- テキストを取り消し線を引くために対象のPDFファイルをクラウドストレージにアップロードします
- PostPageStrikeOutAnnotations() メソッドを呼び出して、カスタム設定でテキストを取り消し線を引く
- 取り消し線付きの更新されたPDFファイルをダウンロードする
これらの手順では、C# REST API を使用して PDF 内のテキストを取り消す方法を定義します。PdfApi クラスのオブジェクトを作成し、対象テキストの周囲の四角形、色、作成日、および変更日を設定して StrikeOutAnnotation オブジェクトをインスタンス化します。対象の PDF ファイルをクラウド ストレージにアップロードし、PostPageStrikeOutAnnotations() メソッドを呼び出してタスクを実行します。
C# .NET ベースの API を使用して PDF に取り消し線を引くコード
using System; | |
using System.IO; | |
using Aspose.Pdf.Cloud.Sdk.Api; | |
using Aspose.Pdf.Cloud.Sdk.Model; | |
using System.Collections.Generic; | |
namespace Aspose.PDF.Cloud.Examples.Kb | |
{ | |
public class PdfTasks | |
{ | |
public static void StrikeoutText() | |
{ | |
PdfApi pdfApi = new PdfApi("API_KEY", "APP_SID"); | |
StrikeOutAnnotation annotation = new StrikeOutAnnotation( | |
Rect: new Rectangle(50, 712, 200, 732), | |
Color: new Color(255, 0, 255, 0) | |
); | |
annotation.Modified = "10/03/2024 12:09:00.000 AM"; | |
annotation.CreationDate = "10/03/2024 12:09:00.00 AM"; | |
try | |
{ | |
FilesUploadResult uploadResult = pdfApi.UploadFile("input.pdf", new MemoryStream(File.ReadAllBytes("input.pdf"))); | |
AsposeResponse strikeoutApiResponse = pdfApi.PostPageStrikeOutAnnotations( | |
"input.pdf", 1, new List<StrikeOutAnnotation>() { annotation }); | |
if (strikeoutApiResponse.Status == "OK") | |
{ | |
// Download created pdf file with strikeout | |
Stream storageRes = pdfApi.DownloadFile("input.pdf"); | |
FileStream fileStream = new FileStream("PdfOutputWithStrikeout.pdf", FileMode.Create, FileAccess.Write); | |
storageRes.CopyTo(fileStream); | |
} | |
Console.WriteLine("Strikeout text done"); | |
Console.ReadKey(); | |
} | |
catch (Exception ex) | |
{ | |
System.Diagnostics.Debug.WriteLine("error:" + ex.Message + "\n" + ex.StackTrace); | |
} | |
} | |
} | |
} |
このコード スニペットは、C# REST インターフェイスを使用して PDF に取り消し線を引く方法を示しています。ページ インデックス、ZIndex、水平および垂直配置、名前、件名、タイトルなどの取り消し線注釈プロパティを設定できます。リストに必要な数の注釈を追加し、PostPageStrikeOutAnnotations() メソッドを呼び出してすべての注釈を適用できます。
この記事では、PDF 内のテキストを取り消す方法について説明しました。PDF ファイル内のテキストを置換する場合は、C# REST API を使用して PDF 内のテキストを置換する の記事を参照してください。