Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Insert text is not working #14

Open
jesseXu opened this issue May 22, 2019 · 7 comments
Open

Insert text is not working #14

jesseXu opened this issue May 22, 2019 · 7 comments

Comments

@jesseXu
Copy link

jesseXu commented May 22, 2019

That is my code below. However the text is not showing. The image is showing properly.
Any help? Thanks.

func main() {
	var pt pdft.PDFt
	err := pt.Open("abc.pdf")
	if err != nil {
		panic("Couldn't open pdf.")
	}

	err = pt.AddFont("arial", "./arial.ttf")
	if err != nil {
		fmt.Println(err)
		return
	}

	err = pt.SetFont("arial", "", 14)
	if err != nil {
		panic(err)
	}

	err = pt.Insert("Hello World", 1, 100, 100, 100, 100, gopdf.Center|gopdf.Bottom)
	if err != nil {
		panic(err)
	}

	//read image file
	// pic, err := ioutil.ReadFile("./testlb.png")
	// if err != nil {
	// 	panic("Couldn't read pic.")
	// }

	//insert image to pdf
	// err = pt.InsertImg(pic, 1, 100, 100, 172.0, 49.0)
	// if err != nil {
	// 	panic("Couldn't insert image")
	// }

	pt.Save("hello.pdf")
}
@plutov
Copy link

plutov commented Jun 4, 2019

I have the same issue @signintech

@plutov
Copy link

plutov commented Jun 4, 2019

@jesseXu I managed to add text to PDF, I had to fork this repo and fix few things:

  • Set RGB color, current repo doesn't support it
  • Repo uses font Index prefix as F, in my case I had to use TT

You can check changes here - https://github.com/plutov/pdft, but I am not going to create a PR, since current project is very limited, so my PR won't really help. It requires the major rewrite.

@swoldemi
Copy link

swoldemi commented Jun 4, 2019

@plutov I am also having issues getting things to behave as expected. Using your fork, though, my unit tests failed on an error: strconv.Atoi: parsing "F1": invalid syntax. Using the original source, my PDF opens with a warning that the file is corrupted. 🤔

@plutov
Copy link

plutov commented Jun 5, 2019

@swoldemi if you look into my commit history there are few places where I replaced F with TT to work with my PDF file. You can revert it back if your PDF file uses F. You can check it by opening PDF file raw data and look for /Font.

@swoldemi
Copy link

swoldemi commented Jun 5, 2019

@plutov Ah I see, thank you! (Btw, huge fan of your YouTube series)

@mikegleasonjr
Copy link

@signintech any news on this?

I will clone the repo and try to use the same font as you in the example but just downloading a times roman TTF off the Internet did not work for me as per the example in the readme.

@AndreRenaud
Copy link
Contributor

I had this same issue crop up. I resolved it with the following changes: https://github.com/signintech/pdft/pull/20/files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants