Dalam tutorial ini, Anda akan mempelajari cara mengonversi DOC ke HTML dengan Java REST API di cloud. Untuk mengekspor DOC ke format HTML, kami menggunakan Aspose.Words untuk Java Cloud SDK. Jika Anda memerlukan Konversi DOC ke HTML di Java Low Code API maka ini dapat dilakukan dengan bantuan kode dan langkah-langkah di bawah ini.
Prasyarat
- Buat akun dan dapatkan kredensial API
- Unduh Aspose.Words Cloud SDK for Java
- Siapkan proyek Java dengan SDK di atas
Langkah-langkah Mengonversi DOC ke HTML di Java REST API
- Tetapkan ID Klien dan Rahasia Klien untuk API
- Buat objek kelas WordsAPI dengan kredensial klien
- Tentukan file input dan output
- Baca masukan file DOC dan unggah ke penyimpanan cloud
- Buat instance WordsAPI dengan format file input dan output
- Panggil metode convertDocument untuk Mengonversi DOC ke HTML menggunakan REST API
- Simpan file HTML keluaran pada disk lokal
Kode untuk Konversi DOC ke HTML di Java Low Code API
String ClientID = Client.getID(); //replace Client.getID() with your own client ID here | |
String ClientSecret = Client.getSecret(); //replace3 Client.getSecret() with your own client secret here | |
String APIBaseUrl="https://api.aspose.cloud"; | |
String Local_Path = "C:/Temp/"; | |
try { | |
//Create API client with credentials | |
ApiClient apiClient = new ApiClient(ClientID, ClientSecret, APIBaseUrl); | |
//Create SDK object | |
WordsApi wordsApi = new WordsApi(apiClient); | |
String inputFile = "DOCToHTML.doc"; | |
String outputFile = "DOCToHTML.html"; | |
String outputFormat = "html"; | |
//Read input file to bytes array | |
byte[] inputFileData = Files.readAllBytes(Paths.get(Local_Path + inputFile).toAbsolutePath()); | |
//create conversion request object with input and output files | |
ConvertDocumentRequest convertDocumentRequest = new ConvertDocumentRequest(inputFileData, outputFormat, null, null, null, null, null, null, null); | |
//convert the input file to output format | |
byte[] outputFileData = wordsApi.convertDocument(convertDocumentRequest); | |
//save the output file from the bytes array | |
FileOutputStream fileOutputStream = new FileOutputStream(Local_Path + outputFile); | |
fileOutputStream.write(outputFileData); | |
} catch (Exception e) { | |
System.out.println(e.getMessage()); | |
} |
Cuplikan kode di atas membantu Anda mengonversi DOC ke HTML dengan Java REST API. Anda hanya perlu menyediakan file DOC dengan bantuan Aspose.Words REST API SDK untuk Java dan mengunduh file HTML keluaran untuk menyimpannya secara lokal dengan menggunakan API konversi Aspose online.
Fitur Konversi DOC ke HTML ini dapat digunakan dengan aplikasi tanpa kode atau kode rendah apa pun di Windows, Linux, atau Mac.
Fitur serupa dapat ditemukan di topik berikut: Cara Mengonversi DOCX ke HTML dengan Java REST API