Set export value of a new created checkbox with iText - pdf

I need to add a checkbox to an existing pdf. Also I need set the export value of this checkbox. I saw that this should be configurared with appearance dictionary /AP but till now I did evaluate how to set this on a new checkbox.
With export value I mean the value which is marked in the screenshot
Here is my code which creates a checkbox, but the export value is always empty...
case AcroFields.FIELD_TYPE_CHECKBOX:
PdfFormField checkbox = PdfFormField.createCheckBox(stamper.getWriter());
checkbox.setWidget(fieldVO.rect, PdfAnnotation.HIGHLIGHT_NONE);
checkbox.setFieldName(fieldVO.getNewName());
//TODO set export value
log.info("exportValue is " + fieldVO.getExportValue());
stamper.addAnnotation(checkbox, fieldVO.getPageNumber());
break;

First this: you are using PdfFormField to create a check box. That is hard. Why don't you use the RadioCheckField class?
rect = new Rectangle(180, 806, 200, 788);
checkbox = new RadioCheckField(stamper.getWriter(), rect,
"fieldVO.getNewName()", "on");
field = checkbox.getCheckField();
Then you want to define the appearances. Suppose that onOff is an array of PdfAppearance objects, one with the appearance if the box isn't selected (0) and one if the box is selected (1). Note that the name of the off state should be "Off" as defined in ISO-32000-1. As far as I remember, the standard recommends using "Yes" for the on state, but you can use a custom value, such as "MyCustomValue":
field.setAppearance(
PdfAnnotation.APPEARANCE_NORMAL, "Off", onOff[0]);
field.setAppearance(
PdfAnnotation.APPEARANCE_NORMAL, "MyCustomValue", onOff[1]);
In this case, the appearance of the on state will be stored as an entry with key /MyCustomValue. This key is a PDF name object and several restrictions apply. That's why the /Opt key was introduced:
(Taken from ISO-32000-1) Beginning with PDF 1.4, the field dictionary for check boxes and radio buttons may contain an optional Opt entry. If present, the Opt entry shall be an array of text strings representing the export value of each annotation in the field. It may be used for the following purposes:
To represent the export values of check box and radio button fields in non-Latin writing systems. Because name objects in the appearance dictionary are limited to PDFDocEncoding, they cannot represent non-Latin text.
To allow radio buttons or check boxes to be checked independently, even if they have the same export value.
EXAMPLE: a group of check boxes may be duplicated on more than one page such that the desired behavior is that when a user checks a box, the corresponding boxes on each of the other pages are also checked. In this case, each of the corresponding check boxes is a widget in the Kids array of a check box field.
In your case, you'd need something like:
PdfArray options = new PdfArray();
options.add(new PdfString("My Custom Value"));
field.put(PdfName.OPT, options);
I haven't tested if this works, I'm merely interpreting what ISO-32000-1 says and converting the spec into iText code.
Finally, you can add the field.
stamper.addAnnotation(field, 1);

Related

Setting Default Values to Drop Down in Orbeon Form Builder

I have a autocomplete field:
I need to set the default value selected for this dropdown using another control value as shown in:
This control is passed to the form load as shown in:
For example if use cost center is 110 as shown in:
Then the default selected value of the Site lookup dropdown needs to be as shown in:
The tricky part is that your Site-Item field isn't a dropdown but an autocomplete. An autocomplete doesn't know all the possible label/values, but can only find some label/values doing a search by label. So you can't tell an autocomplete "set your value to 110", because it doesn't know what the label corresponding to 110 is.
If you knew the label, you could do this programmatically with an fr-set-label, but here you don't have the label but the value. You can read more about this in the section Setting by value. So, my advice is to use a Dynamic Data Dropdown instead of an Autocomplete field.

Assign data to an item in a list?

I've set up a list that shows all available fonts. The issue I am having is assigning the actual font "data" to the list item itself so that, when clicked, it will apply that font to the textbox.
How would I go about doing this?
(I'm entirely new to this)
You don't need to, in your case. But if I interpret your question correctly..
What you can do is something like this:
myTextBox.Font = New Font(myListBox.SelectedItem, myTextBox.Font.Size)
This way, you'll be able to assign the font to the textbox based on your listbox's selected item, provided the listbox item IS the name of the font.

Office Addin Custom Attributes on Range Text

I would like to know if it's possible to add additional attributes to simple Range text or Paragraph text from my Word Add-in. For simplicity see code below where I can populate the document with text but additionally i would like to store additional but behind the scenes info along with that text. Ultimately I want these read these custom attributes using the Open Xml SDK when these documents go through a processing stage.
private void AddAttributedContent(string documentContent)
{
var doc = Globals.Factory.GetVstoObject(Globals.ThisAddIn.Application.ActiveDocument);
var range = doc.Range();
range.Font.Size = 12;
range.Font.Name = "Calibri";
range.Underline = Word.WdUnderline.wdUnderlineSingle;
range.Text = documentContent;
// range.AddOpenXmlProperty("MyProp", "MyValue");
var para = doc.Paragraphs.Add();
para.Range.Text = documentContent;
//para.AddCustomProperty("MyProp", "MyVal");
}
Edit:
Ideally our property would sit inside of the resulting RunProprties :
No, you can't do that. You could probably do it with a content control or a text box though.
For a ContentControl, you could probably use Tag (if this is like sources, it probably has to be unique, though the description seems to imply it's meant for the purpose you need) or Title.
The Tag property is different from the Title property in that a tag is never displayed while a user edits a document. Instead, developers can use it to store a value for programmatic manipulation while the document is opened.
For a text box (a Shape), you could use AlternativeText or Title.
Note that altering Title (in both cases) or AlternativeText will probably affect the way the document is displayed if you save it as HTML.

Difference between Combobox properties SelText and Text?

I don't quite understand the differences between the combobox properties SelText and Text.
If I want to send the content of a combobox as a parameter to another procedure, should I send .text or .selText?
If I want to make enter text into a combobox using a macro, should I write the text in .selText or .Text?
The difference is really given in the name (SelText vs. Text) where Sel stands for Selected. One is used to return or modify the selected text (i.e. SelText) and the other is used to return or modify the entire text (i.e. Text).
If no text is selected in the ComboBox then they return and modify the same value.
I suspect you want to use Text unless you are specifically interested in the selected text.
This appears to be consistent for an ActiveX control on a Worksheet or for a control on a User Form.

dijit.form.Combobox show label Instead of value

I've a dijit.form.Combobox field which uses a ItemFileReadStore to pull Its data.
Teh ItemFileReadStore has two attribute per Item value which will be used for form submission , generally Unique Integers and label which is Human Understandable String.
In ComboBox HTML I've done searchAttr="value" labelAttr="label"
When the ComboBox Shows the list it uses teh label Attribute.
But When the User selects one of the Item it shows the value of that Item.
What I want is , The value Attribute will Still be used for Form Submission. But the User will always see the label in the combobox Control.
alt text http://img822.imageshack.us/img822/6660/dijitcombo.jpg
e.g. I Want to Show The Label for value 3 (Admin) instead of 3
Use FilteringSelect instead of Combobox.
Note: ComboBox only has a single value that matches what is displayed while FilteringSelect incorporates a hidden value that corresponds to the displayed value.
I have tried the following.
var cmbObject = Registry.byId('combo dojo id'); var id =
cmbObject.item.<Code Property>;
You should check if item is null.