Git Product home page Git Product logo

go-pdfbox's Introduction

go-pdfbox

Go package for working with the pdfbox command line tool, with an embedded copy of the pdfbox jarfile.

Motivation

This is a simple Go "wrapper" package for working with the pdfbox command line tool. It contains an embedded copy of the pdfbox jar file but depends on a local copy of Java to run. The goal of the tool is to hide some of the details of working with pdfbox in a Go context but my hope is that eventually this package can be retired in favour of being able to invoke a WASM-compiled version of pdfbox. Until then this package exists.

Documentation

Go Reference

Example

Error handling has been removed for the sake of brevity.

Basic

import (
	"context"       
	"github.com/sfomuseum/go-pdfbox"
)

func main() {

     ctx := context.Background()
     p, _ := pdfbox.New(ctx, "pdfbox://")
     p.Execute(ctx, "ExtractText", "example.pdf", "example.txt")
}     

Use with io.Reader and io.Writer

import (
       	"bytes"
	"bufio"		
	"context"       
	"github.com/sfomuseum/go-pdfbox"
	"os"
)

func main() {

     ctx := context.Background()

     r, _ := os.Open("example.pdf")

     var buf bytes.Buffer
     wr := bufio.NewWriter(&buf)

     p, _ := pdfbox.New(ctx, "pdfbox://")
     
     p.ExecuteWithReaderAndWriter(ctx, r, wr, "ExtractText", pdfbox.READER, pdfbox.WRITER)
}     

Note the use of the pdfbox.READER and pdfbox.WRITER variables. They are placeholder strings used to swap in the name of the temporary files created using the io.Reader and io.Writer variables respectively. The order of input and output files in pdfbox is not constant so it's easier just to be explicit about things rather than try to guess at positional elements.

See also

go-pdfbox's People

Contributors

thisisaaronland avatar leowmjw 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.