通過Python添加文本圖章 PDF

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

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

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

Python Package Manager Console

pip install aspose-pdf

將文字圖章添加到 PDF 文件 Python


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

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

將文字圖章加入到 PDF - Python。

    # Open document
    document = Document(dataDir+ "AddTextStamp.pdf")
    # Create text stamp
    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
    textStamp.TextState.FontStyle = FontStyles.Bold
    textStamp.TextState.FontStyle = FontStyles.Italic
    textStamp.TextState.ForegroundColor = System.Drawing.Color.Aqua

    # Add stamp to particular page
    document.Pages[1].AddStamp(textStamp)

    dataDir = dataDir + "AddTextStamp_out.pdf"
    # Save output document
    document.Save(dataDir)