Hotunan Raster sun dace don gyaran hoto da ƙirƙirar zane-zane na dijital saboda, an matsa su don ajiya kuma an inganta su don yanar gizo. Yawancin na’urorin rayuwar mu na yau da kullun ciki har da kyamarori na dijital, na’urar daukar hoto na gani da sauransu. Yanzu shahararrun nau’ikan fayilolin raster sun haɗa da JPEG, PNG, da GIF kuma a cikin wannan labarin, muna Za su tattauna cikakkun bayanai kan yadda ake canza JPG zuwa Kalma. Dalilin da ya sa muke canza JPEG zuwa Kalma shine saboda, ƙila muna da buƙatu don haɗa tarin hotunan JPG a cikin takarda ɗaya sannan a adana su a cikin tarihin hukuma. Don haka bari mu bincika cikakkun bayanai kan yadda ake Haɓaka JPG zuwa Mai sauya Kalma ta amfani da Java Cloud SDK
API ɗin Canjin Kalma zuwa JPG
Samfurin da ya ci kyautar mu Aspose.Word Cloud ƙaramin API ne kuma ingantaccen bayani yana ba da damar ƙirƙira, gyara da kuma canza takaddun Kalma zuwa nau’ikan tallafi iri-iri. Idan kuna neman aiwatar da damar sarrafa daftarin aiki a cikin aikace-aikacen Java, to Aspose.Words Cloud SDK don Java zaɓi ne mai ban mamaki. Don haka ba tare da amfani da kowace software ko sarrafa kansa ta MS Office ba, zaku iya ƙirƙira, gyara da canza takaddun MS Word ta Cloud. Yanzu don farawa da amfani da SDK, muna buƙatar ƙara bayanin Cloud SDK a cikin aikinmu. Don haka da fatan za a ƙara cikakkun bayanai masu zuwa a cikin pom.xml na nau’in ginin maven.
<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.8.0</version>
</dependency>
</dependencies>
Don amfani da SDK, muna buƙatar tantance mai amfani da Aspose Cloud. Don haka idan ba ku da asusun da ke akwai, da fatan za a ƙirƙiri asusun kyauta ta amfani da adireshin imel mai aiki. Sannan shiga ta amfani da sabon asusun da aka ƙirƙira kuma bincika/ƙirƙiri ID na abokin ciniki da Sirrin Abokin ciniki a Cloud Dashboard. Ana buƙatar waɗannan cikakkun bayanai don dalilai na tantancewa a cikin sassan masu zuwa.
Maida JPG zuwa Kalma a Java
Wannan sashe yana bayyana cikakkun bayanai kan yadda zamu iya haɓaka JPG zuwa mai sauya Kalma ta amfani da Java Cloud SDK. Da fatan za a bi umarnin da aka ƙayyade a ƙasa.
- Da farko, da fatan za a ƙirƙiri wani abu na WordsApi yayin samar da ClientID da sirrin Abokin ciniki azaman muhawara.
- Abu na biyu, ƙirƙirar wani abu na CreateDocumentRequest wanda ke buƙatar sunan sabon takaddar Kalma
- Na uku, ƙirƙiri daftarin kalma mara komai kuma a loda zuwa Ma’ajiyar gajimare ta amfani da hanyar ƙirƙirarDocument(…).
- Mataki na gaba shine ƙirƙirar abu na DrawingObjectInsert domin a iya sanya abu mai zane a cikin takaddar kalma
- Saita gefe, girma da bayanin daidaitawa don abin zane
- Karanta fayil ɗin hoto daga faifan gida zuwa cikin ByteArray
- Yanzu ƙirƙiri wani abu na InsertDrawingObjectRequest yana ba da shigar da sunan fayil ɗin Word da bayanan kumburi don riƙe abu mai zane.
- A ƙarshe kira hanyar sakaDrawingObject(…) don saka abu Zane a cikin takaddar Kalma da adana fitarwa a cikin Ma’ajiyar girgije.
// Don ƙarin snippets na lamba, da fatan za a https://github.com/aspose-words-cloud/aspose-words-cloud-java
try
{
// Samu ClientID da ClientSecret daga https://dashboard.aspose.cloud/
String clientId = "7ef10407-c1b7-43bd-9603-5ea9c6db83cd";
String clientSecret = "ba7cc4dc0c0478d7b508dd8ffa029845";
// ƙirƙirar wani abu na WordsApi
// idan baseUrl ba shi da amfani, WordsApi yana amfani da tsoho https://api.aspose.cloud
WordsApi wordsApi = new WordsApi(clientId, clientSecret, null);
// ƙ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.setHeight((double)0);
// saita bayanan gefen hagu don zana abu
requestDrawingObject.setLeft((double)0);
// saita manyan bayanan gefe don zana abu
requestDrawingObject.setTop((double)0);
// saita bayanin faɗi don zane abu
requestDrawingObject.setWidth((double)0);
// saita jeri a kwance don misalin zane
requestDrawingObject.setRelativeHorizontalPosition(DrawingObjectInsert.RelativeHorizontalPositionEnum.MARGIN);
// saita jeri tsaye don misali zane
requestDrawingObject.setRelativeVerticalPosition(DrawingObjectInsert.RelativeVerticalPositionEnum.MARGIN);
// saita nau'in kunsa cikakkun bayanai azaman Layin layi
requestDrawingObject.setWrapType(DrawingObjectInsert.WrapTypeEnum.INLINE);
// karanta shigar da hoton JPG
byte[] requestImageFile = Files.readAllBytes(Paths.get("Tulips.jpg").toAbsolutePath());
// ƙ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);
System.out.println("JPG to Word Conversion completed !");
}catch(Exception ex)
{
System.out.println(ex);
}
Za a iya sauke samfurin fayilolin da aka yi amfani da su a sama misali daga Tulips.jpeg da Resultant.docx.
JPG zuwa DOC ta amfani da Umarnin CURL
A cikin wannan sashe, za mu yi amfani da umarnin CURL don canza JPG zuwa DOC. Muna amfani da umarnin CURL saboda suna ba mu damar samun dama ga APIs REST ta tashar layin umarni. Yanzu a matsayin abin da ake buƙata don wannan hanyar, da farko muna buƙatar samar da alamar samun damar JWT (dangane da shaidar abokin ciniki) yayin aiwatar 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"
Da zarar mun sami alamar JWT, mataki na gaba shine ƙirƙirar takaddar Kalma ta amfani da umarni mai zuwa.
curl -v -X PUT "https://api.aspose.cloud/v4.0/words/create?fileName=input.docx" \
-H "accept: application/json" \
-H "Authorization: Bearer <JWT Token>"
Yanzu da aka ƙirƙiri daftarin rubutu mara kyau, muna buƙatar shigar da abin Zane mai ɗauke da hoton JPG a cikin fayil ɗin DOCX.
curl -v -X POST "https://api.aspose.cloud/v4.0/words/input.docx/sections/0/drawingObjects?destFileName=resultant.docx" \
-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":{"Tulips.jpg"}}
Kammalawa
A cikin wannan labarin, mun koyi game da cikakkun bayanai don canza hoto zuwa kalma ta amfani da Java Cloud SDK. Baya ga snippet na lamba, mun kuma bincika zaɓuɓɓukan canza JPG zuwa DOC ta amfani da Umarnin CURL da haɓaka hoto zuwa mai sauya Kalma akan layi. Samfurin Takardu an wadatar da shi tare da ɗimbin batutuwa masu ban mamaki suna ƙara yin bayanin iyawar wannan API. Bugu da ƙari, da fatan za a lura cewa duk Cloud SDKs an buga su ƙarƙashin lasisin MIT, don haka kuna iya yin la’akari da zazzage cikakkiyar lambar tushe daga GitHub kuma gyara ta gwargwadon buƙatun ku. A cikin kowane matsala, kuna iya la’akari da kusantar mu don ƙuduri mai sauri ta hanyar [Tallafin tallafin samfur 9.
Labarai masu alaka
Da fatan za a ziyarci hanyoyin haɗin yanar gizon don ƙarin koyo game da: