gofpdf icon indicating copy to clipboard operation
gofpdf copied to clipboard

How to add editable cell?

Open lexrus opened this issue 8 years ago • 7 comments

I'd like to add some editable fields in my generated PDF with gofpdf. Make them editable in Safari or Chrome as the following screenshot. How can I do that? screen shot 2016-11-08 at 2 33 27 pm

I've already set protection:

pdf.SetProtection(gofpdf.CnProtectPrint|gofpdf.CnProtectCopy|gofpdf.CnProtectModify, "", "")

lexrus avatar Nov 08 '16 06:11 lexrus

gofpdf does not currently support editable form fields. Fpdf (from which gofpdf is derived) has the following script: Form filling. Is that the kind of functionality you are after?

jung-kurt avatar Nov 08 '16 13:11 jung-kurt

It's called AcroForms (a.k.a. Acrobat Forms) for PDF. I just found a browser-side JS lib which has a plugin for adding textfield/radio/button in PDF: https://github.com/MrRio/jsPDF/blob/master/plugins/acroform.js

lexrus avatar Nov 08 '16 15:11 lexrus

Thanks, @lexrus, for the link. I'll label this issue as an enhancement and with luck find some time to work on it. If you're up to the task, it would make a great pull request!

jung-kurt avatar Nov 09 '16 15:11 jung-kurt

Hello, and thank you for providing a useful tool for the go community!

Just curious if you have any plans to implement editable fields in gofpdf? It would be awesome to generate forms that can be filled out digitally rather than just when printed :)

thanks again!

dhalman avatar Jun 14 '18 23:06 dhalman

I agree, this would be a very welcome enhancement. I have not had time to pursue this, but I continue to hope that someone will implement this.

jung-kurt avatar Jun 16 '18 18:06 jung-kurt

I could attempt a PR with the feature, but I may need some guidance in where to start?

dhalman avatar Jun 16 '18 21:06 dhalman

Thanks for your interest, @dhalman!

Rather than extending fpdf.go directly, the best approach is to create a new file that contains the extension logic. See layer.go as an example, and notice that it includes methods like layerPutCatalog and layerPutResourceDict to reduce the changes in fpdf.go to some method calls. You may need to add some fields to the Fpdf type; do this is def.go.

Most of the functionality in gofpdf is ported from the fpdf PHP package. It may be that editable field support can come from there as well. The form filling script may be a good start.

Once you get things working, one or more examples in fpdf_test.go provide test coverage and are a real help for people using your extension.

Good luck and don't hesitate to ask questions here along the way.

jung-kurt avatar Jun 16 '18 22:06 jung-kurt