Watermark PDF

Nambahake watermark menyang file PDF minangka cara sing apik kanggo nglindhungi konten sing penting lan mesthekake yen karya sampeyan wis dikreditake kanthi bener. Apa sampeyan pengin menehi tandha banyu PDF kanthi online, utawa nggawe tandha banyu khusus nggunakake Python, proses kasebut gampang lan gampang. Ing kirim blog iki, kita bakal njelajah carane nambah watermark menyang file PDF, kanthi alat online lan nggunakake Python. Apa sampeyan pengin nglebokake watermark teks, utawa nambah watermark gambar, pandhuan iki bakal nuduhake sampeyan carane nambah watermark ing PDF online lan carane nambah watermark menyang PDF gratis.

Info: Aspose nyedhiyakake alat PowerPoint online gratis sing ngidini sampeyan nambah tandha banyu menyang presentasi lan [mbusak tandha banyu 3 saka presentasi.

Pasang Watermark API

Aspose.PDF Cloud minangka REST API sing menang penghargaan sing nyedhiyakake fitur kanggo nggawe, ngapusi lan menehi file PDF menyang macem-macem format output. Sampeyan uga ngidini sampeyan mbukak file EPUB, HTML, TeX, SVG, XML, lsp lan nyimpen ing format PDF nganggo baris kode kurang. Sisih paling nggumunake saka API iki yaiku kemampuan platform-independen. Ngleksanakake lan gunakake kemampuan pangolahan PDF ing platform apa wae kalebu Desktop, Web, utawa Seluler. Ora perlu nginstal Adobe Acrobat utawa aplikasi liyane kanggo ngrampungake syarat sampeyan.

Minangka emphasis kita ing artikel iki menyang basa Python, supaya kita kudu nginstal dhisik Aspose.PDF Cloud SDK kanggo Python sing pambungkus watara Aspose.PDF Cloud API. SDK kasedhiya kanggo diundhuh liwat PIP lan GitHub repositori. Dadi, tindakake printah ing ngisor iki ing terminal / command prompt kanggo nginstal versi paling anyar saka SDK ing sistem.

 pip install asposepdfcloud

MS Visual Studio

Yen ngono sampeyan kudu langsung nambah referensi ing project Python ing Visual Studio IDE, mangga nelusuri asposepdfcloud minangka paket ing jendhela lingkungan Python.

Aspose.PDF Cloud Python

Gambar 1: - Aspose.PDF Cloud SDK kanggo paket Python.

Sawise instalasi, kita kudu njupuk kredensial klien saka Aspose.Cloud dashboard. Yen sampeyan ora duwe akun, sampeyan bisa langganan nggunakake akun GitHub utawa Google.

Kredensial Klien

Gambar 2:- Kredensial klien ing dasbor Aspose.Cloud.

Tambah Watermark menyang PDF nggunakake Python

Mangga tindakake pandhuan ing ngisor iki kanggo nambah watermark teks ing dokumen PDF nggunakake Python.

  1. Gawe conto kelas ApiClient nalika nyedhiyakake rincian ID Klien & Rahasia Klien minangka argumen
  2. Kapindho, nggawe conto kelas PdfApi sing njupuk obyek ApiClient minangka argumen
  3. Katelu, nemtokake jeneng file PDF input, jeneng PDF asil lan nomer kaca ing ngendi watermark kudu ditambahake.
  4. Saiki, gawe obyek Stamp lan nemtokake properti sing ana gandhengane karo sudut puteran, opacity, keselarasan horisontal lan vertikal, nilai watermark, rincian font, informasi latar ngarep lan warna latar mburi.
# Kanggo conto liyane, bukak https://github.com/aspose-pdf-cloud/aspose-pdf-cloud-python

def textWatermark():
    try:
        #Client credentials
        client_secret = "406b404b2df649611e508bbcfcd2a77f"
        client_id = "88d1cda8-b12c-4a80-b1ad-c85ac483c5c5"

        #initialize PdfApi client instance using client credetials
        pdf_api_client = asposepdfcloud.api_client.ApiClient(client_secret, client_id)

        # nggawe conto PdfApi nalika ngliwati PdfApiClient minangka argumen
        pdf_api = PdfApi(pdf_api_client)

        #input PDF file name
        input_file = 'awesomeTable.pdf'

        # nomer kaca PDF ing ngendi prangko teks kudu ditambahake
        pageNumber = 1

        textStamp = asposepdfcloud.models.Stamp
        textStamp.type = 'Text'
        textStamp.background = True
        textStamp.horizontal_alignment = 1 #Left
        textStamp.opacity = 0.5
        textStamp.rotate = 1
        textStamp.rotate_angle = 45
        textStamp.x_indent=100
        textStamp.y_indent=100
        textStamp.zoom=1.5
        textStamp.value = 'Confidential'
        
        textState = asposepdfcloud.TextState
        textState.font_size = 20
        textState.font= 'Arial'
        textState.foreground_color = {'A': 0,
        'R': 200,
        'G': 0,
        'B': 0 }
        textState.background_color = {
         'A': 10,
        'R': 0,
        'G': 0,
        'B': 0}
        textState.font_style = 2
        textStamp.vertical_alignment = 1

        #invoke Aspose.Pdf Cloud SDK API to insert text watermark in PDF file
        response = pdf_api.post_page_text_stamps(input_file, pageNumber, textStamp)

        # pesen print ing konsol (opsional)
        print('Text Watermark successfully added to PDF document !')    
    except ApiException as e:
        print("Exception while calling PdfApi: {0}".format(e))
        print("Code:" + str(e.code))
        print("Message:" + e.message)
Pratinjau tandha banyu teks

Gambar 3: - Watermark Teks ditambahake ing PDF.

Gunakake printah cURL kanggo nambah Watermark Teks

cURL minangka alat baris perintah sing ngidini sampeyan nransfer data saka utawa menyang server nggunakake macem-macem protokol, kalebu HTTP. Uga nyedhiyakake mekanisme sing trep kanggo ngakses API REST liwat terminal baris perintah. Wiwit Aspose.PDF Cloud adhedhasar arsitektur REST, mula bisa diakses kanthi gampang nggunakake perintah cURL.

Saiki, langkah pisanan yaiku ngasilake Token Web JSON (JWT) adhedhasar kredensial klien individu sing ditemtokake ing dasbor Aspose.Cloud. Mangga nglakokake printah ing ngisor iki kanggo ngasilake token JWT:

curl -v "https://api.aspose.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=88d1cda8-b12c-4a80-b1ad-c85ac483c5c5&client_secret=406b404b2df649611e508bbcfcd2a77f" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"

Sawisé iku, mangga nglakokaké printah ing ngisor iki kanggo nambah watermark teks ing file PDF, ngendi rotate amba saka 45 derajat, alignment horisontal Kiri lan alignment vertikal ditemtokake minangka Ngisor.

curl -v -X POST "https://api.aspose.cloud/v3.0/pdf/awesomeTable.pdf/pages/1/stamps/text" \
-H  "accept: application/json" \
-H  "authorization: Bearer <JWT Token>" \
-H  "Content-Type: application/json" \
-d "[  {    \"Background\": true,    \"HorizontalAlignment\": \"1\",    \"Opacity\": 0.5,    \"Rotate\": \"1\",    \"RotateAngle\": 45.,    \"XIndent\": 100,    \"YIndent\": 100,    \"Zoom\": 1.5,    \"TextAlignment\": \"0\",    \"Value\": \"Confidential\",    \"TextState\": {      \"FontSize\": 20,      \"Font\": \"Arial\",      \"ForegroundColor\": {        \"A\": 0,        \"R\": 200,        \"G\": 0,        \"B\": 0      },      \"BackgroundColor\": {        \"A\": 10,        \"R\": 0,        \"G\": 0,        \"B\": 0      },      \"FontStyle\": \"2\"    },    \"VerticalAlignment\": \"1\",    \"BottomMargin\": 10,    \"LeftMargin\": 10,    \"TopMargin\": 10,    \"RightMargin\": 10  }]"

Gunakake printah cURL kanggo nambah Watermark Gambar

Mangga nglakokake perintah cURL ing ngisor iki kanggo nambah watermark gambar menyang dokumen PDF lan simpen output ing panyimpenan awan.

Yen ngono sampeyan kudu nyimpen output ing drive lokal, mangga nemtokake “-o” argumen.

curl -v -X POST "https://api.aspose.cloud/v3.0/pdf/awesomeTable.pdf/pages/1/stamps/image" \
-H  "accept: application/json" \
-H  "authorization: Bearer <JWT Token>" \
-H  "Content-Type: application/json" \
-d "[  {    \"Links\": [      {        \"Type\": \"Image\",        \"Title\": \"Image stamp\"      }    ],    \"Background\": true,    \"HorizontalAlignment\": \"LEFT\",    \"Opacity\": 1.0,    \"Rotate\": \"None\",    \"RotateAngle\": 0,    \"XIndent\": 0,    \"YIndent\": 0,    \"Zoom\": 0.5,    \"FileName\": \"confidential.jpg\",    \"Width\": 400,    \"Height\": 200,    \"VerticalAlignment\": \"TOP\",    \"BottomMargin\": 0,    \"LeftMargin\": 10,    \"TopMargin\": 10,    \"RightMargin\": 0  }]"
Pratinjau tandha banyu gambar

Gambar 4: - Tandha banyu gambar ing PDF.

File sampel sing digunakake ing conto ing ndhuwur bisa diundhuh saka awesomeTable.pdf, Text-Watermark.pdf, lan Image-Watermark.pdf.

Kesimpulan

Kesimpulane, nambahake watermark menyang file PDF minangka cara sing cepet lan efektif kanggo nglindhungi konten sampeyan lan mesthekake yen wis dikreditake kanthi bener. Apa sampeyan luwih seneng nggunakake alat online utawa skrip Python, ana akeh pilihan sing kasedhiya kanggo mbantu sampeyan menehi tandha banyu PDF kanthi gampang. Kanthi ngetutake langkah-langkah sing digarisake ing kiriman blog iki, sampeyan bisa kanthi gampang nambah watermarks menyang file PDF lan ngamanake informasi penting sampeyan. Dadi apa ngenteni? Miwiti watermarking file PDF sampeyan dina iki lan ayem tentrem ngerti manawa karya sampeyan dilindhungi.

Sampeyan uga entuk pengaruh kanggo ndownload kode sumber Cloud SDK saka GitHub. Salajengipun, yen sampeyan duwe pitakon sing gegandhengan utawa nemoni masalah nalika nggunakake API, hubungi kita liwat Forum dhukungan produk gratis.

Artikel sing gegandhengan

Disaranake ngunjungi artikel ing ngisor iki kanggo sinau babagan: