jpg to pdf

JPG to PDF online

The JPG or JPEG images are very popular because as use a complex lossy compression algorithm enabling the users to create smaller graphics. The majority of devices including Desktop, mobile, and other handheld devices support JPG images. However, if we need to share a large set of images, or we need to compress them as a single archive, we can convert them to a single Portable Document Format (PDF). In this article, we are going to discuss the details on how to convert JPG to PDF using REST API.

JPG to PDF Conversion API

Aspose.Imaging Cloud is one of our popular APIs offering the capabilities to manipulate images on the cloud. Some of the exciting features include image resizing, cropping, rotation, and conversion to other supported file formats. It is developed as per REST API architecture, therefore it is platform-independent and can easily integrate with other cloud services. Also, when using programming language-specific SDKs, it takes care of the low-level details while enabling you to focus on writing code specific to your project requirements. Aspose.Imaging Cloud SDK for .NET is a wrapper around Aspose.Imaging and is capable of converting image to PDF.

PDF to JPG Conversion API

Similarly, Aspose.PDF Cloud is one of our leading REST APIs enabling the users to create, digitally sign, split, merge, & convert PDF files to HTML, XLS, XLSX, PPTX, DOC, XML, etc. At the same time, it also enables you to transform EPUB, PS, SVG, XPS, JPEG, and other popular formats to PDF.

Albeit, both the APIs provide the capability to transform JPG raster images to PDF format, we are going to focus on the conversion using Aspose.PDF Cloud SDK for .NET.


The first step in getting started with SDK usage is installation and it’s available for download at NuGet and| GitHub. Please execute the following command in the terminal to install the SDK via NuGet:

nuget install Aspose.Pdf-Cloud

Or execute the following command in NuGet Package Manager:

PM> Install-Package Aspose.Pdf-Cloud

Another approach is the installation directly within Visual Studio:

  1. Open the Solution Explorer.
  2. Expand the project and Right-click the Packages folder within your solution.
  3. Select Manage NuGet Packages… option
  4. Click on the Browse tab and search for “Aspose.Pdf-Cloud“.
  5. Click on the Aspose.Pdf-Cloud package, select the appropriate version in the right-tab and click Add Package button.
Aspose.PDF Cloud NuGet package

Image 1:- Aspose.PDF Cloud as NuGet package.

After installation, we need to create a free subscription account by visiting Aspose.Cloud dashboard where you can use your existing GitHub / Google account or simply Sign Up and obtain your Client Credentials.

How to Convert JPG to PDF in C#

Please follow the instructions below to convert the JPEG to PDF format using C# .NET code.

  • First of all, define Client ID and Client Secret details using string objects
  • Secondly, initialize the PdfApi object while passing Client ID and Client Secret details as arguments
  • Thirdly, read the file content and upload it to Cloud storage using the UploadFile(..) method of PdfApi
  • Next, create an object of ImageTemplatesRequest class where we define if OCR is enabled on image file, the language for OCR, margin details for image in PDF and page margin details.
  • Finally, call the PutImageInStorageToPdf(..) method of PdfApi class which take ouput PDF name and ImageTemplatesRequest object as arguments.
JPG to PDF preview

Image 2:- JPG to PDF conversion preview.

Convert Multiple JPG to PDF Online

image to pdf

Image 3:- Convert multiple images to PDF.

In case we have a requirement to convert a bulk of images to PDF format, all we need to do is create more instances of the ImageTemplate class within the ImageTemplatesRequest object. Please see the code snippet below which shows how easily we can convert three images available in Cloud storage to a single PDF document.

Similarly, you can specify different margin details for each image being placed inside the PDF document.

ImageTemplatesRequest imageTemplatesRequest = new ImageTemplatesRequest(IsOCR: true,
                OCRLangs: "eng",
                ImagesList: new List<ImageTemplate>()
                    new ImageTemplate(ImagePath: $"jpg_to_pdf.jpg", ImageSrcType: ImageSrcType.Common, LeftMargin : 10, RightMargin : 10),
                    new ImageTemplate(ImagePath: $"word-to-jpg.png", ImageSrcType: ImageSrcType.Common, LeftMargin : 0, RightMargin : 0),
                    new ImageTemplate(ImagePath: $"word-to-pdf.jpg", ImageSrcType: ImageSrcType.Common, LeftMargin : 5, RightMargin : 5)
combine jpg to pdf

Image 4:- Preview of 3 combine JPG to PDF.

Convert JPG to PDF using cURL Commands

As Aspose.PDF Cloud is developed as per REST architecture, so it can also be accessed via cURL commands. However, before accessing the APIs, we need to generate a JSON Web Token (JWT) based on ClientID and ClientSecret details retrieved from Aspose.Cloud dashboard. Please execute the following command in the terminal to generate the JWT token.

curl -v "" \
-d "grant_type=client_credentials&client_id=4ccf1790-accc-41e9-8d18-a78dbb2ed1aa&client_secret=caac6e3d4a4724b2feb53f4e460eade3" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"

Once the JWT token has been generated, please execute the following command to convert the JPG image to PDF format and save the output in Cloud storage.

curl -X PUT "" \
-H  "accept: application/json" \
-H  "authorization: Bearer <JWT Token>" \
-H  "Content-Type: application/json" \
-d "{  \"IsOCR\": true,  \"ImagesList\": [    {      \"ImagePath\": \"word-to-jpg.jpeg\",      \"ImageSrcType\": \"Common\",      \"LeftMargin\": 0,      \"RightMargin\": 0,      \"TopMargin\": 0,      \"BottomMargin\": 0,      \"PageWidth\": 800,      \"PageHeight\": 800,      \"MarginInfo\": {        \"Left\": 10,        \"Right\": 10,        \"Top\": 10,        \"Bottom\": 10      }    }  ]}"


In this article, we have discussed the details pertinent to JPG to PDF conversion using Aspose.PDF Cloud. The API is so robust that with the same code snippet, you may also convert PNG to PDF, TIFF to PDF, and Pic to PDF. Furthermore, the SDK is distributed under an MIT license and its complete source code is available for download over GitHub.

Should you have any related queries, please feel free to contact us via our Free product support forums.

You may consider visiting the following links to learn more about