通過C#添加文本圖章 PDF

使用 C# API 建立帶有文本戳記.PDF。

如何使用 .NET 庫向 PDF 添加文本圖章

為了將文本戳記處理成PDF檔,我們將使用[Aspose.PDF用於.NET](https://products.aspose.com/pdf/net)API,這是一個功能豐富,功能強大且易於使用的文檔操作API,適用於 net 平臺。打開 [NuGet](https://www.nuget.org/packages/aspose.pdf) 包管理器,搜索“.PDF”並安裝。您也可以從程式包管理器主控台使用以下命令。

Package Manager Console

PM > Install-Package Aspose.PDF

將文字圖章添加到 PDF 文件 C#


您需要使用 [Aspose.PDF for .NET](https://releases.aspose.com/pdf/net) 來嘗試環境中的代碼。

  1. 載入包含文件實例的 PDF。
  2. 使用文件對象打開 PDF 文件。
  3. 建立文字戳並定義其屬性。
  4. 使用添加時間戳方法將文字戳添加到頁面

將文字圖章加入到 PDF - C#。


// Open document
Document pdfDocument = new Document(dataDir+ "AddTextStamp.pdf");

// Create text stamp
TextStamp textStamp = new TextStamp("Sample Stamp");
// Set whether stamp is background
textStamp.Background = true;
// Set origin
textStamp.XIndent = 100;
textStamp.YIndent = 100;
// Rotate stamp
textStamp.Rotate = Rotation.on90;
// Set text properties
textStamp.TextState.Font = FontRepository.FindFont("Arial");
textStamp.TextState.FontSize = 14.0F;
textStamp.TextState.FontStyle = FontStyles.Bold;
textStamp.TextState.FontStyle = FontStyles.Italic;
textStamp.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Aqua);
// Add stamp to particular page
pdfDocument.Pages[1].AddStamp(textStamp);

dataDir = dataDir + "AddTextStamp_out.pdf";
// Save output document
pdfDocument.Save(dataDir);