Ngonversi jpg menyang pdf

Sinau carane ngowahi JPG dadi PDF

Artikel iki nerangake langkah-langkah sing gampang lan prasaja kanggo ngowahi JPG dadi PDF nggunakake Java Cloud SDK. Kita ngerti manawa format JPG minangka salah sawijining format gambar raster sing akeh digunakake lan minangka format standar kanggo njupuk gambar saka kamera digital, telpon seluler, lan sapiturute. situs web. Nanging, yen sampeyan duwe akeh gambar sing kudu dienggo bareng online, konversi dadi PDF minangka pilihan sing tepat. Kita uga bisa nggawe album foto sing apik, nyuda ukuran file kanthi gampang, entuk resolusi sing luwih apik, lsp.

JGP kanggo PDF Konversi API

Aspose.PDF Cloud SDK for Java nyedhiyakake kapabilitas kanggo nggawe, ngowahi lan ngowahi macem-macem format file menyang format PDF. Uga ndhukung fitur kanggo ngowahi JPG dadi PDF / Gambar dadi PDF / Foto dadi PDF ing aplikasi Java. Saiki kanggo nggunakake SDK, mangga nambah rincian ing ngisor iki ing pom.xml saka project jinis mbangun 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>

Sawise instalasi, kita kudu nggawe akun gratis kanthi ngunjungi Aspose.Cloud dashboard. Cukup Ndaftar nggunakake akun GitHub utawa Google sing wis ana, utawa klik tombol Gawe Akun anyar.

JPG menyang PDF ing Jawa

Ing bagean iki, kita bakal ngrembug rincian kanggo ngowahi JPG dadi PDF nggunakake potongan kode java.

  • Kaping pisanan, nggawe obyek PdfApi nalika ngliwati rincian ClientID lan ClientSecret minangka argumen
  • Kapindho, gawe file PDF kosong nggunakake metode putCreateDocument(…) saka kelas PdfApi kanggo nggawe dokumen PDF kosong.
  • Saiki nelpon postInsertImage(..) metode sing njupuk jeneng file PDF input, PageNumber, koordinat XY, lan jeneng file gambar minangka argumen
// kanggo conto liyane, bukak https://github.com/aspose-pdf-cloud/aspose-pdf-cloud-java/tree/master/Examples/src/main/java/com/aspose/asposecloudpdf/examples

try
    {
    // Entuk ClientID lan ClientSecret saka https://dashboard.aspose.cloud/
    String clientId = "bbf94a2c-6d7e-4020-b4d2-b9809741374e";
    String clientSecret = "1c9379bb7d701c26cc87e741a29987bb";
    
    // nggawe conto PdfApi
    PdfApi pdfApi = new PdfApi(clientSecret,clientId);
    
    // jeneng input gambar JPG
    String imageFile = "Compare-Word-Document-preview.jpg";
    
    String resultantPDF = "Resultant.pdf";
    // nggawe dokumen PDF kosong ing panyimpenan maya
    DocumentResponse document = pdfApi.putCreateDocument(resultantPDF, "Internal",null);
        
    // mbukak gambar JPG saka drive lokal
    File file = new File("c://Downloads/"+imageFile);
    
    // nomer kaca file PDF
    int pageNumber = 1;
        
    // koordinat kanggo gambar ing dokumen PDF
    // Koordinat kasebut ana ing Titik wiwit saka Ngisor-Kiwa nganti Ndhuwur-Tengen
    double llx = 10.0;
    double lly = 850;
    double urx = 580.0;
    double ury = 650.0;
    
        
    // jeneng Jeneng dokumen. (dibutuhake)
    // pageNumber Nomer kaca. (dibutuhake)
    // llx Koordinat sisih kiwa ngisor X. (dibutuhake)
    // lly Koordinasi kiwa ngisor Y. (dibutuhake)
    // urx Koordinat ndhuwur tengen X. (dibutuhake)
    // ury Koordinat ndhuwur tengen Y. (dibutuhake)
    // imageFilePath Path menyang file gambar yen kasebut. Panjaluk isi digunakake digunakake. (opsional)
    // panyimpenan Dokumen panyimpenan. (opsional)
    // folder Folder dokumen. (opsional)
    // gambar File gambar. (opsional)
    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);
		}
gambar menyang pratinjau PDF

Pratinjau konversi gambar menyang PDF

Gambar menyang PDF nggunakake CURL Commands

Kita uga bisa nindakake konversi JPG menyang PDF nggunakake perintah cURL. Minangka prasyarat, kita kudu nglakokake printah ing ngisor iki kanggo ngasilake token akses 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"

Sawise JWT digawe, tindakake printah ing ngisor iki kanggo ngasilake dokumen PDF kosong lan simpen ing panyimpenan awan.

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

Saiki kita kudu nglakokake perintah ing ngisor iki kanggo nyelehake gambar JPG ing dokumen 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":{}}

Kesimpulan

Ing blog iki, kita wis ngrembug langkah-langkah kanggo ngowahi JPG dadi PDF nggunakake potongan kode Java. Kita uga wis njelajah pilihan kanggo ngowahi Gambar dadi PDF / foto dadi PDF nggunakake perintah cURL. Sampeyan uga bisa njelajah conto liyane sing kasedhiya ing gudang GitHub Coba gunakake API kita lan yen sampeyan nemoni masalah nalika nggunakake API, mangga hubungi Forum dhukungan produk gratis.

Artikel sing gegandhengan

Kita uga nyaranake ngunjungi blog ing ngisor iki kanggo rincian liyane babagan: