Document Conversion Library for Go

The ConvertAPI Go library brings powerful document conversion and management capabilities into your Go applications. An intuitive API design, flexible parameters, and minimal overhead allow you to quickly add robust, high-quality document processing features into the Go workflows.

GitHub

Integrate within minutes

ConvertAPI library for Ruby is designed to streamline even the most complex workflows, the library’s flexible parameters and straightforward configuration help you reduce development overhead, improve efficiency, and deliver high-quality results with minimal effort.

It is easy to start converting documents using Go in a few simple steps:

1

Sign up for a free account

Sign up for free and receive 250 conversions to try and evaluate our service. You will receive a free trial with no credit card required upon registration!

2

Set up the conversion online

On your account dashboard you will access an intuitive UI tool that allows you to set up the conversion, adjust the parameters, and try the conversion online with zero code.

3

Copy auto-generated code snippet

Once you have set up the conversion parameters and are happy with the conversion results, you will receive an auto-generated Go code snippet with your custom parameters!

Get started now

Enterprise-Grade Document Processing

Document management toolkit for Go

With a simple integration in Go, you can convert documents not only to PDF, but also to images, text files, spreadsheets, ZIP archives, HTML, and many other destination formats, making it easy to automate file processing within your applications.

Select from 300+ converters and tools!

File Converter Suite

High-performance and unbeatable accuracy document converter suite with support for over 300+ conversion.

Document Builder using Go

Generate dynamic DOCX and PDF documents like invoices, contracts, reports, on the fly.

Document Management tools

Protect, redact, compare, watermark, flatten, compress and modify your documents using ConvertAPI Go SDK.

Security and Decryption

Protect and unprotect PDFs, MS Office Powerpoint and MS Office Word documents.

AI Data Extractor

Built to scale with your business, whether you're handling a few conversions or thousands.

Archiving & Optimization

Reduce file sizes without losing quality. Archive converters are designed to handle over 100 different file formats.

Configure it online - we will generate the Go code for you!

Configure your file conversion directly online using our intuitive interface. Select the desired parameters and see the results in real-time. Once you're satisfied, we’ll automatically generate the Go code for you, making integration into your project effortless. No need to start from scratch - just copy the code and implement it seamlessly into your Go application!

Get started now

File conversion example using Go

The ConvertAPI Go library delivers a comprehensive, developer-friendly solution for integrating powerful document conversion, manipulation, and management capabilities right into your Go applications. Designed with performance, simplicity, and scalability in mind, this library helps you handle a broad spectrum of file formats, ranging from PDFs and Office documents to images and beyond, through an intuitive and consistent API.

The library supports converting and processing hundreds of file types. Whether you need to transform PDFs into editable DOCX files, generate PDFs from images, or merge multiple documents into one streamlined output, the ConvertAPI Go library provides the versatility to handle diverse use cases without juggling multiple tools.

Install the ConvertAPI library into your Go project

To get started, install the ConvertAPI Go dependency. Execute this command in your GOPATH:

go get github.com/ConvertAPI/convertapi-go

Convert multiple images to a PDF using Go

The ConvertAPI Go library makes it easy to combine multiple images into a single, cohesive PDF document with just a few lines of code. Whether you’re building a client-ready report from various visual assets, or consolidating a set of scanned pages into a single digital file, the library streamlines the entire process.

By allowing you to fine-tune parameters, such as page size, orientation, and image compression, you can produce a custom-tailored PDF that meets your exact requirements. Its intuitive API ensures that even complex tasks, like merging numerous high-resolution images, fit seamlessly into your Go-based workflows, letting you focus on delivering polished, professional-quality output to your users.

// Code snippet is using the ConvertAPI JavaScript Client: https://github.com/ConvertAPI/convertapi-library-js

// Code snippet is using the ConvertAPI Node.js Client: https://github.com/ConvertAPI/convertapi-nodejs

// Code snippet is using the ConvertAPI PHP Client: https://github.com/ConvertAPI/convertapi-php

// Code snippet is using the ConvertAPI Java Client: https://github.com/ConvertAPI/convertapi-java

// Code snippet is using the ConvertAPI C# Client: https://github.com/ConvertAPI/convertapi-dotnet

# Code snippet is using the ConvertAPI Ruby Client: https://github.com/ConvertAPI/convertapi-ruby

# Code snippet is using the ConvertAPI Python Client: https://github.com/ConvertAPI/convertapi-python

// Code snippet is using the ConvertAPI Go Client: https://github.com/ConvertAPI/convertapi-go

REM Code snippet is using the command line utility program: https://github.com/ConvertAPI/convertapi-cli

