Ƙara alamar ruwa zuwa fayilolin PDF babbar hanya ce don kare abun ciki mai mahimmanci da tabbatar da cewa aikinku yana da ƙima sosai. Ko kuna son sanya alamar PDF ɗinku akan layi, ko ƙirƙirar alamar ruwa ta al’ada ta amfani da Python, tsarin yana da sauƙi kuma madaidaiciya. A cikin wannan gidan yanar gizon, za mu bincika yadda ake ƙara alamar ruwa zuwa fayilolin PDF, tare da kayan aikin kan layi da ta amfani da Python. Ko kana so ka saka alamar ruwa ta rubutu, ko ƙara alamar ruwa, wannan jagorar zai nuna maka yadda ake ƙara alamar ruwa a cikin PDF akan layi da yadda ake ƙara alamar ruwa zuwa PDF kyauta.
- Saka Watermark API
- Ƙara Watermark zuwa PDF ta amfani da Python
- Yi amfani da umarnin CURL don ƙara Alamar Rubutu
- Yi amfani da umarnin CURL don ƙara Alamar Ruwa ta Hoto
Bayani: Aspose yana ba da kayan aikin PowerPoint na kan layi kyauta waɗanda ke ba ku damar [ƙara alamar ruwa zuwa gabatarwa 2 da cire alamar ruwa daga gabatarwa.
Saka Watermark API
Aspose.PDF Cloud shine lambar yabo ta REST API tana ba da fasalulluka don ƙirƙira, sarrafa da sanya fayilolin PDF zuwa nau’ikan fitarwa daban-daban. Hakanan yana ba ku damar loda fayilolin EPUB, HTML, TeX, SVG, XML da sauransu kuma adana su cikin tsarin PDF tare da ƙananan layukan lamba. Mafi ban sha’awa na wannan API shine damar dandali mai zaman kansa. Aiwatar da amfani da damar sarrafa PDF akan kowane dandamali gami da Desktop, Yanar Gizo, ko Wayar hannu. Babu buƙatar shigar da Adobe Acrobat ko wasu aikace-aikace don cika bukatunku.
Kamar yadda fifikonmu a cikin wannan labarin ya shafi harshen Python, don haka muna buƙatar fara shigar da Aspose.PDF Cloud SDK don Python wanda shine abin rufewa a kusa da Aspose.PDF Cloud API. Ana samun SDK don saukewa akan PIP da GitHub ma’aji. Don haka da fatan za a aiwatar da umarni mai zuwa akan tasha / umarni da sauri don shigar da sabuwar sigar SDK akan tsarin.
pip install asposepdfcloud
MS Visual Studio
Idan kuna buƙatar ƙara bayanin kai tsaye a cikin aikin Python ɗinku a cikin Visual Studio IDE, da fatan za a bincika asposepdfcloud azaman fakiti a ƙarƙashin taga yanayin Python.
Bayan shigarwa, muna buƙatar samun takaddun shaidar abokin ciniki daga Aspose.Cloud dashboard. Idan ba ku da asusu, kuna iya biyan kuɗi ta amfani da GitHub ko asusun Google.
Ƙara Watermark zuwa PDF ta amfani da Python
Da fatan za a bi umarnin da aka bayar a ƙasa don ƙara alamar ruwa a cikin takaddar PDF ta amfani da Python.
- Ƙirƙiri misali na aji ApiClient yayin samar da ID na Abokin ciniki & bayanan Sirrin Abokin ciniki azaman muhawara
- Na biyu, ƙirƙiri misali na ajin PdfApi wanda ke ɗaukar abu ApiClient azaman hujja
- Na uku, saka sunayen shigar da fayil ɗin PDF, sunan sakamakon PDF da lambar shafi inda ake buƙatar ƙara alamar ruwa.
- Yanzu, ƙirƙiri wani abu tambari kuma saka kaddarorin masu alaƙa da jujjuya kwana, bawul, jeri a kwance da tsaye, ƙimar alamar ruwa, cikakkun bayanan rubutu, bayanin launi na gaba da bango.
- A ƙarshe, kira hanyar postpagetextstamps(..) na ajin PdfApi, don ƙara alamar ruwa zuwa PDF.
# Don ƙarin misalai, da fatan za a ziyarci 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)
# ƙirƙirar misalin PdfApi yayin wucewa PdfApiClient azaman hujja
pdf_api = PdfApi(pdf_api_client)
#input PDF file name
input_file = 'awesomeTable.pdf'
# lambar shafi na PDF inda ake buƙatar ƙara tambarin rubutu
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)
# buga sakon a cikin na'ura mai kwakwalwa (na zaɓi)
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)
Yi amfani da umarnin CURL don ƙara Alamar Rubutu
cURL kayan aiki ne na layin umarni wanda ke ba ku damar canja wurin bayanai daga ko zuwa sabar ta amfani da ka’idoji daban-daban, gami da HTTP. Hakanan yana samar da ingantacciyar hanya don samun dama ga APIs REST ta tashar layin umarni. Tunda Aspose.PDF Cloud ya dogara ne akan gine-gine na REST, don haka ana iya samun dama ga sauƙi ta amfani da umarnin cURL.
Yanzu, mataki na farko shine ƙirƙirar Token Yanar Gizo na JSON (JWT) bisa la’akari da takaddun shaidar abokin cinikin ku da aka ƙayyade akan dashboard na Aspose.Cloud. Da fatan za a aiwatar da umarni mai zuwa don samar da alamar 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"
Bayan haka, da fatan za a aiwatar da umarni mai zuwa don ƙara alamar ruwa ta rubutu a cikin fayil ɗin PDF, inda ake jujjuya kusurwar digiri 45, jeri a kwance hagu kuma an ayyana daidaitawar tsaye azaman ƙasa.
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 }]"
Yi amfani da umarnin CURL don ƙara Alamar Ruwan Hoto
Da fatan za a aiwatar da umarnin cURL mai zuwa don ƙara alamar ruwa zuwa takaddar PDF kuma adana abin fitarwa a cikin ma’ajiyar gajimare.
Idan kuna buƙatar adana kayan aiki akan tuƙi na gida, da fatan za a saka hujjar “-o”.
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 }]"
Ana iya sauke fayilolin samfurin da aka yi amfani da su a cikin misalin da ke sama daga awesomeTable.pdf, Text-Watermark.pdf, da Image-Watermark.pdf.
Kammalawa
A ƙarshe, ƙara alamar ruwa zuwa fayilolin PDF hanya ce mai sauri da inganci don kare abun ciki da tabbatar da cewa an ƙirƙira shi da kyau. Ko kun fi son yin amfani da kayan aikin kan layi ko rubutun Python, akwai zaɓuɓɓuka da yawa da ke akwai don taimaka muku sanya alamar PDF ɗinku cikin sauƙi. Ta bin matakan da aka zayyana a cikin wannan gidan yanar gizon, zaku iya ƙara alamun ruwa cikin sauƙi zuwa fayilolin PDF kuma ku kiyaye mahimman bayanan ku. To me yasa jira? Fara watermarking fayilolin PDF ɗinku a yau kuma ku ba kanku kwanciyar hankali da sanin cewa aikinku yana da kariya.
Hakanan kuna samun ƙarfi don zazzage lambar tushe na Cloud SDK daga GitHub. Bugu da ƙari, idan kuna da wata tambaya mai alaƙa ko kun ci karo da kowace matsala yayin amfani da API, da fatan za ku ji daɗin tuntuɓar mu ta [ dandalin tallafin samfur kyauta 20.
Labarai masu alaka
Muna ba da shawarar ziyartar labarai masu zuwa don koyo game da su: