webp menyang pdf

WebP to PDF Converter in Java

WebP minangka format gambar modern sing nawakake kompresi lan kualitas sing luwih unggul dibandhingake karo format tradisional kaya JPEG lan PNG. Iki cukup populer amarga file WebP umume luwih cilik tinimbang JPEG tradisional lan mula situs web mbukak luwih cepet lan menehi pengalaman pangguna sing luwih apik. Nanging, ora mesthi kompatibel karo kabeh piranti lan platform. Ing kono sampeyan kudu ngowahi WebP dadi PDF. Ing artikel iki, kita bakal nuntun sampeyan carane ngowahi WebP dadi PDF nggunakake Java REST API. Kita bakal nuntun sampeyan proses nggawe proyek Java, nelpon titik pungkasan REST API lan ngowahi file WebP dadi PDF.

WebP menyang PDF REST API

Kanggo ngolah gambar raster, Metafiles, photoshop lan format gambar populer liyane, kita wis ngembangake Aspose.Imaging Cloud SDK for Java. Iku solusi paling apik sing nawakake pangolahan gambar sing dipercaya lan kemampuan konversi gambar. Uga ndhukung fitur kanggo ngowahi file WebP menyang format PDF. Saiki kanggo ngowahi WebP dadi PDF Online, kita kudu nambah referensi API ing proyek java kita kanthi nyakup informasi ing pom.xml (proyek jinis mbangun maven).

<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>

Sawise referensi REST API wis ditambahake ing proyek Java, entuk kredensial klien saka Cloud Dashboard. Yen ora, sampeyan kudu ndhaptar akun gratis nalika nggunakake alamat email sing bener.

Ngonversi WebP menyang PDF ing Jawa

Ayo ngrembug langkah-langkah kanggo ngowahi WebP dadi PDF nggunakake Java. Elinga yen potongan kode ing ngisor iki ngarepake gambar WebP input kasedhiya ing panyimpenan Cloud, mula kita bakal ngunggah gambar WebP input menyang panyimpenan maya.

  • Gawe conto ImagingApi nggunakake kredensial pribadi
  • Muat file WebP nggunakake metode readAllBytes(…) lan lebokake nilai bali menyang array byte []
  • Saiki gawe obyek CreateConvertedImageRequest sing njupuk jeneng gambar WebP lan format ‘pdf’ minangka argumen
  • Telpon cara createConvertedImage(…) kanggo nindakake konversi WebP menyang PDF. Akibaté, output bali menyang stream respon
  • Pungkasan, simpen WebP asil menyang drive lokal nggunakake obyek FileOutputStream
// Entuk ClientID lan ClientSecret saka https://dashboard.aspose.cloud/
String clientId = "bb959721-5780-4be6-be35-ff5c3a6aa4a2";
String clientSecret = "4d84d5f6584160cbd91dba1fe145db14";

// nggawe obyek Imaging
ImagingApi imageApi = new ImagingApi(clientSecret, clientId);

// mbukak gambar WebP saka drive lokal
File file1 = new File("input.png");
byte[] imageStream = Files.readAllBytes(file1.toPath());
			
// nemtokake format output minangka PDF
String format = "pdf";

// Nggawe obyek panjalukan konversi Gambar
CreateConvertedImageRequest convertRequest = new CreateConvertedImageRequest(imageStream,format,null,null);
// Ngonversi WebP menyang PDF lan ngasilake output ing stream respon
byte[] resultantImage = imageApi.createConvertedImage(convertRequest);

// Simpen PDF asil menyang drive lokal
FileOutputStream fos = new FileOutputStream("/Users/nayyer/Documents/" + "resultant.pdf");
fos.write(resultantImage);
fos.close();
webp menyang pdf

Gambar: - Pratinjau konversi WebP dadi PDF

Gambar WebP input sing digunakake ing conto ing ndhuwur bisa didownload saka link iki.

File WebP menyang PDF nggunakake Perintah cURL

Kajaba saka potongan kode Java, pendekatan liyane kanggo ngowahi file WebP menyang format PDF yaiku liwat perintah cURL. Saiki minangka prasyarat, kita kudu ngasilake token akses JWT (adhedhasar kredensial klien) nggunakake printah ing ngisor iki.

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"

Saiki nglakokake printah ing ngisor iki kanggo ngowahi WebP dadi format PDF lan simpen output menyang drive lokal

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"

Kesimpulan

Artikel kasebut kanthi jelas nyedhiyakake kabeh rincian sing dibutuhake kanggo ngowahi WebP dadi PDF nggunakake Java. Kajaba iku, kita banget ngajak sampeyan njelajah Dokumentasi Produk sing minangka sumber informasi sing luar biasa kanggo sinau babagan fitur-fitur menarik liyane sing ditawakake API. Sampeyan uga bisa nyoba API liwat SwaggerUI ing browser web lan yen sampeyan kudu ngundhuh lan ngowahi kode sumber Cloud SDK, kasedhiya ing GitHub (diterbitake ing lisensi MIT).

Pungkasan, yen sampeyan nemoni masalah nalika nggunakake API, sampeyan bisa nimbang nyedhaki kita kanggo resolusi cepet liwat [forum dhukungan produk] gratis 9.

Artikel sing gegandhengan

Mangga bukak link ing ngisor iki kanggo mangerteni sing luwih lengkap babagan: