GithubHelp home page GithubHelp logo

timr11 / convertapi-go Goto Github PK

View Code? Open in Web Editor NEW

This project forked from convertapi/convertapi-go

0.0 0.0 0.0 1.07 MB

A Go library for the ConvertAPI

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

License: Other

Go 100.00%

convertapi-go's Introduction

ConvertAPI Go Client

example workflow

Convert your files with our online file conversion API

ConvertAPI helps in 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 other file manipulations. You can integrate it into your application in just a few minutes and use it easily.

The ConvertAPI-Go library makes it easier to use the Convert API from your Go projects without having to build your own API calls. You can get your free API secret at https://www.convertapi.com/a

Installation

Execute this command in your GOPATH:

go get github.com/timr11/convertapi-go

Usage

Configuration

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

config.Default.Secret = "your-api-secret"

or

config.Default.Token = "your-token"
config.Default.ApiKey = "your-api-key"

File conversion

Convert DOCX file to PDF example. All supported formats and options can be found here.

pdfRes := convertapi.ConvDef("docx", "pdf", param.NewPath("file", "test.docx", nil))

// save to file
pdfRes.ToPath("/tmp/result.pdf")

Other result operations:

// save all result files to folder
res.ToPath("/tmp")

// get second file in result
files, err := res.Files()
secondFile := files[1]

// result implements Reader interface so it is possible to stream result
io.Copy(myReader, res)

// get conversion cost
cost, err := res.Cost()

Convert remote file

pptxRes := convertapi.ConvDef("pptx", "pdf",
    param.NewString("file", "https://cdn.convertapi.com/cara/testfiles/presentation.pptx"),
)

Additional conversion parameters

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

jpgRes := convertapi.ConvDef("pdf", "jpg",
    param.NewResult("file", extractRes, nil),
    param.NewBool("scaleimage", true),
    param.NewBool("scaleproportions", true),
    param.NewInt("imageheight", 300),
)

User information

You can always check your remaining seconds programmatically by fetching user information.

user, err := convertapi.UserInfo(nil)
secondsLeft := user.SecondsLeft

Alternative domain

How to set an alternative domain can be found in the advanced example. Dedicated to the region domain list.

More examples

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 a WORD DOCX file to PDF:

package main

import (
	"github.com/timr11/convertapi-go"
	"fmt"
	"os"
)

func main() {
	config.Default.Secret = "your-api-secret"

	if file, errs := convertapi.ConvertPath("test.docx", "/tmp/result.pdf"); errs == nil {
		fmt.Println("PDF file saved to: ", file.Name())
	} else {
		fmt.Println(errs)
	}
}

This is the bare-minimum to convert a file using the ConvertAPI client, but you can do a great deal more with the ConvertAPI Go 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 Go Library is licensed under the MIT license. Refer to the LICENSE file for more information.

convertapi-go's People

Contributors

jonas-jasas avatar jonasjasas avatar kostas-jonauskas avatar lilien1010 avatar timr11 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.