pdftables

package module
v0.0.0-...-23f2a37 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2016 License: MIT Imports: 10 Imported by: 0

README

pdftables-go

Go Report Card GoDoc Reference

pdftables-go is an SDK for using PDFTables' API in your Go application. PDFTables automates extraction of data from PDF files.

Install

go get github.com/hasit/pdftables-go

Usage

In order to get started with making your Go application that uses the PDFTables' API, you will need to register first. Upon successful registration, you will be provided with an API key.

Go ahead and save it somewhere. I propose that you create an environment variable for easy retrieval. Since I use fish, here is how you can create a global environment variable in fish shell. Finding a way to do the same in other shells is simply a matter of searching a little.

set -xg PDFTABLES_APIKEY <your-api-key>

Make sure you restart your terminal or reload your shell before you go forward.

Don't worry about losing it; you can easily find your API key on the API Documentation page.

Next step is to create a new Go program and import this library.

package main

import "github.com/hasit/pdftables-go"
...

Now we will create a new client with the recently saved API key.

...
func main()  {
  apikey := os.Getenv("PDFTABLES_APIKEY")
  p := pdftables.NewClient(apikey)
}
...
Convert PDF File
...
func main() {
	apikey := os.Getenv("PDFTABLES_APIKEY")
	p := pdftables.NewClient(apikey)
	path, err := filepath.Abs("examples/test.pdf")
	if err != nil {
		log.Fatal(err)
	}
	err = p.Convert(path, pdftables.FormatCSV)
	if err != nil {
		log.Fatal(err)
	}
}
Supported Formats
Format pdftables-go const name
CSV pdftables.FormatCSV
XML pdftables.FormatXML
XLSX pdftables.FormatXLSXSingle, pdftables.FormatXLSXMultiple

Read the Formats section for more information on formats and how xlsx-single and xlsx-multiple differ.

Get Remaining Balance
...
func main()  {
  apikey := os.Getenv("PDFTABLES_APIKEY")
	p := pdftables.NewClient(apikey)
	balance, err := p.GetBalance()
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(balance)
}

Contribute

Feel free to ask questions, post issues and open pull requests. My only requirement is that you run gofmt on your code before you send in a PR.

Documentation

Index

Constants

View Source
const (
	// FormatCSV sets the document to be returned in Comma Separated Values, blank row between pages.
	FormatCSV = "csv"
	// FormatXML sets the document to be returned in HTML <table> tags; <td> tags may have colspan= attributes.
	FormatXML = "xml"
	// FormatXLSXSingle sets the document to be returned in Excel, all PDF pages on one sheet, blank row between pages.
	FormatXLSXSingle = "xlsx-single"
	// FormatXLSXMultiple sets the document to be returned in Excel, one sheet per page of the PDF.
	FormatXLSXMultiple = "xlsx-multiple"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	Message string `json:"message"`
	Code    int    `json:"code"`
}

Error defines an error received when making a request to the API.

func (Error) Error

func (e Error) Error() string

Error returns a string representing the error, satisfying the error interface.

type PDFTables

type PDFTables struct {
	APIKey string
	Host   string
}

PDFTables defines a new client for making API calls.

func NewClient

func NewClient(apikey string) *PDFTables

NewClient returns a new PDFTables API client which can be used to make requests.

func (*PDFTables) Convert

func (p *PDFTables) Convert(file, format string) error

Convert extracts data from PDF file by calling PDFTables API into supported formats. Supported formats are CSV, XML, XLSX. Returns nil error and creates a file in specified format in the same directory as the PDF file. Upon error (err != nil), no file will be created and appropriate error message will be returned. Example: examples/convert.go Note: `file` parameter only accepts abosulte file path.

func (*PDFTables) GetBalance

func (p *PDFTables) GetBalance() (int, error)

GetBalance gets the number of remaining pages. Returns number of pages (integer) and error. Upon error (err != nil), balance returned will be -1 along with appropriate error message. Example: examples/getbalance.go

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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