I am experimenting with Essential Objects' EO.PDF component for .NET
and can't find a way to "check" a checkbox in an existing PDF document.
I have posted to the EO forum already, but I think that it may not be a vendor specific issue.
// I've tried 'Yes', 'On', 'True', and even 'X'
// but it does not show a tick in the output PDF.
doc.Fields["chk1"].Value = "???";
Please guide me.
I have not used EssentialObjects' EO.PDF personally, but according to the documentation there seem to be two ways to set it: you can either set the Value property to "1", or set the boolean Checked property to true. (I think you'd have to cast the field to a PdfCheckBoxField to use the latter method.)
Related
I'm trying check a checkbox on my PDF with iText7.
But instead of checking only one field, it's checking all fields
What I need:
What I get:
PDF when editing:
I think the exported value has something to do with it.
But I don't kown what to do.
My code:
private static void CreatePdf(string output)
{
using var _pdfDoc = new PdfDocument(new PdfReader("CheckTest.pdf"), new PdfWriter(output));
var form = PdfAcroForm.GetAcroForm(_pdfDoc, true);
var check = form.GetField("Check");
check.SetValue("01");
}
PDF: Link
Someone know how to check it properly?
Thanks!
First of all, the PDF essentially mis-uses PDF AcroForm check box fields as radio buttons instead of using genuine PDF AcroForm radio button fields.
The PDF specification does not clearly specify what a PDF viewer should do in such a case (it's mis-use after all) but the developers of the PDF form generator in question probably have experimented and determined that in the most widely used PDF viewer, Adobe Acrobat Reader, this mis-use works just as they want.
As this use is beyond specification, though, other PDF processors processing such PDFs may produce completely different results without doing anything wrong.
That being said, there is a way to fill the form using iText and achieve results similar to those generated by Adobe Reader.
The problem at hand is that iText by default for all form field types except actual AcroForm radio button fields generates new appearances in a way appropriate for the field type when setting the field value. In your document there are three check box field objects with the same name. Thus, they are considered a single check box with three widgets representing the same value, and so the appearances are generated as you observe.
But you can tell iText to not generate new appearances, using another SetValue overload accepting an additional boolean value, simply replace
check.SetValue("01");
by
check.SetValue("01", false);
Now iText makes do with the existing appearances, so only the field becomes checked that has an appearance for that "01" value.
Beware, only prevent iText from generating appearances in cases like this. In case of text fields, for example, not updating the appearances would cause the old appearances with the former field content to continue to be displayed even though the internal field value changed.
A did it like this:
Dim MyPDFFormCheckBoxField As Fields.PdfFormField = myform.GetField("myCheckBox")
MyPDFFormCheckBoxField.SetCheckType(PdfFormField.TYPE_CHECK)
MyPDFFormCheckBoxField.SetValue("", If(myCheckBox.IsChecked = True, True, False))
Notice that it is the second parameter of SetValue that is setting the checkbox True or False.
[Short Question] :
How can I Cast or Convert a PowerPoint.TextRange to a Word.Range ?
[Longer description ] :
I'm trying to mark a selected text range as "Do Not Check Spelling",
in PowerPoint 2013, from my code. It's a PowerPoint Add-In written in C#,
but I could adapt it from any other sample in other language (VBA, VB, PowerShell...)
Of course doing it manually with the Review, Language Settings is working perfectly.
My code gets the selected range in a Microsoft.Office.Interop.PowerPoint.TextRange
read from Globals.ThisAddIn.Application.ActiveWindow.Selection.TextRange;
(I've also started some tests with a Microsoft.Office.Core.TextRange2)
These objects contain a LanguageID property. Setting it to msoLanguageIDNoProofing is ignored (other real languages work, though). It seems coherent with the GUI display, where there are two properties, the selected language and a separate checkbox to disable the Spell Check.
I've displayed the TextRange properties for two similar ranges, one with the "Do Not Check Spelling" setting set manually... and it seems there's not an evident difference on them.
So I found by chance the Microsoft.Office.Interop.Word.Range object.
It contains both the LanguageID, and a separate NoProofing property...
so probably PowerPoint is using this Word object when editing Ranges.
My question is, how can I Cast or Convert the Powerpoint.TextRange to a Word.Range ?
These are entirely different objects. There is no direct conversion between these types. You can copy property values from one and set them on another. Or just use the Copy/Paste operations programmatically.
I want to set value to the Test Variable using Custom Code.
Can you tell me how to do it as i am not able to access the variable from code.
I need to access the User Variable URL in my custom code and set the value.
Please help me if you know how to do it using Custom Code.
Thanks,
Madhan
Based on your question:
1. Click on File menu and then Settings, it will open Properties pane.
2. Click on "+" to add user variable and give a name.
3. In your custom code, type below code:
string s = "https://www.google.com/";
this.Context.TestProfile.SetVariableValue("NameOfYourVariable",s);
To retrieve the value of given variable:
string ss = this.Context.TestProfile.GetVariableValue("NameOfYourVariable");
CodeActivity5.Report("Variable is : ", ss); //(This line will print your variable value)
answer provided here is valid when the need is to set string values. The "SetVariableValue" method takes two "String" type parameters. This limits the ability to set Int32 type variables. Obviously, C# throws an error when trying to set an integer value.
Now, an integer value is particularly useful while setting values for loop iterations. I am not sure whether this is a limitation of the tool or whether my lack of knowledge. So, to work around this, i used the output property of custom code activity. To do this, create a custom code activity and create an output property of the desired type, say Int. Now, assign a value to this output property using the line:
this.ActivityName.Output.property name = property value
This is available in UFT help and can be useful while trying to pass values other than string between different activities in a flow.
Basically, I have my DOM objects set up and am calling the .getAttribute method on an IMG element that is defined as below:
<IMG style="WIDTH: 134px; HEIGHT: 75px;" src="...">
Assuming hElement is the object reference to above element, when I call the following:
MsgBox hElement.getAttribute("style")
I get the following returned: "WIDTH" only, ie: part including and after the : character is ignored. To add to this, if I do a hElement.getAttribute("width") on the IMG element, it returns the actual width as "134" even though I don't explicitely have a width="..." attribute defined. So, basically, I am asking, how can I ensure I get back things as they are written, and not as they are reconstructed and stored by IE, as that is what it seems to be doing with the inferred WIDTH attribute. Also, not sure why it is ignoring everything including and after the : character right next to the WIDTH - how can I make this work properly?
Odd thing is, if I do the following, it shows everything as it should be:
hElement.outerHTML
The style attribute's value is shown as defined above. If I have to parse .outerHTML in order to get correct readings, that is just going to be depressing - I'm really disappointed in MS's half baked efforts. If you're looking for something extra to read, feel free to refer to another issue I noted about attributes returning odd behaviour when using capitals and when not (solved through a hack).
I'm using VB6, but it is all just the same, mshtml.dll, I gather, I am using IHTMLElement to define the hElement, not sure if I should be using something else but I think IHTMLElement is good for IE6+...?
UPDATE:
If I declare the hElement as IHTMLElement5 or IHTMLElement6 then it WORKS AS EXPECTED. If I use any of the following, it doesn't work: IHTMLElement, IHTMLElement2, IHTMLElement3 and IHTMLElement4. Since it only goes up to 6, only 5 & 6 work. It seems as though these are added later for newer versions of IE, and although you don't see the .getAttribute object in intellisense in 2 and above, you can still use it for some reason (not sure if its based on what IE version is installed). Does anyone know what version of IE IHTMLElement5 and IHTMLElement6 stands for? How can I get consistent behaviour for IE6+ as I don't have control on what versions are installed on the clients. If I use IHTMLElement5 or IHTMLElement6 does this mean it will not work on IE6 clients?
More:
Turns out IHTMLElement5 is for IE8+ and IHTMLElement6 is for IE9+ - any ideas or recommendations on how to get consistent behaviour for IE6+? Thanks.
UPDATE2: I have added a new question, which spawns from this question, it can be found here for those interested:
What happens when using IHTMLElement5/6 (for IE8/9) in IE6/7? Does it divert to IHTMLElement behaviour?
You might wanna take a look at this http://robertnyman.com/2006/04/24/get-the-rendered-style-of-an-element/
SO in your case you should try using the cssText property which will return a string consisting of all the css properties
hElement.style.cssText
Flags are not supported anymore? http://msdn.microsoft.com/en-us/library/ms536429%28v=vs.85%29.aspx
However, this works:
styleContent=hElement.style.cssText;
It seems, that getAttribute('style') returns an object instead of the value of the attribute, since the code below works too.
styleContent=hElement.getAttribute('style').cssText;
Suppose i have some value in excel cell,its type may be anything date,numeric or string
and i want that cell to be validated against its type...
Is there any way of doing this ?
thanks in advance..
I assume you mean that you have contents in a cell, which could be either a date, a double, or a plain string, and that you want to assert what corresponding .NET type it is. I believe there is no direct way of doing this. One approach would be to retrieve the Value2 in the cell, and try to cast it to each of these types, starting from the most restrictive one, until the cast works - i.e. DateTime (DateTime.FromOADate), then double (Convert.ToDouble), then string - and then apply the validation rule that applies to the particular type you found.
I am not quite sure what you mean by validation, though, and what that would buy you. Once you know the type of the content, what would you do with it?
I use Excel's data validation technique in a VSTO application myself. It obviously isn't VSTO but it works well enough. There are some drawbacks like you can't have multiple validations on the same cell (i.e. you have to know what your validating for)
You can directly use the excel's functionality !!!
no need of any coding for that !!
instead of hard work go for the smart work ...
In excel,
Go to the cell where you want the validation to come
Menu ->> Data --> validation
Here you can directly use the various excel validation terms.
Which you can refer here or..
http://support.microsoft.com/kb/211485
Thanx
Regards.