Ejemplo n.º 1
0
func (pdf *PDF) AddPageLabel(
	pageNum uint, pageNumStyle PageNumStyle, firstPage uint, prefix string,
) error {
	cprefix := C.CString(prefix)
	C.HPDF_AddPageLabel(
		pdf.doc,
		C.HPDF_UINT(pageNum),
		C.HPDF_PageNumStyle(pageNumStyle),
		C.HPDF_UINT(firstPage),
		cprefix,
	)
	C.free(unsafe.Pointer(cprefix))
	return nil
}
Ejemplo n.º 2
0
func (encoder *Encoder) GetByteType(text string, index uint) ByteType {
	ctext := C.CString(text)
	defer C.free(unsafe.Pointer(ctext))

	return ByteType(
		C.HPDF_Encoder_GetByteType(encoder.encoder, ctext, C.HPDF_UINT(index)),
	)
}
Ejemplo n.º 3
0
func (pdf *PDF) LoadRawImageFromFile(
	filename string, width, height uint32, colorSpace ColorSpace,
) (*Image, error) {
	cfilename := C.CString(filename)
	cimage := C.HPDF_LoadRawImageFromFile(
		pdf.doc, cfilename,
		C.HPDF_UINT(width), C.HPDF_UINT(height),
		C.HPDF_ColorSpace(colorSpace),
	)
	C.free(unsafe.Pointer(cfilename))

	if cimage != nil {
		return newImage(cimage, pdf), nil
	} else {
		return nil, pdf.GetLastError()
	}
}
Ejemplo n.º 4
0
func (pdf *PDF) LoadPngImageFromMem(mem []byte) (*Image, error) {
	ptr := (*C.HPDF_BYTE)((unsafe.Pointer(&mem[0])))
	cimage := C.HPDF_LoadPngImageFromMem(pdf.doc, ptr, C.HPDF_UINT(uint32(len(mem))))

	if cimage != nil {
		return newImage(cimage, pdf), nil
	} else {
		return nil, pdf.GetLastError()
	}
}
Ejemplo n.º 5
0
func (pdf *PDF) LoadRawImageFromMem(
	mem []byte,
	width uint32,
	height uint32,
	colorSpace ColorSpace,
	bitsPerComponent uint32,
) (*Image, error) {
	ptr := (*C.HPDF_BYTE)((unsafe.Pointer(&mem[0])))
	cimage := C.HPDF_LoadRawImageFromMem(
		pdf.doc,
		ptr,
		C.HPDF_UINT(width),
		C.HPDF_UINT(height),
		C.HPDF_ColorSpace(colorSpace),
		C.HPDF_UINT(bitsPerComponent),
	)

	if cimage != nil {
		return newImage(cimage, pdf), nil
	} else {
		return nil, pdf.GetLastError()
	}
}
Ejemplo n.º 6
0
func (pdf *PDF) LoadTTFontFromFile2(fontName string, index uint, embedding bool) (string, error) {
	cfontName := C.CString(fontName)
	var cembedding C.HPDF_BOOL = C.HPDF_TRUE
	if !embedding {
		cembedding = C.HPDF_FALSE
	}
	retFontName := C.HPDF_LoadTTFontFromFile2(pdf.doc, cfontName, C.HPDF_UINT(index), cembedding)
	C.free(unsafe.Pointer(cfontName))

	if retFontName != nil {
		return C.GoString(retFontName), nil
	} else {
		return "", pdf.GetLastError()
	}
}
Ejemplo n.º 7
0
func (image *Image) SetColorMask(
	rmin, rmax, gmin, gmax, bmin, bmax uint32,
) error {
	C.HPDF_Image_SetColorMask(
		image.image,
		C.HPDF_UINT(rmin), C.HPDF_UINT(rmin),
		C.HPDF_UINT(gmin), C.HPDF_UINT(gmin),
		C.HPDF_UINT(bmin), C.HPDF_UINT(bmin),
	)
	return image.pdf.GetLastError()
}
Ejemplo n.º 8
0
func (pdf *PDF) SetPagesConfiguration(page_per_pages uint) error {
	C.HPDF_SetPagesConfiguration(pdf.doc, C.HPDF_UINT(page_per_pages))
	return pdf.GetLastError()
}
Ejemplo n.º 9
0
func (pdf *PDF) SetCompressionMode(compressionMode CompressionMode) error {
	C.HPDF_SetCompressionMode(pdf.doc, C.HPDF_UINT(compressionMode))
	return pdf.GetLastError()
}
Ejemplo n.º 10
0
func (pdf *PDF) SetEncryptMode(encryptMode EncryptMode, keyLen uint32) error {
	C.HPDF_SetEncryptionMode(
		pdf.doc, C.HPDF_EncryptMode(encryptMode), C.HPDF_UINT(keyLen),
	)
	return pdf.GetLastError()
}
Ejemplo n.º 11
0
func (pdf *PDF) SetPermission(permission Permission) error {
	C.HPDF_SetPermission(pdf.doc, C.HPDF_UINT(permission))
	return pdf.GetLastError()
}