pdfread

package module
v0.0.0-...-ba91185 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2016 License: MIT Imports: 7 Imported by: 0

README

go-pdfreader

Quick & Dirty copy of https://code.google.com/p/pdfreader/ to run under Go1.4

Example how to use it

package main

import (
	"github.com/1lann/go-pdfreader"
	"flag"
	"fmt"
	"path"
)

func main() {

	fileFlag := flag.String("file", "", "File to use")
	flag.Parse()

	if *fileFlag == "" {
		return
	}

	pd := pdfread.Load(*fileFlag)
	if pd != nil {
		pg := pd.Pages()
		fmt.Printf("        %s PagesCount=%d\n\n", path.Base(*fileFlag), len(pg))
		for k := range pg {
			fmt.Printf("Page %d - MediaBox: %s\n",
				k+1, pd.Att("/MediaBox", pg[k]))
			fonts := pd.PageFonts(pg[k])
			for l := range fonts {
				fontname := pd.Dic(fonts[l])["/BaseFont"]
				fmt.Printf("  %s = \"%s\"\n",
					l, fontname[1:])
			}

		}

	}
}

Documentation

Overview

Access to PDF files.

Index

Constants

View Source
const (
	MAX_PDF_UPDATES   = 1024
	MAX_PDF_ARRAYSIZE = 1024
)

Variables

This section is empty.

Functions

func Array

func Array(s []byte) [][]byte

Array() extracts an array from PDF data.

Types

type DictionaryT

type DictionaryT map[string][]byte

func Dictionary

func Dictionary(s []byte) DictionaryT

Dictionary() makes a map/hash from PDF dictionary data.

type PdfReaderT

type PdfReaderT struct {
	File string // name of the file

	Startxref int         // starting of xref table
	Xref      map[int]int // "pointers" of the xref table
	Trailer   DictionaryT // trailer dictionary of the file
	// contains filtered or unexported fields
}

func Load

func Load(fn string) *PdfReaderT

Load() loads a PDF file of a given name.

func (*PdfReaderT) Arr

func (pd *PdfReaderT) Arr(reference []byte) [][]byte

pd.Arr() queries array data from a reference.

func (*PdfReaderT) Att

func (pd *PdfReaderT) Att(a string, src []byte) []byte

pd.Att() tries to get an attribute from a page reference. The attribute will be resolved.

func (*PdfReaderT) Attribute

func (pd *PdfReaderT) Attribute(a string, src []byte) []byte

pd.Attribute() tries to get an attribute definition from a page reference. Note that the attribute definition is not resolved - so it's possible to get back a reference here.

func (*PdfReaderT) DecodedStream

func (pd *PdfReaderT) DecodedStream(reference []byte) (DictionaryT, []byte)

pd.DecodedStream() returns decoded contents of a stream.

func (*PdfReaderT) Dic

func (pd *PdfReaderT) Dic(reference []byte) DictionaryT

pd.Dic() queries dictionary data from a reference.

func (*PdfReaderT) ForcedArray

func (pd *PdfReaderT) ForcedArray(reference []byte) [][]byte

pd.ForcedArray() queries array data. If reference does not refer to an array, reference is taken as element of the returned array.

func (*PdfReaderT) Num

func (pd *PdfReaderT) Num(reference []byte) int

pd.Num() queries integer data from a reference.

func (*PdfReaderT) Obj

func (pd *PdfReaderT) Obj(reference []byte) []byte

pd.Obj() is the universal method to access contents of PDF objects or data tokens in i.e. dictionaries. For reading streams you'll have to utilize pd.Resolve().

func (*PdfReaderT) PageFonts

func (pd *PdfReaderT) PageFonts(page []byte) DictionaryT

pd.PageFonts() returns references to the fonts defined for a page.

func (*PdfReaderT) Pages

func (pd *PdfReaderT) Pages() [][]byte

pd.Pages() returns an array with references to the pages of the PDF.

func (*PdfReaderT) Resolve

func (pd *PdfReaderT) Resolve(s []byte) (int, []byte)

pd.Resolve() resolves a reference in the PDF file. You'll probably need this method for reading streams only.

func (*PdfReaderT) Stream

func (pd *PdfReaderT) Stream(reference []byte) (DictionaryT, []byte)

pd.Stream() returns contents of a stream.

Directories

Path Synopsis
Character Mappings (cmap).
Character Mappings (cmap).
HTTP-server example.
HTTP-server example.
"crush" bytes into bits - variable length.
"crush" bytes into bits - variable length.
Enhanced input.
Enhanced input.
hex encoder/decoder for PDF.
hex encoder/decoder for PDF.
LZW decoder for PDF.
LZW decoder for PDF.
Decoder for pfb fonts.
Decoder for pfb fonts.
PS top-down parser.
PS top-down parser.
Stacks of different types.
Stacks of different types.
string math
string math
Library to convert PDF pages to SVG.
Library to convert PDF pages to SVG.
SVG driver for graf.go.
SVG driver for graf.go.
SVG driver (text) for graf.go.
SVG driver (text) for graf.go.
Some utilities.
Some utilities.
Encode UTF-8.
Encode UTF-8.

Jump to

Keyboard shortcuts

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