Пример #1
0
// pd.Stream() returns contents of a stream.
func (pd *PdfReaderT) Stream(reference []byte) (DictionaryT, []byte) {
	q, d := pd.Resolve(reference)
	dic := pd.Dic(d)
	l := pd.Num(dic["/Length"])
	pd.rdr.Seek(int64(q), 0)
	t, _ := ps.Token(pd.rdr)
	if string(t) != "stream" {
		return nil, []byte{}
	}
	ps.SkipLE(pd.rdr)
	return dic, pd.rdr.Slice(l)
}
Пример #2
0
// xrefSkip() queries the start of the trailer for a (partial) xref-table.
func xrefSkip(f fancy.Reader, xref int) int {
	f.Seek(int64(xref), 0)
	t, p := ps.Token(f)
	if string(t) != "xref" {
		return -1
	}
	for {
		t, p = ps.Token(f)
		if t[0] < '0' || t[0] > '9' {
			f.Seek(p, 0)
			break
		}
		t, _ = ps.Token(f)
		ps.SkipLE(f)
		f.Seek(int64(num(t)*20), 1)
	}
	r, _ := f.Seek(0, 1)
	return int(r)
}
Пример #3
0
// xrefRead() reads the xref table(s) of a PDF file. This is not recursive
// in favour of not to have to keep track of already used starting points
// for xrefs.
func xrefRead(f fancy.Reader, p int) map[int]int {
	var back [MAX_PDF_UPDATES]int
	b := 0
	s := _Bytes
	for ok := true; ok; {
		back[b] = p
		b++
		p = xrefSkip(f, p)
		f.Seek(int64(p), 0)
		s, _ = ps.Token(f)
		if string(s) != "trailer" {
			return nil
		}
		s, _ = ps.Token(f)
		s, ok = Dictionary(s)["/Prev"]
		p = num(s)
	}
	r := make(map[int]int)
	for b != 0 {
		b--
		f.Seek(int64(back[b]), 0)
		ps.Token(f) // skip "xref"
		for {
			m := tupel(f, 2)
			if string(m[0]) == "trailer" {
				break
			}
			ps.SkipLE(f)
			o := num(m[0])
			dat := f.Slice(num(m[1]) * 20)
			for i := 0; i < len(dat); i += 20 {
				if dat[i+17] != 'n' {
					r[o] = 0, false
				} else {
					r[o] = num(dat[i : i+10])
				}
				o++
			}
		}
	}
	return r
}