<commit_before>package test

import (
	"encoding/base64"
	"io/ioutil"
	"os"
	"testing"

	_ "image/png"

	"github.com/signintech/pdft"
)

func TestInsertImg(t *testing.T) {

	//source := "./pdf/pdf_from_docx_with_f.pdf"
	source := "./pdf/pdf_from_docx.pdf"
	//source := "./pdf/pdf_from_gopdf.pdf"
	//signature := "./img/gopher.png"
	signature := "./img/gopher2.jpg"
	target := "./out/pdf_from_docx_out.pdf"

	var ipdf pdft.PDFt
	err := ipdf.Open(source)
	if err != nil {
		t.Error("Couldn't open pdf.")
	}

	encoded, data, err := readImg(signature)
	if err != nil {
		t.Error("Couldn't read image")
	}

	/*err = ipdf.InsertImgBase64(encoded, 1, 100, 200, 100, 100)
	if err != nil {
		t.Error("Couldn't insert image base64")
	}

	*/
	_ = data
	_ = encoded
	err = ipdf.InsertImg(data, 1, 100.0, 100.0, 100, 100)
	if err != nil {
		t.Error("Couldn't insert image")
	}

	err = ipdf.Save(target)
	if err != nil {
		t.Error("Couldn't save pdf.")
	}
}

func readImg(path string) (string, []byte, error) {<commit_msg>add test case<commit_after>package test

import (
	"encoding/base64"
	"io/ioutil"
	"os"
	"testing"

	_ "image/png"

	"github.com/signintech/pdft"
)

func TestInsertImgDocx(t *testing.T) {
	testWriteImg(t, "./pdf/pdf_from_docx.pdf", "./out/pdf_from_docx_out.pdf")
}

func TestInsertImgChromePdf(t *testing.T) {
	testWriteImg(t, "./pdf/pdf_from_chrome_50_linux64.pdf", "./out/pdf_from_chrome_50_linux64_out.pdf")
}

func testWriteImg(t *testing.T, source string, target string) {
	//source := "./pdf/pdf_from_docx_with_f.pdf"
	//source := "./pdf/pdf_from_gopdf.pdf"
	//signature := "./img/gopher.png"
	signature := "./img/gopher2.jpg"

	var ipdf pdft.PDFt
	err := ipdf.Open(source)
	if err != nil {
		t.Error("Couldn't open pdf.")
		return
	}

	encoded, data, err := readImg(signature)
	if err != nil {
		t.Error("Couldn't read image")
		return
	}

	/*err = ipdf.InsertImgBase64(encoded, 1, 100, 200, 100, 100)
	if err != nil {
		t.Error("Couldn't insert image base64")
	}

	*/
	_ = data
	_ = encoded
	err = ipdf.InsertImg(data, 1, 100.0, 100.0, 100, 100)
	if err != nil {
		t.Errorf("Couldn't insert image %+v", err)
		return
	}

	err = ipdf.Save(target)
	if err != nil {
		t.Errorf("Couldn't save pdf. %+v", err)
		return
	}
}

func readImg(path string) (string, []byte, error) {
{'fraction_non_alphanumeric': 0.17839965019676432, 'fraction_numerical': 0.034105815478793176, 'mean_word_length': 3.557768924302789, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3359979', 'n_tokens_mistral': 1051, 'n_tokens_neox': 949, 'n_words': 198}