<!-- For conversions with the multiple file result please refer to this example: https://repl.it/@ConvertAPI/HTML-Form-with-multiple-file-result -->

Conversion Chaining

The following example demonstrates a multi-step conversion process, such as converting a DOCX file to PDF and then compressing the PDF, showcasing how to chain multiple conversions seamlessly. It is meant for complex workflows requiring multiple file transformations in a specific sequence.

Key Features:

  • Performs sequential conversions using intermediate results.
  • Manages multiple steps within a single process.
  • Outputs the final converted file after all transformations.
ConvertApi.configure do |config|
  config.api_credentials = ENV['CONVERT_API_TOKEN'] # your api token
end

# Short example of conversions chaining, the PDF pages extracted and saved as separated JPGs and then ZIP'ed
# https://www.convertapi.com/doc/chaining

puts 'Converting PDF to JPG and compressing result files with ZIP'

jpg_result = ConvertApi.convert('jpg', {File: 'files/test.pdf'})

puts "Conversions done. Cost: #{jpg_result.conversion_cost}. Total files created: #{jpg_result.files.count}"

zip_result = ConvertApi.convert('zip', {Files: jpg_result.files})

puts "Conversions done. Cost: #{zip_result.conversion_cost}. Total files created: #{zip_result.files.count}"

saved_files = zip_result.save_files(Dir.tmpdir)

puts "File saved to #{saved_files}"

Convert File Streams

Illustrates how to convert a file streams, eliminating the need for intermediate file storage. It's useful for applications that handle file data dynamically, such as web services or cloud-based systems, where writing to disk is undesirable.

Key Features:

  • Reads input data from a stream.
  • Processes the conversion entirely in memory.
  • Outputs the result to another stream.
func main() {
    config.Default = config.NewDefault(os.Getenv("CONVERTAPI_TOKEN")) // Get your token at https://www.convertapi.com/a

    fmt.Println("Converting HTML from the stream to TXT")

    reader := strings.NewReader("<!DOCTYPE html><html><head><title>My First Heading</title></head><body><h1>My First Heading</h1><p>My first paragraph.</p></body></html>\n")

    htmlRes := convertapi.ConvDef("html", "txt",
        // Reading source file body from the io.Reader
        param.NewReader("file", reader, "page.html", nil),
    )

        fmt.Println("TXT file content:")

    // Copy the content of the reader to stdout.
    if _, err := io.Copy(os.Stdout, htmlRes); err != nil {
        log.Fatalf("failed to copy data: %s", err)
    }
}

Convert a Remote File

This example illustrates how to convert a remote file, eliminating the need for intermediate file storage. It's useful for automating the conversion of files available online without manual intervention.

Key Features:

  • Accepts a publicly accessible file URL as input.
  • Processes the file conversion without downloading it locally first.
  • Stores the converted file on the local machine
func main() {
	config.Default = config.NewDefault(os.Getenv("CONVERTAPI_TOKEN")) // Get your token at https://www.convertapi.com/a

	fmt.Println("Converting remote PPTX to PDF")
	pptxRes := convertapi.ConvDef("pptx", "pdf",
		param.NewString("file", "https://cdn.convertapi.com/public/files/demo.pptx"))

	if files, errs := pptxRes.ToPath("/tmp/converted.pdf"); errs == nil {
		fmt.Println("PDF file saved to: ", files[0].Name())
	} else {
		fmt.Println(errs)
	}
}

Parallel Conversions

The following example demonstrates how to perform multiple file conversions concurrently, leveraging Go's concurrency features to enhance performance. It is ideal for scenarios requiring the conversion of numerous files simultaneously, such as bulk processing tasks.

Key Features:

  • Initiates multiple conversions in parallel.
  • Utilizes goroutines and channels for efficient concurrency.
  • Reduces total processing time for batch conversions.
func main() {
	config.Default = config.NewDefault(os.Getenv("CONVERTAPI_TOKEN")) // Get your token at https://www.convertapi.com/a

	fmt.Println("Converting DOCX to PDF and JPG in parallel using same source file")
	fileParam := param.NewPath("file", "assets/test.docx", nil)
	pdfRes := convertapi.ConvDef("docx", "pdf", fileParam)
	jpgRes := convertapi.ConvDef("docx", "jpg", fileParam)

	// Downloading and saving files also in parallel
	c1 := save(pdfRes)
	c2 := save(jpgRes)
	<-c1
	<-c2
}

