kalma zuwa jpg

Canza Kalma zuwa JPG a Java

Microsoft Word yana ba ku damar ƙirƙirar takaddun sarrafa kalmomi masu sauƙi kamar haruffa da rahotanni. Kuna iya ƙara launi, zane-zane, rubutawa cikin nau’ikan rubutu da girma dabam, ƙara teburi, iyakoki & tsara harsashi. Koyaya, don duba takaddar Kalma (DOC, DOCX), muna buƙatar takamaiman aikace-aikace kamar MS Word, OpenOffice da sauransu. Wani lokaci yana da wahala sosai don duba waɗannan takaddun akan na’urori masu ɗaukar nauyi ( wayoyin hannu da sauransu). Don haka ɗayan mafi kyawun mafita shine canza Kalma zuwa Tsarin Hoto (JPG, PNG, GIF da sauransu). Don haka a cikin wannan labarin, za mu bincika cikakkun bayanai kan yadda ake Canza Kalma zuwa JPG ta amfani da Java REST API.

Canjin JPG zuwa REST API

Don ƙirƙira, gyara da canza takaddun Kalma zuwa nau’ikan tsararrun tallafi, mun ƙirƙira tushen tushen REST mai suna Aspose.Words Cloud. Domin mu yi amfani da damar sarrafa daftarin aiki iri ɗaya a cikin aikace-aikacen Java, muna buƙatar gwada amfani da Aspose.Words Cloud SDK don Java. Yanzu 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>

Da zarar an ƙara bayanin Java Cloud SDK, da fatan za a sami takaddun shaidar abokin ciniki daga Cloud Dashboard. In ba haka ba, kuna buƙatar fara rajistar asusun kyauta, ta amfani da ingantaccen adireshin imel.

Canza Kalma zuwa JPG a Java

A cikin wannan sashe, za mu tattauna matakai da cikakkun bayanai masu alaƙa don canza Kalma zuwa JPG ta amfani da Java.

  • Fara tare da ƙirƙirar WordsApi abu inda muka wuce keɓaɓɓen takaddun shaida azaman muhawara
  • Abu na biyu, loda daftarin aiki daftarin aiki ta amfani da hanyar readAllBytes(…) sannan ku wuce ƙimar da aka dawo zuwa byte[] tsararru.
  • Na uku, ƙirƙiri wani abu na ConvertDocumentRequest wanda ke ɗaukar shigar da sunan takaddar Word, tsarin JPG da sunan fayil ɗin sakamakon azaman mahawara.
  • A ƙarshe, kira hanyar convertDocument(…) don aiwatar da fassarar Kalma zuwa JPG. Ana adana hoton sakamakon a cikin ma’ajiyar 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());
  
        // sakamakon hoto
        String format = "jpg";

        // ƙirƙiri buƙatun jujjuya daftarin aiki inda muka samar da sunan fayil na sakamako
        ConvertDocumentRequest convertRequest = new ConvertDocumentRequest(documentStream,format, "Converted.jpg",null, null, null);
  
        // Yi kalma zuwa jpg
        wordsApi.convertDocument(convertRequest);
      
    }catch(Exception ex)
    {
	System.out.println(ex);
    }
kalma zuwa jpg

Hoto:- Kalma zuwa PDF preview

Hoton shigarwar WebP da aka yi amfani da shi a cikin misalin da ke sama ana iya saukewa daga testmultipages.docx.

DOC zuwa JPG ta amfani da Umarnin CURL

Wata hanyar canza DOC zuwa JPG ita ce ta umarnin cURL. Don haka muna buƙatar fara samar da alamar samun damar JWT (dangane da shaidar abokin ciniki) ta amfani da umarni mai zuwa sannan mu aiwatar da DOC zuwa JPG ko DOCX zuwa JPG.

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"

Lura cewa waɗannan umarni masu zuwa suna tsammanin shigar da daftarin aiki Word a cikin ma’ajiyar gajimare. Bayan jujjuyawar, za mu iya adana sakamakon JPG zuwa faifan gida

curl -v -X GET "https://api.aspose.cloud/v4.0/words/test_multi_pages.docx?format=jpg" \
-H  "accept: application/octet-stream" \
-H  "Authorization: Bearer <JWT Token>" \
-o output.jpg

Hakanan muna iya yin la’akari da adana fayil ɗin sakamako a cikin ma’ajin gajimare kuma don wannan dalili, muna buƙatar samar da ƙimar siga na waje.

curl -v -X GET "https://api.aspose.cloud/v4.0/words/test_multi_pages.docx?format=jpg&outPath=newOutput.jpg" \
-H  "accept: application/octet-stream" \
-H  "Authorization: Bearer <JWT Token>"

Kammalawa

A cikin wannan labarin, mun bincika fasalin juyar da Kalma zuwa JPG ta amfani da Java da kuma ta umarnin cURL. Hakanan zaka iya gwada API ta SwaggerUI a cikin mai binciken gidan yanar gizo kuma a lokaci guda, kuna iya yin la’akari da bincika Takardun Samfura. Tushen bayani ne mai ban mamaki game da sauran abubuwan ban sha’awa waɗanda API ɗin ke bayarwa.

Idan kuna son zazzagewa da canza lambar tushe na Cloud SDK, ana samunta akan GitHub (an buga ƙarƙashin lasisin MIT). A ƙarshe, a cikin kowane lamari ko kuna buƙatar ƙarin haske / bayani game da APIs ɗin mu, da fatan za a tuntuɓe mu don saurin ƙuduri ta hanyar [zarun tallafin samfura] kyauta 9.

Labarai masu alaka

Da fatan za a ziyarci hanyoyin haɗin yanar gizon don ƙarin koyo game da: