In deze tutorial leer je hoe je DOCX converteert naar DOC met Java REST API in de cloud. Om DOCX naar DOC-indeling te exporteren, gebruiken we Aspose.Words voor Java Cloud SDK. Als u DOCX naar DOC-conversie in Java Low Code API wilt, kunt u hetzelfde bereiken 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 DOC 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 DOC te converteren met behulp van REST API
- Sla het DOC-uitvoerbestand op de lokale schijf op
Code voor conversie van DOCX naar DOC 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 = "DOCXToDOC.docx"; | |
String outputFile = "DOCXToDOC.doc"; | |
String outputFormat = "doc"; | |
//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()); | |
} |
Het hierboven gespecificeerde voorbeeldcodefragment helpt u bij het converteren van DOCX naar DOC met Java REST API. U hoeft alleen het DOCX-bestand in te voeren met behulp van de Aspose.Words REST API SDK voor Java en het DOC-uitvoerbestand te downloaden om het lokaal op te slaan met behulp van de Aspose-conversie-API online.
De bovenstaande DOCX naar DOC-conversie kan worden gebruikt met elke app 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