WebP tsarin hoto ne na zamani wanda ke ba da matsi da inganci idan aka kwatanta da tsarin gargajiya kamar JPEG da PNG. Suna da shahara sosai saboda fayil ɗin WebP gabaɗaya ya fi na JPEG na gargajiya don haka gidajen yanar gizo suna ɗaukar sauri da samar da ƙwarewar masu amfani. Koyaya, ba koyaushe yana dacewa da duk na’urori da dandamali ba. A nan ne ake shigowa da maida WebP zuwa PDF. A cikin wannan labarin, za mu yi muku jagora kan yadda ake canza WebP zuwa PDF ta amfani da Java REST API. Za mu bi ku ta hanyar ƙirƙirar aikin Java, kiran ƙarshen API na REST kuma mu canza fayilolin WebP zuwa PDF.
- WebP zuwa PDF REST API
- Maida WebP zuwa PDF a Java
- Fayil na Yanar Gizo zuwa PDF ta amfani da Umarnin CURL
WebP zuwa PDF REST API
Domin aiwatar da hotunan raster, Metafiles, Photoshop da sauran shahararrun tsarin hoto, mun haɓaka Aspose.Imaging Cloud SDK for Java. Yana da mafi kyawun bayani yana ba da ingantaccen sarrafa hoto da ikon canza hoto. Hakanan yana goyan bayan fasalin don canza fayil ɗin WebP zuwa tsarin PDF. Yanzu don musanya WebP zuwa PDF Online, muna buƙatar ƙara bayanin API a cikin aikin java ɗin mu ta haɗa da bin bayanai a cikin pom.xml (maven build type project).
<repositories>
<repository>
<id>aspose-cloud</id>
<name>artifact.aspose-cloud-releases</name>
<url>https://artifact.aspose.cloud/repo</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-imaging-cloud</artifactId>
<version>22.4</version>
</dependency>
</dependencies>
Da zarar an ƙara bayanin REST API a cikin aikin Java, da fatan za a sami takaddun shaidar abokin ciniki daga Cloud Dashboard. In ba haka ba, kuna buƙatar fara rajistar asusun kyauta yayin amfani da ingantaccen adireshin imel.
Maida WebP zuwa PDF a Java
Bari mu tattauna matakan canza WebP zuwa PDF ta amfani da Java. Lura cewa snippet code mai zuwa yana tsammanin shigar da hoton WebP zai kasance a cikin ma’ajiyar gajimare, don haka za mu loda hoton shigarwar WebP zuwa ma’ajiyar gajimare.
- Ƙirƙiri misali na ImagingApi ta amfani da keɓaɓɓen takaddun shaida
- Load da fayil ɗin WebP ta amfani da hanyar readAllBytes(…) kuma wuce ƙimar da aka dawo zuwa byte[] tsararru.
- Yanzu ƙirƙirar wani abu na CreateConvertedImageRequest wanda ke ɗaukar sunan hoton WebP da tsarin ‘pdf’ azaman muhawara.
- Kira hanyar ƙirƙirarConvertedImage(…) don aiwatar da WebP zuwa PDF. Sakamakon haka, ana mayar da fitarwa a cikin rafin amsawa
- A ƙarshe, ajiye sakamakon WebP zuwa faifan gida ta amfani da abu FileOutputStream
// Samu ClientID da ClientSecret daga https://dashboard.aspose.cloud/
String clientId = "bb959721-5780-4be6-be35-ff5c3a6aa4a2";
String clientSecret = "4d84d5f6584160cbd91dba1fe145db14";
// haifar da Hoto abu
ImagingApi imageApi = new ImagingApi(clientSecret, clientId);
// ɗora hoton WebP daga faifan gida
File file1 = new File("input.png");
byte[] imageStream = Files.readAllBytes(file1.toPath());
// saka tsarin fitarwa azaman PDF
String format = "pdf";
// Ƙirƙiri abin buƙatar canza hoto
CreateConvertedImageRequest convertRequest = new CreateConvertedImageRequest(imageStream,format,null,null);
// canza WebP zuwa PDF kuma dawo da fitarwa a cikin rafin amsawa
byte[] resultantImage = imageApi.createConvertedImage(convertRequest);
// Ajiye sakamakon PDF zuwa faifan gida
FileOutputStream fos = new FileOutputStream("/Users/nayyer/Documents/" + "resultant.pdf");
fos.write(resultantImage);
fos.close();
Hoton shigarwar WebP da aka yi amfani da shi a cikin misalin da ke sama ana iya saukewa daga wannan hanyar haɗin yanar gizon.
Fayil na Yanar Gizo zuwa PDF ta amfani da Umarnin CURL
Baya ga snippet code na Java, wata hanya don canza fayil ɗin WebP zuwa tsarin PDF shine ta umarnin cURL. Yanzu a matsayin buƙatun farko, muna buƙatar samar da alamar samun damar JWT (bisa ga shaidar abokin ciniki) ta amfani da umarni mai zuwa.
curl -v "https://api.aspose.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=bb959721-5780-4be6-be35-ff5c3a6aa4a2&client_secret=4d84d5f6584160cbd91dba1fe145db14" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"
Yanzu aiwatar da umarni mai zuwa don canza tsarin WebP zuwa tsarin PDF kuma adana abin fitarwa zuwa firar gida
curl -v -X GET "https://api.aspose.cloud/v3.0/imaging/input.webp/convert?format=pdf" \
-H "accept: application/json" \
-H "authorization: Bearer <JWT Token>" \
-o "Output.pdf"
Kammalawa
Labarin ya fito fili ya ba da cikakkun bayanan da suka dace akan canza WebP zuwa PDF ta amfani da Java. Baya ga wannan, muna ƙarfafa ku sosai don bincika Takardun Samfura wanda shine tushen bayanai mai ban mamaki don koyo game da wasu abubuwan ban sha’awa waɗanda API ɗin ke bayarwa. Hakanan zaka iya gwada API ta SwaggerUI a cikin mai binciken gidan yanar gizo kuma idan kuna buƙatar zazzagewa da gyara lambar tushe na Cloud SDK, yana kan GitHub (an buga shi ƙarƙashin lasisin MIT).
A ƙarshe, idan kun haɗu da kowace matsala yayin amfani da API, kuna iya yin la’akari da kusantar mu don ƙuduri mai sauri ta hanyar dandalin tallafi na kyauta 9.
Labarai masu alaka
Da fatan za a ziyarci hanyoyin haɗin yanar gizon don ƙarin koyo game da: