In deze korte tutorial leer je hoe je DOCX converteert naar HTML met Java REST API in de cloud. Om DOCX naar HTML-indeling te exporteren, gebruiken we Aspose.Words voor Java Cloud SDK. Als u DOCX naar HTML-conversie in Java Low Code API nodig heeft, kunt u dit doen door de onderstaande stappen en code te gebruiken.
Voorwaarde
- Maak een account aan en ontvang API-referenties
- Downloaden Aspose.Words Cloud SDK for Java
- Setup Java-project met de bovenstaande SDK
Stappen om DOCX naar HTML te converteren in Java REST API
- Stel Client ID en Client Secret in voor de API
- Maak een object van de WordsAPI-klasse met clientreferenties
- Geef invoer- en uitvoerbestanden op
- Lees invoer DOCX-bestand en upload naar cloudopslag
- Maak een object van WordsAPI met invoer- en uitvoerbestandsindelingen
- Roep de methode convertDocument aan om DOCX naar HTML te converteren met behulp van REST API
- Sla het uitvoer-HTML-bestand op de lokale schijf op
Code voor conversie van DOCX naar HTML in 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 = "DOCXToHTML.docx"; | |
String outputFile = "DOCXToHTML.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()); | |
} |
De bovenstaande code helpt u om DOCX naar HTML te converteren met Java REST API. U hoeft alleen maar het DOCX-bestand in te voeren met behulp van de Aspose.Words REST API SDK voor Java en het uitvoer-HTML-bestand te downloaden om het lokaal op te slaan met behulp van de Aspose-conversie-API online.
Deze conversie van DOCX naar HTML kan worden gebruikt met apps zonder code of met weinig code op elk apparaat of elke computer.
In het volgende onderwerp wordt een vergelijkbare functie onderzocht die ook nuttig kan zijn: Hoe DOCX naar TIFF te converteren met Java REST API