jpg to pdf

Convert JPG to PDF with .NET REST API.

Information exchange and document sharing are integral to daily workflows, and the ability to convert JPG images to PDF documents has become indispensable. While JPG files serve as common formats for capturing and storing images, they lack the versatility and portability necessary for comprehensive document management. Therefore, a transformative process for converting JPG to PDF bridges the gap between static images and dynamic, multipage documents. This article explores the pressing need for this conversion feature using .NET REST API.

JPG to PDF Conversion API

With Aspose.PDF Cloud SDK for .NET, you can initiate JPG to PDF conversion effortlessly, preserving image quality and ensuring accurate representation in the resulting PDF document. The cloud-based architecture of Aspose.PDF Cloud ensures scalability and accessibility, enabling you to integrate the advanced features seamlessly into your applications without the need for complex local installations.

  • Apart from conversion, you may leverage the powerful SDK to manipulate PDF documents in various ways, including merging, splitting, and compressing PDF files, extracting text and images, adding annotations and watermarks, and even performing OCR (Optical Character Recognition) to extract text from scanned documents.

The first step is to search Aspose.Pdf-Cloud in NuGet packages manager and click the Add Package button. This will add the SDK reference in your project. Secondly, obtain your client credentials from cloud dashboard. If you do not have an existing account, simply create a free account by following the instructions specified in the quick start article.

Convert JPG to PDF in C# .NET

The following section explains the details on how we can achieve efficient JPG to PDF conversion and enhance our document processing workflows with unparalleled efficiency and flexibility using C# .NET.

PdfApi pdfApi = new PdfApi(clientSecret, clientID);

Create an object of PdfApi class where we pass client credentials as arguments.

DocumentResponse document = pdfApi.PutCreateDocument(resultantPDF, "basic", null);

Create a blank PDF file and store in cloud storage.

pdfApi.PostInsertImage(resultantPDF, pageNumber, llx, lly, urx, ury, null, "basic", null, inputFile);

Call API to place image in first page of PDF file and set margin details as specified above.

jpg to pdf

A preview of JPG to PDF conversion.

The sample JPG image and the resultant PDF generated in above example can be downloaded from input.jpg and Resultant.pdf

  • Use our free online PDF Viewer to preview the resultant PDF document.

Convert Image to PDF using cURL Commands

As an alternative, you may convert JPG images to PDF documents using a simplified and efficient combination of Aspose.PDF Cloud and cURL commands. By utilizing the cURL commands, you can seamlessly initiate the JPG to PDF conversion. This approach streamlines the process while ensuring accuracy in preserving image quality and maintaining the integrity of the resulting PDF document.

The first step in this approach is to generate a JWT access token using the following command:

curl -v "https://api.aspose.cloud/connect/token" \
 -X POST \
 -d "grant_type=client_credentials&client_id=163c02a1-fcaa-4f79-be54-33012487e783&client_secret=c71cfe618cc6c0944f8f96bdef9813ac" \
 -H "Content-Type: application/x-www-form-urlencoded" \
 -H "Accept: application/json"

Once we have the JWT token, please execute the following command to create a blank PDF file and store in cloud storage.

curl -v -X PUT "https://api.aspose.cloud/v3.0/pdf/input.pdf" \
-H  "accept: application/json" \
-H  "authorization: Bearer {accessToken}"

Now, please execute the following command to insert a JPG image in a PDF document and save the resultant file to cloud storage.

curl -v "https://api.aspose.cloud/v3.0/pdf/{sourceFile}/pages/1/images?llx=1&lly=1&urx=680&ury=850&imageFilePath=44781.jpg&storage=basic" \
-X POST \
-H "accept: application/json" \
-H "authorization: Bearer {accessToken}" \
-H "Content-Type: multipart/form-data"

Replace sourceFile with the name of input blank PDF file already available in cloud storage, and accessToken with JWT access token generated above.

Conclusion

In conclusion, both approaches — leveraging the Aspose.PDF Cloud SDK for .NET and utilizing cURL commands with Aspose.PDF Cloud, offer efficient and reliable solutions for converting JPG images to PDF documents. Embracing either approach enables you to streamline your document processing workflows and unlock a wide range of capabilities for efficient and reliable document conversion. It stands as the optimal choice, providing you with the tools you need to elevate their document management processes and enhance productivity with unparalleled efficiency and flexibility.

We highly recommend visiting the following blog posts for information on: