Aspose.PDF Cloud: Converting documents using C# SDK
Andriy Andruhovski May 29 Updated on Jun 19, 2018
In the previous post, we taught upload files to Aspose.Cloud. Now we will consider basic steps to convert documents with Aspose.Cloud API.
For the first example, we will use converting HTML to PDF. Let assume for easy that source files will be located in
"Html-Demo" folder on the default storage and we will store resultant files on
As in the previous post, we create a console application, but now we will add two packages:
- to manage storage (
- to manipulate documents (
The next step is to declare the necessary fields and constants in our class.
So, we are ready to convert our files from HTML to PDF. To get a list of files we call a
GetListFiles method and filter the results.
All that's left to do is call a conversion API method
PutCreateDocument with appropriate parameters. It should be noted that this method has parameters for several cases of converting, but we set values required only for this one:
- name - destination filename (only name, not a path);
- templateFile - the source file path;
- templateType - the content type of source file, can be xml, html, bmp, jpg, png, tiff, emf, cgm, tex;
- folder - destination folder;
- storage - storage name.
In this case, we deal with an
ApiException. This class is similar to the generic exception, but it has an additional field
ErrorContent. This field usually holds JSON-string with the error message.
The following snippet holds the full code of our function:
As you can see above, we can convert to PDF from different file types. Let's try to change HTML to JPEG:
In this case, we get the PDF document too, but with raster image per file.
To combine a series of images into one PDF we need to call
PutCreateDocumentFromImages method. The following snippet shows how we can combine JPEG files into one PDF. To reduce the explanation, named arguments were used.
So, in this post, we were considered how to create PDF from different formats. In the next article, we will consider the reverse process - converting from PDF to another file formats.