func save(res *convertapi.Result) (finish chan struct{}) {
	finish = make(chan struct{})
	go func() {
		defer close(finish)
		if files, errs := res.ToPath("/tmp"); errs == nil {
			fmt.Println("File saved to: ", files[0].Name())
		} else {
			fmt.Println(errs)
		}
	}()
	return
}

Conversion Workflows

The following example demonstrates a multi-step conversion process, such as converting a DOCX file to JPG and then compressing the JPG files into a ZIP archive, showcasing how to chain multiple conversions seamlessly.

Key Features:

  • Performs sequential conversions using intermediate results.
  • Manages multiple steps within a single process.
  • Outputs the final converted file after all transformations.
func main() {
	config.Default = config.NewDefault(os.Getenv("CONVERTAPI_TOKEN")) // Get your token at https://www.convertapi.com/a

	fmt.Println("Converting PDF to JPG and compressing result files with ZIP")

	jpgRes := convertapi.ConvDef("docx", "jpg", param.NewPath("file", "assets/test.docx", nil))

	zipRes := convertapi.ConvDef("jpg", "zip", param.NewResult("files", jpgRes, nil))

	if cost, err := jpgRes.Cost(); lib.PrintErr(err) {
		fmt.Println("DOCX -> JPG conversion cost: ", cost)
	}

	if files, err := jpgRes.Files(); lib.PrintErr(err) {
		fmt.Println("DOCX -> JPG conversion result file count: ", len(files))
	}

	if cost, err := zipRes.Cost(); lib.PrintErr(err) {
		fmt.Println("JPG -> ZIP conversion cost: ", cost)
	}

	if files, errs := zipRes.ToPath("/tmp/result.zip"); errs == nil {
		fmt.Println("ZIP file saved to: ", files[0].Name())
	} else {
		fmt.Println(errs)
	}
}

With our Go SDK, you can tap into a comprehensive set of over 500 document conversion and management capabilities - all neatly organized within one cohesive platform.

With our Go library, you can effortlessly handle documents sourced from URLs, file streams, or local paths, ensuring smooth integration with your existing environment. To optimize your workflow even further, consider employing conversion workflows that allow you to perform multiple, sequential transformations on the same document.

For detailed examples and advanced guidance, don’t forget to check our GitHub repository.

Take a look at Go code samples

View on GitHub

Automate Your Document Management using Go

Take control of your documents with our Go document management SDK. From basic conversions to full workflow automation, we provide the expertise and tools you need to manage your documents efficiently.

Enterprise-Grade Security

We ensure that all document processing is handled securely in the cloud, adhering to industry-leading standards like ISO 27001, GDPR, and HIPAA. To enhance security even further, we can ensure that no files or data are stored on our servers and never leave your country.

Learn more about security

Businesses trust us

Highest rated File Conversion API on major B2B software listing platforms: Capterra, G2, and Trustpilot.

"ConvertAPI has been a game-changer for our document automation workflows. Their conversion accuracy and API reliability are unmatched in the industry for over 7 years."

"ConvertAPI is a reliable, cost-effective solution with a proven track record of stability. It has grown significantly in maturity, adopting enterprise-grade practices over the years."

"We've integrated ConvertAPI across our entire document processing platform. The performance is exceptional and the support team is always responsive. Highly recommended!"

Frequently Asked Questions

How easy is it to integrate the Go SDK?

Whether you’re running monolithic apps or microservices, you can integrate it quickly by importing the library, setting your credentials, and invoking straightforward conversion methods. Its compatibility with standard Go tooling and package management ensures a smooth setup process.

Can I handle multiple conversions in parallel?

Yes. Taking advantage of ConvertAPI's concurrency model, you can process conversions concurrently with goroutines, significantly boosting throughput for large workloads. This makes it easier to scale your document processing and reduce overall execution time.

Are there specialized operations like redaction or OCR available?

Absolutely. In addition to standard conversions, the Go SDK supports advanced features such as redacting sensitive information and running OCR on scanned documents. These capabilities help consolidate various document workflows under one cohesive toolset.

How does the library perform with large documents?

The Go SDK is built for efficiency and robustness. It can handle big files and high volumes of conversions without sacrificing speed. You can also configure memory usage and file streaming options, ensuring consistent performance even under heavy loads.

Is it possible to chain multiple operations together?

Yes. You can create conversion workflows that apply a series of transformations to the same document. For example, you might convert a DOCX to PDF, apply protection, then compress the output, all within a single, orchestrated process.

Where can I find code examples and advanced configurations?

Our GitHub repository and official documentation include code samples and best practices for a range of use cases. These resources help you quickly experiment, learn, and refine your approach as you tailor the SDK to your project’s unique needs.

Try our Go library for free!