In de korte tutorial hieronder wordt uitgelegd hoe DOCX naar RTF kan worden geconverteerd met Java REST API in de cloud. Om DOCX naar RTF-indeling te exporteren, gebruiken we Aspose.Words voor Java Cloud SDK. Als u DOCX naar RTF-conversie in Java Low Code API nodig heeft, kunt u dit doen door het volgende codefragment samen met de stappen 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 RTF te converteren in Java REST API
- Stel Client ID en Client Secret in voor de API
- Maak een exemplaar 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 RTF te converteren met behulp van REST API
- Sla het RTF-uitvoerbestand op de lokale schijf op
Code voor conversie van DOCX naar RTF 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 = "DOCXToRTF.docx"; | |
String outputFile = "DOCXToRTF.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()); | |
} |
Met het codefragment in dit bericht kunt u DOCX naar RTF converteren met Java REST API. U hoeft alleen maar het DOCX-bestand aan te leveren met behulp van de Aspose.Words REST API SDK voor Java en het uitvoer-RTF-bestand te downloaden om het lokaal op te slaan met behulp van de Aspose-conversie-API online.
Deze DOCX naar RTF-conversie kan worden gebruikt met alle apps zonder code of met weinig code op Windows, Linux of Mac.
U kunt ook een gerelateerd onderwerp bekijken via de volgende link: Hoe DOCX naar TIFF te converteren met Java REST API