PNG to PDF

Convert PNG to PDF | Combine PNG to PDF Online

(PNG) (Portable Network Graphics) and PDF (Portable Document Format) serve distinct purposes in the digital world. PNG is widely used for high-quality images due to its lossless compression and transparency support, making it ideal for web design, graphic creation, and detailed visual content. On the other hand, PDF is a universal format for document sharing and archiving, ensuring layout consistency across devices. Converting PNG to PDF is a beneficial process for creating compilations, generating professional reports

Image Conversion API

Aspose.Imaging Cloud is our dedicated REST API developed to facilitate our customers looking for image processing and manipulation capabilities in the Cloud. You can perform operations such as image resizing, cropping, rotating, scaling, flipping, searching, export to other Supported File Formats. Now, as per this article, we are going to use Aspose.Imaging Cloud SDK for .NET which is a wrapper around Aspose.Imaging Cloud.

Installation

The .NET Cloud SDK is available for download over NuGet and GitHub. Please execute the following command in the terminal to install the SDK via NuGet:

nuget install Aspose.Imaging-Cloud

In case you need to install from NuGet Package Manager, please execute the following command

PM> Install-Package Aspose.Imaging-Cloud

Install in Visual Studio

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.Imaging-Cloud“.
  5. Click the checkbox besides Aspose.Imaging-Cloud package, select the appropriate version in the right tab and click Add Package button.
Aspose.Imaging-Cloud

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

Cloud Subscription

The next step is to create a free subscription account by visiting Aspose.Cloud dashboard. If you have a GitHub or Google account, simply Sign Up. Otherwise, click on the Create a new Account button and provide the required information.

Convert PNG to PDF

In order to convert a PNG image to PDF format, we may use either of the following two APIs to accomplish this requirement:

The GET API expects you to first upload an image to Cloud Storage and then perform the conversion. Whereas the second API requires you to directly pass the image in the request body and the final output is stored on the Cloud Storage.

Load PNG from Cloud Storage

The following steps define how we can first upload an image to Cloud storage and then will perform the conversion. If we skip the image upload routine, then we can also convert any existing image in Cloud storage to PDF format with the same code snippet.

  • Firstly, we need to create an ImagingApi object while passing Client ID and Client Secret details as arguments.
  • Secondly, load PNG image from local drive and pass it as argument to UploadFileRequest object.
  • Thirdly, call the UploadFile(…) method of ImagingApi to upload the file to Cloud storage (you may skip this step if the image is already available in Cloud storage).
  • Create an instance of ConvertImageRequest class which takes the image name and resultant output format as arguments. Folder and Storage names are optional.
  • Now call the ConvertImage(…) method of ImagingApi class to initiate the conversion.
  • Finally, as the response contains a streamed image, so we can save s to a local drive by using File.Create an object (the method is shown below).

Load PNG from Local Drive

In the following section, we are going to use CreateConvertedImage API to convert an image directly passed in the request body.

  • The first step is to create an ImagingApi object which takes Client ID and Client Secret details as arguments.
  • Secondly, read the PNG image from the local drive using File.OpenRead object.
  • Thirdly, create ConvertedImageRequest object which takes ImageStream and output format as arguments.
  • Then call the CreateConvertedImage(…) method of ImagingApi to perform the conversion operation.
  • Finally, save the resultant PDF using File.Create object.
PNG to PDF preview

Image 3:- PNG to PDF conversion preview.

You may consider downloading the input poodle.png and converted resultant.pdf for testing purposes.

PNG to PDF Online using cURL Commands

Our APIs can also be accessed via cURL commands, so we are going to convert PNG to PDF using cURL Commands. So first we need to generate a JWT access token based on Client ID and Client Secret details.

curl -v "https://api.aspose.cloud/connect/token" \
-X POST \
-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 access token has been generated, please execute the following command to convert a PNG image available in Cloud storage to PDF format. The output PDF is then stored on a local drive.

curl -X GET "https://api.aspose.cloud/v3.0/imaging/poodle.png/convert?format=pdf" \
-H  "accept: application/json" \
-H  "authorization: Bearer <JWT Token>" \
-o /Users/nshahbaz/Desktop/myResultant.pdf

Free PNG to PDF Converter

In order to witness the amazing capabilities of the Cloud API for PNG image to PDF conversion, you may try using our Free online PNG to Acrobat 3D PDF converter App.

png to pdf converter

A preview of free PNG to Acrobat 3D PDF converter App

Conclusion

In this article, we have explored the capabilities of Aspose.Imaging Cloud to convert PNG to PDF format. We have also observed that conversion can be performed using .NET Cloud SDK as well as the cURL command. We have also provided the Swagger UI so you can test the REST API directly within the browser.

Also, please be noted that the Cloud SDK is distributed under an MIT license and its complete source code is available for download over GitHub. In case you encounter any issues or have any queries while using the API, please feel free to contact us through the Free product support forum.

We also recommend visiting the following links to learn more about: