canza jpg zuwa pdf

Koyi yadda ake canza JPG zuwa PDF

Wannan labarin yana bayanin matakai masu sauƙi da sauƙi don canza JPG zuwa PDF ta amfani da Java Cloud SDK. Mun san cewa tsarin JPG yana ɗaya daga cikin manyan fayilolin raster da ake amfani da su kuma shine tsarin da aka saba amfani dashi don ɗaukar hotuna daga kyamarori na dijital, wayoyin hannu, da sauransu. Saboda girmansu da aka matsa, ana yawan raba su akan intanet kamar yadda ake nunawa akan su. gidajen yanar gizo. Koyaya, idan kuna da tarin hotuna waɗanda ke buƙatar raba kan layi, jujjuyawa zuwa PDF shine zaɓin da ya dace. Hakanan zamu iya ƙirƙirar kundin hoto mai kyau, rage girman fayil cikin sauƙi, samun ingantaccen ƙuduri, da sauransu.

API ɗin Canjawar JGP zuwa PDF

Aspose.PDF Cloud SDK don Java yana ba da damar ƙirƙira, shiryawa da canza nau’ikan fayilolin fayil zuwa tsarin PDF. Hakanan yana goyan bayan fasalin don canza JPG zuwa PDF / Hoto zuwa PDF / Hoto zuwa PDF a cikin aikace-aikacen Java. Yanzu don amfani da SDK, da fatan za a ƙara cikakkun bayanai masu zuwa a cikin pom.xml na nau’in ginin maven.

<repositories>
    <repository>
        <id>AsposeJavaAPI</id>
        <name>Aspose Cloud Repository</name>
        <url>https://repository.aspose.cloud/repo/</url>
    </repository>
</repositories>

<dependencies>
    <dependency>
		<groupId>com.aspose</groupId>
		<artifactId>aspose-pdf-cloud</artifactId>
		<version>21.11.0</version>
	</dependency>
</dependencies>

Bayan shigarwa, muna buƙatar ƙirƙirar asusun kyauta ta ziyartar Aspose.Cloud dashboard. Kawai Yi rajista ta amfani da asusun GitHub ɗinku ko Google, ko danna maɓallin Ƙirƙiri sabon Asusu.

JPG zuwa PDF a cikin Java

A cikin wannan sashe, zamu tattauna cikakkun bayanai don canza JPG zuwa PDF ta amfani da snippets code na java.

  • Da farko, ƙirƙiri wani abu na PdfApi yayin wucewar ClientID da bayanan sirri na Client hujja ne.
  • Na biyu, ƙirƙirar fayil ɗin PDF mara kyau ta amfani da hanyar putCreateDocument(…) na ajin PdfApi don ƙirƙirar takaddar PDF mara kyau.
  • Yanzu kira postInsertImage(..) wanda ke ɗaukar sunan fayil ɗin PDF, PageNumber, daidaitawar XY, da sunan fayil ɗin hoto azaman muhawara.
// don ƙarin misalai, da fatan za a ziyarci https://github.com/aspose-pdf-cloud/aspose-pdf-cloud-java/tree/master/Examples/src/main/java/com/aspose/asposecloudpdf/examples

try
    {
    // Samu ClientID da ClientSecret daga https://dashboard.aspose.cloud/
    String clientId = "bbf94a2c-6d7e-4020-b4d2-b9809741374e";
    String clientSecret = "1c9379bb7d701c26cc87e741a29987bb";
    
    // ƙirƙirar misali na PdfApi
    PdfApi pdfApi = new PdfApi(clientSecret,clientId);
    
    // sunan shigar da hoton JPG
    String imageFile = "Compare-Word-Document-preview.jpg";
    
    String resultantPDF = "Resultant.pdf";
    // ƙirƙirar takaddar PDF mara kyau a cikin ma'ajin gajimare
    DocumentResponse document = pdfApi.putCreateDocument(resultantPDF, "Internal",null);
        
    // ɗora hoton JPG daga faifan gida
    File file = new File("c://Downloads/"+imageFile);
    
    // lambar shafi na fayil ɗin PDF
    int pageNumber = 1;
        
    // daidaitawa don hoto a cikin takaddun PDF
    // Masu daidaitawa suna cikin Point farawa daga Kasa-Hagu zuwa Sama-Dama
    double llx = 10.0;
    double lly = 850;
    double urx = 580.0;
    double ury = 650.0;
    
        
    // suna Sunan takardar. (da ake bukata)
    // Lambar shafi Lambar shafi. (da ake bukata)
    // llx Hagu na ƙasa na hagu X. (an buƙata)
    // lly Coordinate ƙananan hagu Y. (an buƙata)
    // Urx Coordinate na sama na dama X. (an buƙata)
    // ury Coordinate na sama dama Y. (an buƙata)
    // imageFilePath Hanyar zuwa fayil ɗin hoto idan an ƙayyade. Ana amfani da abun ciki na buƙatar in ba haka ba. (na zaɓi)
    // ajiya Ajiye daftarin aiki. (na zaɓi)
    // babban fayil Babban fayil ɗin daftarin aiki. (na zaɓi)
    // Hoton fayil ɗin hoto. (na zaɓi)
    pdfApi.postInsertImage(resultantPDF, pageNumber, llx, lly, urx, ury, null,"Internal",null,file);
        
    System.out.println("JPG to PDF Conversion sucessfull !");
		}catch(Exception ex)
		{
			System.out.println(ex);
		}
hoto zuwa preview PDF

Hoto zuwa samfoti na juyawa PDF

Hoto zuwa PDF ta amfani da Umarnin CURL

Hakanan zamu iya yin jujjuya JPG zuwa PDF ta amfani da umarnin CURL. A matsayin buƙatun farko, muna buƙatar aiwatar da umarni mai zuwa don samar da alamar samun damar JWT.

curl -v "https://api.aspose.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=bbf94a2c-6d7e-4020-b4d2-b9809741374e&client_secret=1c9379bb7d701c26cc87e741a29987bb" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"

Da zarar an ƙirƙiri JWT, da fatan za a aiwatar da umarni mai zuwa don ƙirƙirar takaddar PDF mara kyau kuma a adana shi cikin ma’ajiyar girgije.

curl -v -X PUT "https://api.aspose.cloud/v3.0/pdf/input.pdf" \
-H  "accept: application/json" \
-H  "authorization: Bearer <JWT Token>"

Yanzu muna buƙatar aiwatar da umarni mai zuwa don sanya hoton JPG a cikin takaddar PDF.

curl -v -X POST "https://api.aspose.cloud/v3.0/pdf/input.pdf/pages/1/images?llx=10.0&lly=850.0&urx=580.0&ury=650.0&imageFilePath=source.JPG" \
-H  "accept: application/json" \
-H  "authorization: Bearer <JWT Token>" \
-H  "Content-Type: multipart/form-data" \
-d {"image":{}}

Kammalawa

A cikin wannan shafin, mun tattauna matakan canza JPG zuwa PDF ta amfani da snippets code na Java. Mun kuma bincika zaɓin canza Hoto zuwa PDF / hoto zuwa PDF ta amfani da umarnin CURL. Hakanan kuna iya bincika wasu misalan da ake samu akan GitHub repository Da fatan za a gwada amfani da APIs ɗin mu kuma idan kun kasance kuna. gamu da kowace matsala yayin amfani da API, da fatan za a ji daɗin tuntuɓar Zauren tallafin samfur na Kyauta.

Labarai masu alaka

Muna kuma ba da shawarar ziyartar shafukan yanar gizo masu zuwa don ƙarin cikakkun bayanai kan: