A cikin duniyar da bayanai ke zuwa ta kowane nau’i, daga takaddun da aka bincika zuwa hotuna, buƙatar canza JPG zuwa Kalma ([DOC](https:// docs.fileformat.com/word-processing/doc/), DOCX) ya taso a matsayin maɓalli mai mahimmanci don samar da abun ciki mai sauƙi da daidaitawa. Ka yi tunanin samun hoto tare da rubutu wanda kake son gyarawa ko raba - anan shine inda JPG zuwa Kalma zai shiga.
- API ɗin REST don Canjawar Hoto zuwa Kalma
- Maida JPG zuwa Kalma a cikin C# .NET
- Maida Hoto zuwa Kalma ta amfani da Umarnin CURL
API ɗin REST don Canjawar Hoto zuwa Kalma
Aspose.Words Cloud SDK don NET mafita ce mai ƙarfi da haɓakawa wanda ke ba da damar canza JPG zuwa tsarin Kalma. SDK yana ba da cikakkun takardu, yana sauƙaƙa muku haɗa ayyukan da suka dace cikin aikace-aikacenku.
Domin amfani da SDK, mataki na farko shine ƙara bayanin sa a cikin aikin. Don haka da fatan za a bincika ‘Aspose.Words-Cloud’ a cikin manajan fakitin NuGet kuma danna maɓallin ‘Ƙara Kunshin’. Wannan zai ƙara bayanin SDK a cikin aikin ku. Na biyu, sami takaddun shaidar abokin ciniki daga dashboard ɗin girgije. Idan ba ku da asusun da ke akwai, kawai ƙirƙirar asusun kyauta ta bin umarnin da aka kayyade a cikin labarin saurin farawa.
Maida JPG zuwa Kalma a cikin C# .NET
Da fatan za a bi umarnin da aka bayar a ƙasa don cimma nasarar juzu’i ta amfani da C# .NET.
WordsApi wordsApi = new WordsApi(new Configuration()
{
ClientId = clientID,
ClientSecret = clientSecret
});
Ƙirƙiri wani abu na ajin WordsApi inda muka wuce abin Kanfigareshan azaman hujja.
CreateDocumentRequest createRequest = new CreateDocumentRequest("input.docx", null, null);
wordsApi.CreateDocument(createRequest);
Ƙirƙiri sabon daftarin aiki mara komai.
DrawingObjectInsert requestDrawingObject = new DrawingObjectInsert();
Ƙirƙiri abu mai zane sannan ayyana gefensa da kuma cikakkun bayanan daidaita abun ciki.
InsertDrawingObjectRequest request = new InsertDrawingObjectRequest("input.docx", requestDrawingObject,
requestImageFile, "sections/0", null, null, null, null, null, "Resultant.docx", null, null);
Ƙirƙiri misali zuwa SakaDrawingObject yana bayyana kumburi inda za a sanya abu Zane.
wordsApi.InsertDrawingObject(request);
A ƙarshe, kira hanyar don saka abin Zane a cikin takaddar Kalma kuma ajiye fitarwa zuwa Ma’ajiyar girgije.
// Don cikakkun misalai da fayilolin bayanai, da fatan za a je zuwa
https://github.com/aspose-words-cloud/aspose-words-cloud-dotnet
// Samu bayanan abokin ciniki daga https://dashboard.aspose.cloud/
string clientSecret = "4d84d5f6584160cbd91dba1fe145db14";
string clientID = "bb959721-5780-4be6-be35-ff5c3a6aa4a2";
// ƙirƙirar misali na sabon takaddar Kalma
CreateDocumentRequest createRequest = new CreateDocumentRequest("input.docx", null, null);
// ƙirƙiri daftarin kalma mara komai kuma adana cikin ma'ajin gajimare
wordsApi.CreateDocument(createRequest);
// ƙirƙirar Abun Zana
DrawingObjectInsert requestDrawingObject = new DrawingObjectInsert();
// saita bayanin tsayi don zane abu
requestDrawingObject.Height = 0;
// saita bayanan gefen hagu don zana abu
requestDrawingObject.Left = 0;
// saita manyan bayanan gefe don zana abu
requestDrawingObject.Top = 0;
// saita bayanin faɗi don zane abu
requestDrawingObject.Width = 0;
// saita jeri a kwance don misalin zane
requestDrawingObject.RelativeHorizontalPosition = DrawingObjectInsert.RelativeHorizontalPositionEnum.Margin;
// saita jeri tsaye don misali zane
requestDrawingObject.RelativeVerticalPosition = DrawingObjectInsert.RelativeVerticalPositionEnum.Margin;
// saita nau'in kunsa cikakkun bayanai azaman Layin layi
requestDrawingObject.WrapType = DrawingObjectInsert.WrapTypeEnum.Inline;
// loda abun ciki na shigar da hoton JPG
var requestImageFile = System.IO.File.OpenRead("Map.jpeg");
// ƙirƙiri misali zuwa SakaDrawingObject da ke ma'anar kumburi inda za'a sanya abu Zane
InsertDrawingObjectRequest request = new InsertDrawingObjectRequest("input.docx", requestDrawingObject,
requestImageFile, "sections/0", null, null, null, null, null, "Resultant.docx", null, null);
// saka abin zana riqe da hoton JPG a cikin takaddar Word
wordsApi.InsertDrawingObject(request);
Maida Hoto zuwa Kalma ta amfani da Umarnin CURL
Cimma jujjuyawar daga JPG zuwa Kalma ta amfani da umarnin cURL tare da Aspose.Words Cloud API yana ba da hanya madaidaiciya da tsarin umarni-kore. Yin amfani da umarnin cURL yana ba ku damar yin hulɗa tare da Aspose.Words Cloud API don wannan ƙayyadaddun juyawa ba tare da matsala ba.
Mataki na farko a wannan hanyar shine samar da alamar samun damar JWT ta amfani da umarni mai zuwa:
curl -v "https://api.aspose.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=163c02a1-fcaa-4f79-be54-33012487e783&client_secret=c71cfe618cc6c0944f8f96bdef9813ac" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"
Yanzu, da fatan za a aiwatar da umarni mai zuwa don ƙirƙirar daftarin aiki mara kyau.
curl -v -X PUT "https://api.aspose.cloud/v4.0/words/create?fileName=input.docx" \
-H "accept: application/json" \
-H "Authorization: Bearer <JWT Token>"
A ƙarshe, kira umarni mai zuwa don saka abin zane a cikin sabon daftarin aiki na Word.
curl -v -X POST "https://api.aspose.cloud/v4.0/words/input.docx/sections/0/drawingObjects?destFileName={outputFile}" \
-H "accept: application/json" \
-H "Authorization: Bearer <JWT Token>" \
-H "Content-Type: multipart/form-data" \
-d {"drawingObject":"{ \"RelativeHorizontalPosition\": \"Margin\", \"Left\": 0, \"RelativeVerticalPosition\": \"Margin\", \"Top\": 0, \"Width\": 0, \"Height\": 0, \"WrapType\": \"Inline\"}","imageFile":{"source.jpg"}}
Sauya ‘fitilar fitarwa’ tare da sunan daftarin aiki na Kalma, da ‘accessToken’ tare da alamar samun damar JWT da aka samar a sama.
Kammalawa
A cikin wannan labarin, mun bincika hanyoyi guda biyu marasa daidaituwa don canza hotunan JPG zuwa tsarin takaddun Word. Mun koyi cewa tare da SDK, an sanye ku da kayan aiki mai ƙarfi da arziƙi, yana ba da damar haɗa kai cikin aikace-aikacen NET. A gefe guda, yin amfani da umarnin cURL yana ba da zaɓi mai sauri da samun dama ga tsarin umarni, wanda ya dace da masu amfani tare da tushen fasaha daban-daban. Don haka, ta hanyar iyawar SDK ko saukaka layin umarni na cURL, zaku iya haɓaka ingantaccen aiki da ingantaccen daftarin aiki.
Hanyoyin haɗi masu amfani
Labarai masu alaka
Muna ba da shawarar ziyartar shafukan yanar gizo masu zuwa: