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

[BUG]: Not able to change text color of form fields in the PDF #558

Closed
pranavbansod opened this issue Jun 19, 2024 · 3 comments
Closed

[BUG]: Not able to change text color of form fields in the PDF #558

pranavbansod opened this issue Jun 19, 2024 · 3 comments
Labels
enhancement New feature or request feature New feature

Comments

@pranavbansod
Copy link

pranavbansod commented Jun 19, 2024

Description

Unidoc version: 3.57.0
I'm trying to fill pdf form from a json. I want to change text color of the new values which are filled from the Json.
Reference Code: https://github.com/unidoc/unipdf-examples/blob/master/forms/pdf_form_fill_json.go

	// NOTE: To customize certain styles try:
	// style := fieldAppearance.Style()
	// style.CheckmarkGlyph = "a22"
	// style.AutoFontSizeFraction = 0.70
	// fieldAppearance.SetStyle(style)
	//
	// or for specifying a full set of appearance styles:
	// fieldAppearance.SetStyle(annotator.AppearanceStyle{
	//     CheckmarkGlyph:       "a22",
	//     AutoFontSizeFraction: 0.70,
	//     FillColor:            model.NewPdfColorDeviceGray(0.8),
	//     BorderColor:          model.NewPdfColorDeviceRGB(1, 0, 0),
	//     BorderSize:           2.0,
	//     AllowMK:              false,
	// })

I'm trying to set FillColor of AppearanceStyle to change the color. But it is not changing.
I tried using different methods to change color

model.NewPdfColorDeviceGray(0.8)
model.NewPdfColorDeviceRGB(1, 0, 0)

The above methods I used are changing border color when set to BorderColor: model.NewPdfColorDeviceRGB(1, 0, 0).
But the same is not happening when I try to change text color.

Expected Behavior

It should change the text color.

Attachments

Here is the code snippet:

fieldAppearance.SetStyle(annotator.AppearanceStyle{
	CheckmarkGlyph:       "a22",
	AutoFontSizeFraction: 0.70,
	FillColor:            model.NewPdfColorDeviceGray(0.8),
	BorderColor:          model.NewPdfColorDeviceRGB(1, 0, 0),
	BorderSize:           2.0,
	AllowMK:              false,
})
Copy link

Welcome! Thanks for posting your first issue. The way things work here is that while customer issues are prioritized, other issues go into our backlog where they are assessed and fitted into the roadmap when suitable. If you need to get this done, consider buying a license which also enables you to use it in your commercial products. More information can be found on https://unidoc.io/

@kellemNegasi kellemNegasi added enhancement New feature or request feature New feature labels Jun 25, 2024
@kellemNegasi
Copy link

Hi @pranavbansod, Thank you for reporting this issue. Currently, there is no rich text support for form field values in UniPDF, which means this is a feature request. We have created a ticket for this, and we will implement it in the future. We will write an update on this issue as soon as the feature gets released.

@kellemNegasi
Copy link

Hi @pranavbansod , This feature has been implemented in Unipdf version v3.61.0.
You can choose a custom text color for text fields as follows.

        fieldAppearance := annotator.FieldAppearance{OnlyIfMissing: true, RegenerateTextFields: true}

	// specify a full set of appearance styles
	fieldAppearance.SetStyle(annotator.AppearanceStyle{
		AutoFontSizeFraction: 0.70,
		FillColor:            model.NewPdfColorDeviceRGB(1, 1, 1),
		BorderColor:          model.NewPdfColorDeviceRGB(0, 0, 0),
		BorderSize:           2.0,
		AllowMK:              false,
		TextColor:            model.NewPdfColorDeviceRGB(0.5, 0.8, 0.8), // text color as normalized RGB values
	})

	// Populate the form data with appearance.
	pdfReader.AcroForm.FillWithAppearance(fdata, fieldAppearance)

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

No branches or pull requests

2 participants