Example #1
0
func Page(pd *pdfread.PdfReaderT, page int) []byte {
	pg := pd.Pages()
	if page >= len(pg) {
		complain("Page does not exist!\n")
	}
	mbox := util.StringArray(pd.Arr(pd.Att("/MediaBox", pg[page])))
	drw := svgdraw.NewTestSvg()
	svgtext.New(pd, drw).Page = page
	w := strm.Mul(strm.Sub(mbox[2], mbox[0]), "1.25")
	h := strm.Mul(strm.Sub(mbox[3], mbox[1]), "1.25")
	drw.Write.Out(
		"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"+
			"<svg\n"+
			"   xmlns:svg=\"http://www.w3.org/2000/svg\"\n"+
			"   xmlns=\"http://www.w3.org/2000/svg\"\n"+
			"   version=\"1.0\"\n"+
			"   width=\"%s\"\n"+
			"   height=\"%s\">\n"+
			"<g transform=\"matrix(1.25,0,0,-1.25,%s,%s)\">\n",
		w, h,
		strm.Mul(mbox[0], "-1.25"),
		strm.Mul(mbox[3], "1.25"))
	cont := pd.ForcedArray(pd.Dic(pg[page])["/Contents"])
	_, ps := pd.DecodedStream(cont[0])
	drw.Interpret(fancy.SliceReader(ps))
	drw.Draw.CloseDrawing()
	drw.Write.Out("</g>\n</svg>\n")
	return drw.Write.Content
}
Example #2
0
func (t *SvgTextT) TShow(a []byte) {
	tx := t.Pdf.ForcedArray(a) // FIXME: Should be "ForcedSimpleArray()"
	for k := range tx {
		if tx[k][0] == '(' || tx[k][0] == '<' {
			part := space_split(ps.String(tx[k]))
			for y := range part {
				tmp, adv := t.Utf8Advance(part[y])
				res := strm.Add(t.x, adv)
				p := 0
				for len(tmp) > p && tmp[p] == 32 {
					p++
				}
				if p > 0 {
					_, ta := t.Utf8Advance(tmp[0:p])
					t.x = strm.Add(t.x, ta)
					tmp = tmp[p:]
				}
				t.Drw.Write.Out(
					"<g transform=\"matrix(%s,%s,%s,%s,%s,%s)\">\n"+
						"<text x=\"%s\" y=\"%s\""+
						" font-size=\"%s\""+
						" style=\"stroke:none;%v\""+
						" fill=\"%s\">%s</text>\n"+
						"</g>\n",
					t.matrix[0], t.matrix[1],
					strm.Neg(t.matrix[2]), strm.Neg(t.matrix[3]),
					t.matrix[4], t.matrix[5],
					t.x, t.y,
					t.Drw.TConfD.FontSize,
					t.Style(t.Drw.TConfD.Font),
					t.Drw.ConfigD.FillColor,
					util.ToXML(tmp))
				t.x = res
			}
		} else {
			t.x = strm.Sub(t.x, strm.Mul(string(tx[k]), "0.01"))
		}
	}
}
Example #3
0
func (t *SvgTextT) Utf8Advance(s []byte) ([]byte, string) {
	r, a := t.Utf8TsAdvance(s)
	return r, strm.Mul(t.Drw.TConfD.FontSize, strm.String(a, WIDTH_DENSITY))
}