How do I get the pdf viewer to show me the textfields?

1 Answer 44 Views
PDFViewer
Dominik
Top achievements
Rank 1
Iron
Iron
Dominik asked on 12 Oct 2023, 01:30 PM | edited on 16 Oct 2023, 08:20 AM

The Fields in my pdf viewer are all collored white and they are not getting highlighted. As seen in example.png. I want to have the same behavior as in the example2.png.

 

Thanks for the help

Dimitar
Telerik team
commented on 13 Oct 2023, 05:47 AM

Hi Dominic, 

How are you creating this document? Would it be possible to attach it here so we ca examine it? 

Thank you in advance for your patience and cooperation. 

Dominik
Top achievements
Rank 1
Iron
Iron
commented on 13 Oct 2023, 08:45 AM | edited

Hey Dimitar,

Yeah i can proviede them for you: https://easyupload.io/m/etkkyd

there is for one the pdf im importing them through the path with: new PdfDocumentSource(new Uri(filePath)); and then just let it show in the RadPdfViewer with pdfViewer.DocumentSource = mPdfDocumentSource;

The other file is a custom xml where there are fields with numbers to get Data from the database and at the top where is <File Encoding="Base64"> there is the pdffile with base64 encoding. The base 64 and the fields I am parsing the fields for the database and the pdf so ican use the telerik methodes at first

RadFixedDocument document = provider.Import(parseResult.PdfData.Span.ToArray());

Then im Iterating throught the fields in the pdf and set the field with the data from my database:

foreach (FormField formField in document.AcroForm.FormFields)
{
string fieldName = formField.Name;

// Check if it's a TextBox field and fill its value
if (formField is TextBoxField)
{
TextBoxField textBox = formField as TextBoxField;

if (textBox.Name == data[counter].Key)
{
textBox.Value = data[counter].Value;
}

 

after that im using the telerik export and convert it to a memory stream to make it usable for the new PdfDocumentSource(memorystream):

PdfFormatProvider provider = new PdfFormatProvider();

return provider.Export(document);

 

Hope that helps und you understand what im doing its a litle complicated but i have to work with the technology given to me.

 

thanks


1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 16 Oct 2023, 11:32 AM

Hello Dominik,

I was able to reproduce this and indeed it can be better handled in our control. I have logged this for improvement on your behalf. You can track its progress, subscribe to status changes, and add your comment to it here: PdfViewer: Provide a default appearance for fields that do not contain one.

As a workaround, I can suggest manually adding this:

var provider = new PdfFormatProvider();
var document = provider.Import(File.ReadAllBytes(@"..\..\..\Systemvariablen.pdf"));

foreach (var item in document.AcroForm.FormFields)
{ 
    var widget = item.Widgets.First() as VariableContentWidget;
     
    if (widget != null)
    { 
        widget.AppearanceCharacteristics.Background = new RgbColor(255, 0, 0);
        widget.AppearanceCharacteristics.BorderColor = new RgbColor(0, 0, 255);
        widget.Border = new AnnotationBorder(2, AnnotationBorderStyle.Solid, null);
      
        widget.RecalculateContent(); 
    }
}

pdfViewer.Document = document;

In addition, you can directly set the document without using PdfDocumetnSource (check the above snippet).

Let me know if I can assist you further.

Regards,
Dimitar
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Dominik
Top achievements
Rank 1
Iron
Iron
commented on 16 Oct 2023, 01:11 PM

Yeah it works thanks for the help
Dominik
Top achievements
Rank 1
Iron
Iron
commented on 27 Oct 2023, 09:56 AM | edited

Hey,

it does work and i added a twostatswidget (Combobox, Checkbox) for the checkbox it works as intendet but for the combobox it only collors the first (see in screenshot) one I might missed something where you need to loop through the combobox.

Here is the code i use to color:

public static void ColorFields(RadFixedDocument doc) // MAKE IT A Own Class
{
	foreach (var item in doc.AcroForm.FormFields)
	{
		var widget = item.Widgets.First();

		ColorSingleField(widget, new RgbColor(0, 0, 0), new RgbColor(64, 0, 0, 0));
	}
}

public static Widget ColorSingleField(Widget widget, RgbColor rgbBorderColor, RgbColor rgbBackgroundColor) // MAKE IT A Own Class
{
	//ÌNFO WIDGET HAT AppearanceCharacteristics aber funktioniert trozudem nur wenn man genau deffiniert welches es ist mit "as"
	if (widget.WidgetContentType == WidgetContentType.VariableContent)
	{
		var widgetVarContent = widget as VariableContentWidget;

		//Funktioniert nur bei TextField & Checkboxen nicht bei ComboBox (Es wird nur die erste Combobox eingefärbt und nicht alle) 


		widgetVarContent.AppearanceCharacteristics.Background = rgbBackgroundColor;
		widgetVarContent.AppearanceCharacteristics.BorderColor = rgbBorderColor;

		widgetVarContent.Border = new AnnotationBorder(1, AnnotationBorderStyle.Inset, null);

		widgetVarContent.RecalculateContent();
	}

	if (widget.WidgetContentType == WidgetContentType.TwoStatesContent)
	{
		var widgetTwoStates = widget as TwoStatesButtonWidget;

		//Funktioniert nur bei TextField & Checkboxen nicht bei ComboBox (Es wird nur die erste Combobox eingefärbt und nicht alle) 

		widgetTwoStates.AppearanceCharacteristics.Background = rgbBackgroundColor;
		widgetTwoStates.AppearanceCharacteristics.BorderColor = rgbBorderColor;

		widgetTwoStates.Border = new AnnotationBorder(1, AnnotationBorderStyle.Inset, null);
		widgetTwoStates.RecalculateContent();
	}

	return widget;
}

Dimitar
Telerik team
commented on 01 Nov 2023, 06:06 AM

Hi Dominik, 

Without having the document I cannot say be sure why this happens. However, the field may have more than one widget and you can try iterating them as well: 

foreach (var item in document.AcroForm.FormFields)
{ 
    foreach (var widget in item.Widgets)
    {
        //set appearance
    } 
}

Let me know if I can assist you further.

 

Tags
PDFViewer
Asked by
Dominik
Top achievements
Rank 1
Iron
Iron
Answers by
Dimitar
Telerik team
Share this question
or