Giter Site home page Giter Site logo

zanzo420 / convertapi-dotnet Goto Github PK

View Code? Open in Web Editor NEW

This project forked from convertapi/convertapi-dotnet

0.0 0.0 0.0 3.21 MB

A .NET library for the ConvertAPI

Home Page: https://www.convertapi.com

License: Other

C# 98.97% Dockerfile 1.03%

convertapi-dotnet's Introduction

ConvertAPI C# Client

Convert your files with our online file conversion API

The ConvertAPI helps converting various file formats. Creating PDF and Images from various sources like Word, Excel, Powerpoint, images, web pages or raw HTML codes. Merge, Encrypt, Split, Repair and Decrypt PDF files. And many others files manipulations. In just few minutes you can integrate it into your application and use it easily.

The ConvertAPI.NET NuGet package makes it easier to use the Convert API from your .NET 2, 3.x, and 4.x projects without having to build your own API calls. You can get your free API secret at https://www.convertapi.com/a

Installation

Run this line from Package Manager Console:

Install-Package ConvertApi

Usage

Configuration

You can get your secret at https://www.convertapi.com/a

ConvertApi convertApi = new ConvertApi("your-api-secret");

File conversion

Example to convert file to PDF. All supported formats and options can be found here.

ConvertApiResponse result = await convertApi.ConvertAsync("docx", "pdf", new[]
{
   new ConvertApiFileParam(@"c:\source\test.docx")   
});

// save to file
 var fileInfo = await result.SaveFileAsync(@"\result\test.pdf");

Other result operations:

// save all result files to folder
result.SaveFilesAsync(@"\result\");

// get result files
ProcessedFile[] files = result.Files;

// get conversion cost
int cost = result.ConversionCost; 

Convert file url

ConvertApiResponse result = await convertApi.ConvertAsync("pptx", "pdf", new[]
{
   new ConvertApiFileParam(new Uri("https://cdn.convertapi.com/cara/testfiles/presentation.pptx"))
});

Additional conversion parameters

ConvertAPI accepts extra conversion parameters depending on converted formats. All conversion parameters and explanations can be found here.

ConvertApiResponse result = await convertApi.ConvertAsync("pdf", "jpg", new[]
{
   new ConvertApiFileParam(@"c:\source\test.docx"),
   new ConvertApiParam("ScaleImage","true"),
   new ConvertApiParam("ScaleProportions","true"),
   new ConvertApiParam("ImageHeight","300"),
   new ConvertApiParam("ImageWidth","300")
});

User information

You can always check remaining seconds amount by fetching user information.

ConvertApiUser user = await convert.GetUserAsync();
int secondsLeft = user.SecondsLeft;

More examples

You can find more advanced examples in the examples folder.

Converting your first file, full example:

ConvertAPI is designed to make converting file super easy, the following snippet shows how easy it is to get started. Let's convert WORD DOCX file to PDF:

try
{
  var convertApi = new ConvertApi("your-api-secret");  
  var conversionTask = await convertApi.ConvertAsync("docx", "pdf", 
      new ConvertApiFileParam(@"c:\source\test.docx")
      );
  var fileSaved = await conversionTask.Files.SaveFilesAsync(@"c:\");
  }
  //Catch exceptions from asynchronous methods
  catch (ConvertApiException e)
  {
     Console.WriteLine("Status Code: " + e.StatusCode);
     Console.WriteLine("Response: " + e.Response);

      if (e.StatusCode == HttpStatusCode.Unauthorized)
          Console.WriteLine("Secret is not provided or no additional seconds left in account to proceed conversion. More information https://www.convertapi.com/a");
  }

This is the bare-minimum to convert a file using the ConvertAPI client, but you can do a great deal more with the ConvertAPI .NET library. Take special note that you should replace your-api-secret with the secret you obtained in item two of the pre-requisites.

Issues & Comments

Please leave all comments, bugs, requests, and issues on the Issues page. We'll respond to your request ASAP!

License

The ConvertAPI .NET Library is licensed under the MIT license. Refere to the LICENSE file for more information.

convertapi-dotnet's People

Contributors

jonas-jasas avatar jonasjasas avatar kostas-baltsoft avatar tomasr78 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.