Python aracılığıyla PDF’ye Metin Damgası Ekle

Python for .NET Kütüphanesi için Aspose.PDF kullanarak programlı olarak metin damgası oluşturun

Python for .NET Kitaplığı Kullanarak PDF'ye Metin Damgaları Ekleme

PDF dosyasına metin damgası eklemek için, güçlü ve kullanımı kolay bir API olan Aspose.PDF for Python via .NET kullanın. PyPI‘yi açın, aspose-pdf‘i arayın ve yükleyin. Alternatif olarak, şu komutu çalıştırın:

Console

pip install aspose-pdf

PDF Belgesine Metin Damgası Ekle Python


Kodu ortamınızda denemek için Aspose.PDF for Python üzerinden .NET gerekir.

  1. PDF’yi bir Belge örneğiyle yükleyin.
  2. Document nesnesini kullanarak bir PDF belgesi açın.
  3. Metin Damgası oluşturun ve özelliklerini tanımlayın.
  4. AddStamp yöntemini kullanarak Metin Damgasını Sayfaya Ekleme

Python ile PDF'ye Metin Damgası Ekle

import aspose.pdf as apdf

from os import path

path_infile = path.join(self.data_dir, infile)
path_outfile = path.join(self.data_dir, outfile)

document = apdf.Document(path_infile)
document.pages.add()
# Create text stamp
textStamp = apdf.TextStamp("Sample Stamp")
# Set whether stamp is background
textStamp.background = True
# Set origin
textStamp.x_indent = 100
textStamp.y_indent = 100
# Rotate stamp
textStamp.rotate = apdf.Rotation.ON90
# Set text properties
textStamp.text_state.font = apdf.text.FontRepository.find_font("Arial")
textStamp.text_state.font_size = 14
textStamp.text_state.font_style = apdf.text.FontStyles(
    apdf.text.FontStyles.BOLD | apdf.text.FontStyles.ITALIC )
textStamp.text_state.foreground_color = apdf.Color.aqua
# Add stamp to particular page
document.pages[1].add_stamp(textStamp)

# Save output document
document.save(path_outfile)