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.
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
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).
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:
publicstaticvoidColorFields(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));
}
}
publicstatic 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
}
}
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.
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