Tugas kanggo mbandhingake file teks umum banget nalika nggabungake owah-owahan menyang dokumen sing manunggal. Mulane sajrone proses review lan gabung, operasi mbandhingake teks ditindakake lan kita kerep nggunakake utilitas kanggo mbandhingake teks kanthi online. Dadi ing artikel iki, kita bakal ngrembug langkah-langkah babagan cara mbandhingake dokumen tembung lan mbandhingake file teks nggunakake Java SDK.
Bandingake API Teks
Aspose.Words Cloud SDK for Java nyedhiyakake macem-macem fitur sing bisa nggawe, ngowahi lan ngapusi dokumen Word ing aplikasi Java. Saiki supaya bisa nggunakake SDK, tambahake rincian ing ngisor iki menyang pom.xml proyek mbangun maven.
<repositories>
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>https://repository.aspose.cloud/repo/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-words-cloud</artifactId>
<version>22.5.0</version>
</dependency>
</dependencies>
Sawise SDK diinstal, mangga ndhaftar akun gratis liwat dasbor Aspose.Cloud nggunakake akun GitHub utawa Google utawa mung Ndaftar lan entuk Kredensial Klien sampeyan.
Bandhingake Dokumen Word ing Jawa
Ing bagean iki, kita bakal ngrembug babagan cara mbandhingake dokumen tembung nggunakake potongan kode Jawa.
- Langkah pisanan yaiku nggawe conto WordsApi nggunakake kredensial klien
- Kapindho, upload input lan dokumen Word sing diowahi menyang panyimpenan maya nalika ngirim obyek UploadFileRequest menyang metode uploadFile(…) WordsApi
- Katelu, nggawe obyek CompareData lan pass dokumen kapindho minangka argumen kanggo metode setComparingWithDocument(…)
- Saiki gawe obyek kelas CompareDocumentRequest ing ngendi kita ngirim file Word input, obyek CompareData, lan dokumen tembung asil minangka argumen
- Pungkasan, mbandhingake file teks nggunakake metode compareDocument(…) lan simpen output ing panyimpenan maya
For more examples, please visit https://github.com/aspose-words-cloud/aspose-words-cloud-java
try
{
// yen baseUrl null, WordsApi nggunakake standar https://api.aspose.cloud
WordsApi wordsApi = new WordsApi(clientId, clientSecret, null);
String firstDocument = "input-sample.docx";
String secondDocument = "input-sample-updated.docx";
String resultantFile = "Comparison.docx";
// maca dokumen Word pisanan saka drive lokal
File file = new File("c://Downloads/"+firstDocument);
// maca dokumen tembung kapindho saka drive lokal
File file2 = new File("c://Downloads/"+secondDocument);
// nggawe panjalukan upload file
UploadFileRequest uploadRequest = new UploadFileRequest(Files.readAllBytes(file.toPath()), firstDocument, null);
// nggawe request upload file 2nd
UploadFileRequest uploadRequest2 = new UploadFileRequest(Files.readAllBytes(file2.toPath()), secondDocument, null);
// upload file menyang panyimpenan maya
wordsApi.uploadFile(uploadRequest);
// upload file menyang panyimpenan maya
wordsApi.uploadFile(uploadRequest2);
// Nggawe conto kelas CompareData
CompareData compareData = new CompareData();
// jeneng kanggo digunakake minangka penulis ngenali beda
compareData.setAuthor("Nayyer");
// nemtokake document kanggo mbandhingaké karo
compareData.setComparingWithDocument(secondDocument);
compareData.setDateTime(OffsetDateTime.now());
// nggawe Panjaluk conto kanthi nyedhiyakake sumber, dokumen kanggo mbandhingake lan jeneng file asil
CompareDocumentRequest request = new CompareDocumentRequest(firstDocument, compareData, null, null, null, null, null,resultantFile,null);
// miwiti perbandingan dokumen
DocumentResponse result = wordsApi.compareDocument(request);
// pesen sukses print
System.out.println("Sucessfull completion of Compare Word Document !");
}catch(Exception ex)
{
System.out.println(ex);
}
File sampel sing digunakake ing conto ing ndhuwur bisa diundhuh saka pranala ing ngisor iki
Bandhingake Teks nggunakake Perintah cURL
Kita uga bisa ngakses Aspose.Words Cloud liwat perintah cURL lan mbandhingake file teks. Dadi minangka prasyarat, mangga jalanake perintah ing ngisor iki kanggo nggawe token akses JWT adhedhasar ID Klien lan rincian Rahasia Klien.
curl -v "https://api.aspose.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=a41d01ef-dfd5-4e02-ad29-bd85fe41e3e4&client_secret=d87269aade6a46cdc295b711e26809af" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"
Sawise kita duwe Token JWT, mangga jalanake perintah ing ngisor iki kanggo mbandhingake teks kanthi online lan simpen file asil ing panyimpenan awan.
curl -v -X PUT "https://api.aspose.cloud/v4.0/words/input-sample.docx/compareDocument?destFileName=Comparison.docx" \
-H "accept: application/json" \
-H "Authorization: Bearer <JWT Token>" \
-H "Content-Type: application/json" \
-d "{\"ComparingWithDocument\":\"input-sample-updated.docx\",\"Author\":\"Nayyer Shahbaz\",\"DateTime\":\"2022-07-21T07:54:06.768Z\",\"CompareOptions\":{\"IgnoreCaseChanges\":true,\"IgnoreTables\":true,\"IgnoreFields\":true,\"IgnoreFootnotes\":true,\"IgnoreComments\":true,\"IgnoreTextboxes\":true,\"IgnoreFormatting\":true,\"IgnoreHeadersAndFooters\":true,\"Target\":\"Current\",\"AcceptAllRevisionsBeforeComparison\":true},\"ResultDocumentFormat\":\"docx\"}"
Kesimpulan
Artikel iki wis nerangake langkah-langkah kanggo mbandhingake dokumen nggunakake Jawa uga perintah cURL. Sampeyan bisa uga nimbang njelajah kemampuan API liwat antarmuka swagger. Salajengipun, kode sumber lengkap SDK bisa diundhuh saka GitHub. Yen sampeyan duwe pitakon luwih lanjut utawa sampeyan ngalami kesulitan, bukak Forum dhukungan gratis.
Artikel sing gegandhengan
Disaranake sampeyan ngunjungi blog ing ngisor iki