package module
v0.0.0-...-1e0f0e2 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Apr 9, 2024 License: MIT Imports: 10 Imported by: 2


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


Execute this command in your GOPATH:

go get



You can get your secret at

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


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

Other result operations:

// save all result files to folder

// 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", ""),
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 (

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 {

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!


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




This section is empty.


This section is empty.


func ConvertPath

func ConvertPath(fromPath string, toPath string) (file *os.File, errs []error)


type ResFile

type ResFile struct {
	FileName string
	FileSize int
	Url      string
	// contains filtered or unexported fields

func (*ResFile) Delete

func (this *ResFile) Delete() error

func (*ResFile) Read

func (this *ResFile) Read(p []byte) (n int, err error)

func (*ResFile) ToFile

func (this *ResFile) ToFile(file *os.File) (err error)

func (*ResFile) ToPath

func (this *ResFile) ToPath(path string) (file *os.File, err error)

type Result

type Result struct {
	// contains filtered or unexported fields

func ConvDef

func ConvDef(fromFormat string, toFormat string, params ...param.IParam) (result *Result)

func Convert

func Convert(fromFormat string, toFormat string, params []param.IParam, conf *config.Config) (result *Result)

func NewResult

func NewResult() *Result

func (*Result) Cost

func (this *Result) Cost() (cost int, err error)

func (*Result) Delete

func (this *Result) Delete() (errs []error)

func (*Result) Files

func (this *Result) Files() (files []*ResFile, err error)

func (*Result) Read

func (this *Result) Read(p []byte) (n int, err error)

func (*Result) ToFile

func (this *Result) ToFile(file *os.File) (err error)

func (*Result) ToPath

func (this *Result) ToPath(path string) (files []*os.File, errs []error)

func (*Result) Urls

func (this *Result) Urls() (urls []string, err error)

type User

type User struct {
	Active      bool
	ApiKey      int
	Email       string
	FullName    string
	SecondsLeft int
	Secret      string
	Status      string

func UserInfo

func UserInfo(conf *config.Config) (user *User, err error)


Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL