A cikin rayuwarmu ta yau da kullun, dole ne mu yi ma’amala da takaddun Microsoft Word (DOC/DOCX) duka don dalilai na sirri da na hukuma. Hakazalika, muna iya samun buƙatu don raba waɗannan takaddun akan intanit kuma don buɗe / duba waɗannan takaddun, mai karɓa yana buƙatar takamaiman aikace-aikace kamar MS Word, OpenOffice da sauransu. Bugu da ƙari, wasu mahalli masu ƙuntatawa ƙila ba su da izini don shigar da ƙarin ƙarin. aikace-aikace, don haka a cikin irin wannan yanayin, juyar da Kalma zuwa HTML na iya zama mafita mai dacewa. Ta wannan hanyar, za mu iya buɗe daftarin aiki cikin sauƙi a cikin mai binciken gidan yanar gizo (ba tare da shigar da wani ƙarin software ba). Don haka wannan labarin zai bayyana matakan yadda ake Convert Word zuwa HTML ta amfani da Java Cloud SDK.
- Canjawar Kalma zuwa HTML REST API
- Maida Kalma zuwa HTML a Java
- DOCX zuwa HTML ta amfani da Umarnin CURL
Canjawar Kalma zuwa HTML REST API
Aspose.Words Cloud shine mafita na tushen REST yana ba da damar yin ƙirƙira, gyara da canza takaddun MS Word zuwa nau’ikan tsararrun tallafi. Yanzu dangane da iyakar wannan labarin, za mu yi amfani da Aspose.Words Cloud SDK don Java wanda ke ba mu damar yin amfani da duk damar juzu’in daftarin aiki a aikace-aikacen Java. Don haka don amfani da wannan SDK, muna buƙatar ƙara bayaninsa a cikin aikin Java ta hanyar haɗa waɗannan bayanai a cikin pom.xml (maven build type project).
<repositories>
<repository>
<id>aspose-cloud</id>
<name>artifact.aspose-cloud-releases</name>
<url>https://artifact.aspose.cloud/repo</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-words-cloud</artifactId>
<version>22.12.0</version>
</dependency>
</dependencies>
Muhimmin mataki na gaba shine samun takaddun shaidar abokin ciniki daga Cloud Dashboard. Idan ba a riga ka yi rajista ba, kana buƙatar fara yin rajistar asusun kyauta ta hanyar ingantaccen adireshin imel sannan ka sami takaddun shaidarka.
Maida Kalma zuwa HTML a Java
Za mu tattauna matakai da cikakkun bayanan da suka danganci yadda ake canza kalmar zuwa HTML ta amfani da snippet code na Java.
- Ƙirƙiri wani abu WordsApi inda muke ƙaddamar da keɓaɓɓen takaddun shaida azaman muhawara
- Yanzu loda abun ciki daftarin aiki na Word ta amfani da hanyar readAllBytes(…) sannan a dawo da kimar byte[]
- Mataki na gaba shine ƙirƙirar wani abu na ajin ConvertDocumentRequest, wanda ke ɗaukar fayil ɗin shigarwar Word, tsarin HTML da sunan fayil ɗin sakamako azaman gardama.
- A ƙarshe, kira hanyar convertDocument(…) don aiwatar da fassarar Kalma zuwa HTML. Bayan nasarar yin nasara, ana adana daftarin aiki na HTML a cikin ma’ajin gajimare
// Don ƙarin snippets na lamba, da fatan za a https://github.com/aspose-words-cloud/aspose-words-cloud-java
try
{
String clientId = "bb959721-5780-4be6-be35-ff5c3a6aa4a2";
String clientSecret = "4d84d5f6584160cbd91dba1fe145db14";
// idan baseUrl ba shi da amfani, WordsApi yana amfani da tsoho https://api.aspose.cloud
WordsApi wordsApi = new WordsApi(clientId, clientSecret, null);
// loda daftarin aiki daga tsarin gida
File file1 = new File("test_multi_pages.docx");
// karanta abun ciki na shigar da daftarin kalma
byte[] documentStream = Files.readAllBytes(file1.toPath());
// resultant fayil format
String format = "html";
// ƙirƙiri buƙatun jujjuya daftarin aiki inda muka samar da sunan fayil na sakamako
ConvertDocumentRequest convertRequest = new ConvertDocumentRequest(documentStream,format, "output.html",null, null, null);
// yi magana zuwa html maida
wordsApi.convertDocument(convertRequest);
}catch(Exception ex)
{
System.out.println(ex);
}
Za a iya sauke samfurin Kalman da aka yi amfani da shi a cikin misalin sama daga testmultipages.docx.
DOCX zuwa HTML ta amfani da Umarnin CURL
APIs na REST suna ba da sauƙin shiga ta umarnin cURL akan kowane dandamali. Don haka a cikin wannan sashe, za mu tattauna cikakkun bayanai kan yadda ake canza DOCX zuwa HTML ta amfani da umarnin CURL. Don haka mataki na farko shine samar da alamar samun damar JWT (bisa ga shaidar abokin ciniki) ta amfani da umarni mai zuwa.
curl -v "https://api.aspose.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=bb959721-5780-4be6-be35-ff5c3a6aa4a2&client_secret=4d84d5f6584160cbd91dba1fe145db14" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"
Yanzu muna buƙatar aiwatar da umarni mai zuwa don yin fassarar Kalma zuwa HTML inda ake sa ran shigar da takaddar Kalma za ta kasance a cikin ajiyar girgije kuma bayan jujjuyawar, za mu adana daftarin HTML na sakamakon akan tuƙi na gida.
curl -v -X GET "https://api.aspose.cloud/v4.0/words/test_multi_pages.docx?format=html" \
-H "accept: application/octet-stream" \
-H "Authorization: Bearer <JWT Token>" \
-o "newOutput.html"
Hakanan zamu iya adana fayil ɗin sakamakon kai tsaye a cikin ma’ajin gajimare kuma saboda wannan dalili, kawai muna buƙatar samar da ƙimar siga na waje (kamar yadda aka nuna a ƙasa)
curl -v -X GET "https://api.aspose.cloud/v4.0/words/test_multi_pages.docx?format=html&outPath=output.html" \
-H "accept: application/octet-stream" \
-H "Authorization: Bearer <JWT Token>"
Kammalawa
Yanzu da muka kai ƙarshen wannan labarin, mun koyi cikakkun bayanai kan yadda ake canza kalmar zuwa HTML ta hanyar amfani da Java. Mun kuma ga zaɓuɓɓukan canza DOCX zuwa HTML ta umarnin cURL. Don dalilai na gwaji cikin sauri, zaku iya gwada samun dama ga API ta SwaggerUI a cikin mai binciken gidan yanar gizo kuma a lokaci guda, kuna iya yin la’akari da bincika Takardun Samfura wanda shine tushen bayanai mai ban mamaki.
Idan kuna buƙatar zazzagewa da canza lambar tushe na Cloud SDK, ana samun ta kyauta akan GitHub (an buga ƙarƙashin lasisin MIT). A ƙarshe, idan kun ci karo da kowace matsala yayin amfani da API ko kuna da wata tambaya mai alaƙa, kuna iya la’akari da kusantar mu don ƙuduri mai sauri ta hanyar [zarun tallafin samfur] kyauta 9.
Labarai masu alaka
Da fatan za a ziyarci hanyoyin haɗin yanar gizon don ƙarin koyo game da: