Ing lingkungan tim sing disebarake, macem-macem anggota tim bisa nggarap modul tartamtu saka dokumen, sing kudu digabungake kanggo ngasilake versi gabungan. Operasi iki bisa ditindakake kanthi nggunakake macem-macem aplikasi nanging langkah manual kanggo nggabungake dokumen tembung bisa dadi kegiatan sing mboseni. Dadi, supaya entuk solusi sing luwih apik, kita bakal ngrembug babagan cara nggabungake dokumen tembung nggunakake Java SDK.
Gabung Dokumen API
Aspose.Words Cloud SDK for Java ngidini sampeyan ngenalake kemampuan nggawe, manipulasi, lan transformasi dokumen Word ing aplikasi Java. Iki uga nyedhiyakake fitur kanggo nggabungake dokumen tembung kanggo ngasilake output sing siji. Saiki kanggo nggunakake SDK, mangga nambah rincian ing ngisor iki ing file pom.xml saka jinis 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 instalasi, kita kudu ndhaptar akun gratis liwat Aspose.Cloud dashboard nggunakake akun GitHub utawa Google utawa mung Ndaftar lan entuk Kredensial Klien sampeyan.
Gabungke Dokumen Word ing Jawa
Tututi pandhuan ing ngisor iki kanggo nggabungake dokumen Word nggunakake potongan kode Java.
- Langkah kapisan yaiku nggawe obyek kelas WordsApi nalika ngirim rincian ID Klien lan Rahasia Klien minangka argumen.
- Kapindho, gawe obyek DocumentEntry sing njupuk dokumen kanggo digabung lan banjur nyetel nilai metode setImportFormatMode(..) minangka KeepSourceFormatting
- Saiki gawe obyek ArrayList lan tambahake obyek DocumentEntry ing njero
- Banjur gawe obyek saka DocumentEntryList sing njupuk obyek ArrayList minangka argumen
- Pungkasan, nanging paling ora, gawe obyek AppendDocumentOnlineRequest sing njupuk file Word sumber lan obyek DocumentEntryList minangka argumen
- Pungkasan, nelpon metode appendDocumentOnline(..) API kanggo nggabungake dokumen lan nyimpen output ing panyimpenan Cloud
For more examples, please visit https://github.com/aspose-words-cloud/aspose-words-cloud-java
try
{
// Entuk ClientID lan ClientSecret saka https://dashboard.aspose.cloud/
String clientId = "bbf94a2c-6d7e-4020-b4d2-b9809741374e";
String clientSecret = "1c9379bb7d701c26cc87e741a29987bb";
// yen baseUrl null, WordsApi nggunakake standar https://api.aspose.cloud
WordsApi wordsApi = new WordsApi(clientId, clientSecret, null);
String firstFile = "Resultant.docx";
String documentToAppend = "TableDocument.doc";
String resultantFile = "MergedFile.docx";
// maca kabeh bita input dokumen Word
byte[] requestDocument = Files.readAllBytes(Paths.get("c://Downloads/"+firstFile).toAbsolutePath());
DocumentEntry requestDocumentListDocumentEntries0 = new DocumentEntry();
requestDocumentListDocumentEntries0.setHref("c://Downloads/"+documentToAppend);
requestDocumentListDocumentEntries0.setImportFormatMode("KeepSourceFormatting");
ArrayList<DocumentEntry> requestDocumentListDocumentEntries = new ArrayList<DocumentEntry>();
requestDocumentListDocumentEntries.add(requestDocumentListDocumentEntries0);
DocumentEntryList requestDocumentList = new DocumentEntryList();
requestDocumentList.setDocumentEntries(requestDocumentListDocumentEntries);
AppendDocumentOnlineRequest appendRequest = new AppendDocumentOnlineRequest(requestDocument, requestDocumentList, null, null, null, resultantFile, null, null);
wordsApi.appendDocumentOnline(appendRequest);
System.out.println("Combine Word Documents in Java sucessfull !");
}catch(Exception ex)
{
System.out.println(ex);
}
Gabung Dokumen Word nggunakake Perintah cURL
Prentah cURL uga bisa digunakake kanggo ngakses REST API ing platform apa wae. Dadi ing bagean iki, kita bakal ngrembug rincian babagan cara nggabungake dokumen tembung nggunakake perintah cURL. Saiki langkah pertama yaiku ngasilake JSON Web Token (JWT), mula lakokake perintah ing ngisor iki ing aplikasi terminal.
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 nggabungake dokumen tembung sing wis kasedhiya ing panyimpenan awan.
curl -v -X PUT "https://api.aspose.cloud/v4.0/words/ComparisonResult.docx/appendDocument?destFileName=MergedFile.docx" \
-H "accept: application/json" \
-H "Authorization: Bearer <JWT Token>" \
-H "Content-Type: application/json" \
-d "{\"DocumentEntries\":[{\"Href\":\"SampleMailMergeTemplate.docx\",\"ImportFormatMode\":\"KeepSourceFormatting\"}],\"ApplyBaseDocumentHeadersAndFootersToAppendingDocuments\":true}"
Kesimpulan
Kita wis ngrembug rincian babagan cara nggabungake dokumen tembung ing Jawa uga nggunakake perintah cURL. Elinga yen kode sumber lengkap SDK bisa diundhuh saka GitHub. Salajengipun, kanggo njelajah kemampuan API, sampeyan bisa nimbang ngakses liwat antarmuka swagger.
Yen sampeyan duwe pitakon luwih lanjut utawa sampeyan ngalami kesulitan, bukak Forum dhukungan gratis.
Artikel sing gegandhengan
Disaranake sampeyan ngunjungi blog ing ngisor iki