In deze korte tutorial ziet u hoe u DOC kunt converteren naar MHTML met Java REST API in de cloud. Om DOC naar MHTML-indeling te exporteren, gebruiken we Aspose.Words voor Java Cloud SDK. Als u DOC naar MHTML-conversie in de Java Low Code API nodig heeft, kunt u hetzelfde doen met behulp van de volgende stappen en het codefragment.
Voorwaarde
- Maak een account aan en ontvang API-referenties
- Downloaden Aspose.Words Cloud SDK for Java
- Stel een Java-project in met de bovenstaande SDK
Stappen om DOC naar MHTML te converteren in Java REST API
- Stel de client-ID en het clientgeheim in voor de API
- Maak een object van de klasse WordsAPI met clientreferenties
- Specificeer invoer- en uitvoerbestanden
- Lees het invoerDOC-bestand en upload het naar de cloudopslag
- Maak een object van WordsAPI met invoer- en uitvoerbestandsindelingen
- Roep de methode convertDocument aan naar Convert DOC naar MHTML met behulp van REST API
- Sla het uitvoer-MHTML-bestand op de lokale schijf op
Code voor DOC naar MHTML-conversie 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 = "DOCToMHTML.doc"; | |
String outputFile = "DOCToMHTML.mhtml"; | |
String outputFormat = "mhtml"; | |
//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()); | |
} |
Met de voorbeeldcode in dit bericht kunt u DOC naar MHTML converteren met Java REST API. U hoeft alleen maar het DOC-bestand te uploaden met behulp van de Aspose.Words REST API SDK voor Java en het MHTML-uitvoerbestand te downloaden om het lokaal op te slaan met behulp van de Aspose-conversie-API online.
De bovenstaande DOC naar MHTML-conversie kan worden gebruikt met alle apps zonder code of met weinig code op elk platform.
U kunt ook een gerelateerd onderwerp raadplegen via de volgende link: Hoe DOCX naar MHTML te converteren met Java REST API