A zamanin dijital da aka kawo tare da abun ciki na kan layi, da bukatar kiyaye, raba, da kuma samun damar bayani a cikin wani tsari da kuma gabatar da tsari ba ya fi mahimmanci. Canza HTML fayiloli zuwa PDF yana magance wannan buƙatar daidai, yana ba da fa’idodi da yawa waɗanda suka wuce iyawar HTML kaɗai. Mun fahimci cewa PDFs an san su a duk duniya, suna tabbatar da cewa tsarin da aka yi niyya da salon abun ciki ya kasance daidai da na’urori da dandamali daban-daban. Don haka, idan kuna neman adana abubuwan gidan yanar gizo, ƙirƙirar takaddun bugu, ko daidaita raba bayanai, za mu tattauna mafita mai ƙarfi da samun damar canza HTML zuwa PDF.
Don haka, wannan labarin yana zurfafa cikin dalilai masu tursasawa bayan sauya HTML zuwa PDF ta amfani da Python Cloud SDK. Yana ba da haske game da hanyoyi daban-daban na juyawa, ƙarfafa mutane da kasuwanci wajen sarrafa da rarraba bayanai yadda ya kamata.
- Canjin HTML zuwa PDF REST API
- Maida HTML zuwa PDF a Python
- Yanar gizo zuwa PDF a cikin Python
- Yadda ake Canza HTML zuwa PDF ta amfani da Umarnin CURL
Canjin HTML zuwa PDF REST API
Canza HTML zuwa PDF mara kyau iska ce tare da taimakon Aspose.PDF Cloud SDK don Python. Wannan SDK mai ƙarfi yana ba da hanya madaidaiciya kuma mai inganci don haɗa HTML zuwa ƙarfin jujjuya PDF zuwa aikace-aikacen Python. Yin amfani da juzu’in Aspose.PDF Cloud’s, kuna iya jujjuya tsarin HTML zuwa ƙwararrun tsara PDFs.
Yanzu mataki na farko na amfani da SDK shine shigarwa, wanda akwai don saukewa akan PIP da GitHub ma’aji. Aiwatar da umarni mai zuwa akan tasha / umarni da sauri don shigar da sabuwar sigar SDK akan tsarin.
pip install asposepdfcloud
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. Da fatan za a bi matakai masu lamba a hoton da ke ƙasa don kammala aikin shigarwa.
Bayan shigarwa, muna buƙatar ƙirƙirar asusu akan dashboard ɗin girgije. Idan kuna da asusun GitHub ko Google, kawai Yi rajista ko, danna maɓallin Ƙirƙiri sabon Asusu kuma samar da bayanan da ake buƙata.
Maida HTML zuwa PDF a Python
A cikin wannan sashe, za mu tattauna cikakkun bayanai kan yadda ake loda fayil ɗin HTML da aka riga aka samu a cikin Cloud Cloud da kuma canza fitarwa zuwa tsarin PDF. Ana adana fayil ɗin sakamakon a cikin ma’ajiyar girgije.
- Da farko, muna buƙatar ƙirƙirar misali na aji ApiClient yayin samar da ID na Abokin ciniki & Sirrin Abokin ciniki azaman muhawara.
- Na biyu, ƙirƙiri misali na ajin PdfApi wanda ke ɗaukar abu ApiClient azaman hujja.
- Yanzu saka sunan shigar da HTML (kunshin azaman .zip archive) da sunan fayil ɗin PDF sakamakonsa.
- A ƙarshe, kira hanyar puthtmlinstoragetopdf(…) wanda ke ɗaukar tushen fayil ɗin .zip, sunan HTML, sakamakon sunan PDF, Tsawo, Nisa, da sigogi gami da daidaitawar shafi azaman muhawara.
def html2pdf():
try:
#initialize PdfApi client instance using ClientID and ClientSecret
pdf_api_client = asposepdfcloud.api_client.ApiClient("406b404b2df649611e508bbcfcd2a77f", "88d1cda8-b12c-4a80-b1ad-c85ac483c5c5")
# ƙirƙirar misalin PdfApi yayin wucewa PdfApiClient azaman hujja
pdf_api = PdfApi(pdf_api_client)
# Shigar da fayil na HTML
input_file_name = 'source.zip'
# sunan resultant PDF file
resultant_file_name = 'Converted.pdf'
# Kira API don canza HTML zuwa tsarin PDF
# tushen HTML yana cikin tsarin .zip tare da .css da hotuna masu alaƙa
response = pdf_api.put_html_in_storage_to_pdf(src_path='source.zip', html_file_name='completeWorkbook.html', name=resultant_file_name, height='1024', width='800', is_landscape='false')
# buga sakon a cikin na'ura mai kwakwalwa (na zaɓi)
print('HTML successfully converted to PDF format !')
except ApiException as e:
print("Exception while calling PdfApi: {0}".format(e))
Ana iya sauke shigarwar HTML da sakamakon PDF da aka samar a cikin misalin da ke sama daga source.zip da HTMLConverted.pdf.
Yanar gizo zuwa PDF a cikin Python
A cikin wannan sashe, za mu canza shafin yanar gizon zuwa tsarin PDF ta amfani da snippet code na Python.
- Ƙirƙiri misali na aji ApiClient yayin samar da ID na Abokin ciniki & Sirrin Abokin ciniki azaman muhawara.
- Na biyu, ƙirƙiri misali na ajin PdfApi wanda ke ɗaukar abu ApiClient azaman hujjar shigarwa.
- Na uku, saka sunan sakamakon sunan fayil ɗin PDF.
- Yanzu kira hanyar putwebinstoragetopdf(…) don canza shafin yanar gizon zuwa tsarin PDF.
def web2pdf():
try:
#initialize PdfApi client instance using ClientID and ClientSecret
pdf_api_client = asposepdfcloud.api_client.ApiClient("406b404b2df649611e508bbcfcd2a77f", "88d1cda8-b12c-4a80-b1ad-c85ac483c5c5")
# ƙirƙirar misalin PdfApi yayin wucewa PdfApiClient azaman hujja
pdf_api = PdfApi(pdf_api_client)
# Sakamakon fayil na PDF
resultant_file_name = 'Web2PDF.pdf'
# Kira API don canza shafin yanar gizo/URL zuwa PDF
# mun saita isLandscape gaskiya ne don mafi kyawun masaukin abubuwan da ke cikin shafin yanar gizon
response = pdf_api.put_web_in_storage_to_pdf(name=resultant_file_name, url='https://www.aspose.cloud/', is_landscape='true')
# buga saƙo a cikin na'ura mai kwakwalwa (na zaɓi)
print('Webpage successfully converted to PDF format !')
except ApiException as e:
print("Exception while calling PdfApi: {0}".format(e))
Da fatan za a danna URL2PDF.pdf don zazzage fayil ɗin PDF da aka ƙirƙira tare da snippet na sama.
Yadda ake Canza HTML zuwa PDF ta amfani da Umarnin CURL
Canza HTML zuwa PDF ta amfani da Aspose.PDF Cloud da umarnin cURL tsari ne mai sauƙi, haɗa ikon Aspose.PDF Cloud tare da sauƙi na cURL. Tare da Aspose.PDF Cloud, masu haɓakawa za su iya cimma HTML zuwa fassarar PDF ba tare da buƙatar lambobi masu rikitarwa ba ko kuma daidaitawa mai yawa. Bugu da ƙari, haɗin kai yana da ‘yancin kai na dandamali, yana sa shi samun dama da tasiri a cikin tsarin aiki daban-daban.
Yanzu, a matsayin abin da ake buƙata, muna buƙatar samar da alamar samun damar JWT ta amfani da takaddun shaidar abokin ciniki. Don haka, da fatan za a aiwatar da umarni mai zuwa don samar da alamar shiga 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"
Da zarar an ƙirƙiri alamar JWT, da fatan za a yi amfani da umarnin CURL mai zuwa don canza gidan yanar gizo zuwa PDF kuma adana abubuwan da aka fitar a cikin ma’ajiyar girgije.
curl -v -X PUT "https://api.aspose.cloud/v3.0/pdf/Converted.pdf/create/html?srcPath=source.zip&htmlFileName=completeWorkbook.html&height=1024&width=800&isLandscape=false" \
-H "accept: application/json" \
-H "authorization: Bearer <JWT Token>"
Idan muna buƙatar canza shafin yanar gizon Live zuwa tsarin PDF, da fatan za a gwada amfani da umarnin CURL mai zuwa.
curl -X PUT "https://api.aspose.cloud/v3.0/pdf/URL2PDF.pdf/create/web?url=https%3A%2F%2Fwww.aspose.cloud%2F&isLandscape=true" \
-H "accept: application/json" \
-H "authorization: Bearer <JWT Token>"
Kammalawa
A cikin wannan labarin, mun bincika hanyoyi biyu masu ƙarfi: yin amfani da Aspose.PDF Cloud SDK don Python da kuma amfani da Aspose.PDF Cloud tare da umarnin cURL. SDK ɗin da aka sadaukar don Python yana ba da kayan aikin haɓaka-abokan haɓakawa, yana ba da ingantaccen sarrafawa da zaɓuɓɓukan gyare-gyare don canza HTML zuwa PDF. Yana ba ku ikon haɗa wannan aikin ba tare da wani lahani ba, yana haɓaka ɗaukar takardu da gabatarwa. A gefe guda, haɗawa da Aspose.PDF Cloud ta hanyar umarnin cURL yana daidaita gidan yanar gizon yanar gizon zuwa HTML, yana samar da mafita mai sauƙi da sauƙi.
Ko kun zaɓi Aspose.PDF Cloud SDK mai fa’ida don Python ko kuma sauƙin umarnin cURL tare da Aspose.PDF Cloud, hanyoyin biyu suna kaiwa ga ingantaccen HTML zuwa fassarar PDF. Wannan sassauci yana ba ku damar daidaita HTML ɗinku zuwa tsarin jujjuya PDF, haɓaka sarrafa takardu da rabawa.
Hanyoyin haɗi masu amfani
- [Takardun samfur 18
- Tsarin tushen don Python girgije SDK
- Zauren tallafin abokin ciniki kyauta
Labarai masu alaka
Muna ba da shawarar ziyartar hanyoyin haɗin yanar gizo masu zuwa don koyo game da: