In de volgende stapsgewijze zelfstudie ziet u hoe u DOC kunt converteren naar RTF met Java REST API in de cloud. Om DOC naar RTF-indeling te exporteren, gebruiken we Aspose.Words voor Java Cloud SDK. Als u DOC naar RTF-conversie nodig heeft in de Java Low Code API, kunt u hetzelfde bereiken met behulp van onderstaande code en stappen.
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 RTF te converteren in Java REST API
- Stel de client-ID en het clientgeheim in voor de API
- Maak een exemplaar 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 RTF met behulp van REST API
- Sla het uitvoer-RTF-bestand op de lokale schijf op
Code voor DOC naar RTF-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 = "DOCToRTF.doc"; | |
String outputFile = "DOCToRTF.rtf"; | |
String outputFormat = "rtf"; | |
//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 eenvoudige en gemakkelijke codefragment op deze pagina helpt u bij het converteren van DOC naar RTF met Java REST API. U hoeft alleen maar een DOC-bestand aan te leveren met behulp van de Aspose.Words REST API SDK voor Java en het RTF-uitvoerbestand te downloaden om het lokaal op te slaan met behulp van de Aspose-conversie-API online.
Deze DOC naar RTF-conversie kan worden gebruikt met alle no-code- of low-code-apps op elk platform.
De volgende link toont een soortgelijke functie die wellicht nuttig voor u kan zijn: Hoe DOCX naar RTF te converteren met Java REST API