A cikin duniyar dijital ta yau, galibi ana buƙatar mu canza takaddun PDF zuwa tsarin hoto, musamman JPG. Bukatar canza PDF zuwa JPG na iya tasowa daga dalilai daban-daban, kama daga son raba PDF azaman hoto zuwa adana ingancin gani na takaddar. Amma canza PDF zuwa JPG da hannu na iya zama aiki mai wahala da cin lokaci. A nan ne Python REST API ke shigowa. Tare da taimakon wannan ƙaƙƙarfan mai amfani, canza PDF zuwa JPG bai taɓa samun sauƙi ba. A cikin wannan cikakkiyar jagorar, za mu nuna muku yadda ake canza PDF zuwa JPG akan layi tare da inganci mai inganci ta amfani da Python REST API.
API ɗin mu na Cloud yana da ban mamaki sosai cewa kawai yana buƙatar shigar da PDF da hanyar manufa kuma yana kula da duk hadaddun juzu’in na ciki.
- API ɗin Canjin JPG zuwa PDF
- Canza PDF zuwa JPG a cikin Python
- Maida PDF zuwa JPG ta amfani da Umarnin CURL
API ɗin Canjin JPG zuwa PDF
Mayar da takaddun PDF zuwa hotunan JPG na iya zama aiki mai wahala, musamman idan aka yi da hannu. Amma da zuwan fasahar girgije, canza PDF zuwa JPG ya zama mafi sauƙi. Apsose.PDF Cloud SDK don Python yana ba da mafita mara wahala da inganci don canza PDF zuwa JPG tare da inganci mai inganci. A cikin wannan jagorar, za mu ɗauke ku ta hanyar canza PDF zuwa JPG ta amfani da Aspose.PDF Cloud SDK don Python. Shirya don daidaita tsarin jujjuya ku kuma ƙirƙirar hotuna JPG masu ban sha’awa daga takaddun PDF ɗinku.
Ana samun SDK don shigarwa akan PIP da GitHub. Yanzu 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
Mataki na gaba mai mahimmanci shine biyan kuɗi kyauta ga ayyukan girgijenmu ta Aspose.Cloud dashboard ta amfani da GitHub ko asusun Google. Idan ba ku da asusun da ke wanzu, kawai ƙirƙiri sabon Asusu kuma sami Keɓaɓɓen Shaidar Abokin Ciniki na ku.
Canza PDF zuwa JPG a cikin Python
Da fatan za a bi matakan da aka bayar a ƙasa don adana PDF azaman tsarin JPG kuma adana fitarwa a cikin ma’ajiyar gajimare.
- Ƙirƙiri misalin aji na ApiClient yayin ba da Sirrin Abokin ciniki ID azaman muhawara
- Yanzu ƙirƙiri misali na ajin PdfApi wanda ke ɗaukar abu ApiClient azaman hujjar shigarwa
- Mataki na gaba shine ƙirƙirar masu canji da ke riƙe da sunayen shigar da fayil ɗin PDF da sakamakon JPEG
- A ƙarshe, kira hanyar putpageconverttojpeg(..) na PdfApi ɗaukar shigar da PDF, lambar shafin da za a canza, da sunan sakamakon sunan fayil na JPEG.
def pdf2Image():
try:
#Client credentials
client_secret = "1c9379bb7d701c26cc87e741a29987bb"
client_id = "bbf94a2c-6d7e-4020-b4d2-b9809741374e"
#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)
#source PDF file
input_file = 'URL2PDF.pdf'
#resultant Image file
resultant_image = 'PDF2JPEG.jpeg'
# Kira API don canza shafukan PDF zuwa tsarin JPEG da adana fitarwa zuwa ma'ajiyar gajimare
response = pdf_api.put_page_convert_to_jpeg(name = input_file, page_number= 3, out_path= resultant_image)
print(response)
# buga sakon a cikin na'ura mai kwakwalwa (na zaɓi)
print('PDF page successfully converted to JPEG !')
except ApiException as e:
print("Exception while calling PdfApi: {0}".format(e))
print("Code:" + str(e.code))
print("Message:" + e.message)
Za a iya sauke samfurin fayilolin da aka yi amfani da su a cikin misalin da ke sama daga URL2PDF.pdf da PDF2JPEG.jpeg.
Lura cewa don adana PDF zuwa wasu nau’ikan hoton raster, da fatan za a yi amfani da hanyoyi masu zuwa
Yi amfani da putpageconverttotiff(…) don adana shafukan PDF zuwa TIFF Yi amfani da putpageconverttopng(…) don adana shafukan PDF zuwa PNG Yi amfani da putpageconverttoemf(..) don adana shafukan PDF zuwa EMF Yi amfani da putpageconverttobmp(…) don adana shafukan PDF zuwa BMP Yi amfani da putpageconverttogif(…) don adana shafukan PDF zuwa GIF
Canza PDF zuwa JPG ta amfani da Umarnin CURL
Hakanan za’a iya amfani da umarnin CURL don samun dama ga APIs REST ta tashoshin layin umarni. Don haka za mu canza shafin farko na PDF zuwa JPG inda aka adana sakamakon sakamakon zuwa ma’ajiyar girgije. Yanzu don samun damar Aspose.PDF Cloud, muna buƙatar fara samar da JSON Web Token (JWT) yayin aiwatar da umarni mai zuwa.
curl -v "https://api.aspose.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=bbf94a2c-6d7e-4020-b4d2-b9809741374e&client_secret=1c9379bb7d701c26cc87e741a29987bb" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"
Yanzu da muke da alamar JWT, da fatan za a aiwatar da umarni mai zuwa don canza pdf zuwa tsarin hoto.
curl -v -X PUT "https://api.aspose.cloud/v3.0/pdf/URL2PDF.pdf/pages/1/convert/jpeg?outPath=ConvertedPage.jpeg&width=800&height=1000" \
-H "accept: application/json" \
-H "authorization: Bearer <JWT Token>" \
-d{}
Kammalawa
A cikin wannan jagorar, mun bincika tsarin canza PDF zuwa JPG ta amfani da Aspose.PDF Cloud SDK don Python. Ta amfani da wannan kayan aiki mai ƙarfi, zaku iya canza takaddun PDF cikin sauƙi zuwa hotuna JPG masu inganci tare da ƴan layukan lamba. Aspose.PDF Cloud SDK don Python yana ba da ingantaccen mafita mara wahala ga duk buƙatun canza PDF zuwa JPG. Yi bankwana da jujjuyawar hannu kuma ku rungumi ƙarfin fasahar girgije don canza PDFs ɗinku zuwa hotuna na JPG masu ban sha’awa.
Muna kuma ba da shawarar ziyartar Jagorancin Masu Shirye-shiryen don koyo game da wasu abubuwan ban sha’awa waɗanda REST API ke bayarwa. Bugu da ƙari, cikakkiyar lambar tushe ta Aspose.PDF Cloud SDK don Python yana samuwa don saukewa akan GitHub (an buga a ƙarƙashin lasisin MIT). Koyaya, idan kun ci karo da wasu batutuwa yayin amfani da API ko kuna da wasu ƙarin tambayoyi, da fatan za ku ji daɗin tuntuɓar mu ta zauren tallafin samfur kyauta.
Labarai masu alaka
Muna kuma ba da shawarar ziyartar hanyoyin haɗin yanar gizon don ƙarin koyo game da su