OfficeJS Word Addin - Modify content control in the whole document ( including header/footer ) - api

Due to the office API limitation ( API is only restricted to rich text content controls). We had to insert content controls as an OOXML object. It inserted the content control correctly but office API doesn’t recognize that as a content control. For example, using office API, if you call a method to get all the content controls, above content control will not be returned.
If you run following code, it will not return those content controls that were inserted like that.
// Run a batch operation against the Word object model.
Word.run(function (context) {
// Create a proxy object for the content controls collection.
var contentControls = context.document.contentControls;
}
Here is the OOXML:
<pkg:package xmlns:pkg="http://schemas.microsoft.com/office/2006/xmlPackage">
<pkg:part pkg:name="/_rels/.rels" pkg:contentType="application/vnd.openxmlformats-package.relationships+xml" pkg:padding="512">
<pkg:xmlData>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml" />
</Relationships>
</pkg:xmlData>
</pkg:part>
<pkg:part pkg:name="/word/document.xml" pkg:contentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml">
<pkg:xmlData>
<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml">
<w:body>
<w:sdt>
<w:sdtPr>
<w:alias w:val="[REPLACE_THIS]" />
<w:id w:val="1382295294" />
<w:placeholder>
<w:docPart w:val="4D926923E99F45DBAF2203E4FEA73047" />
</w:placeholder>
<w:dataBinding w:xpath="[REPLACE_THIS]" w:storeItemID="{AFE97E21-6B3F-435F-8566-BD38F346ABE4}" />
<w:showingPlcHdr />
</w:sdtPr>
<w:sdtContent>
<w:p>
<w:r>
<w:t>[REPLACE_THIS]</w:t>
</w:r>
</w:p>
</w:sdtContent>
</w:sdt>
</w:body>
</w:document>
</pkg:xmlData>
</pkg:part>
</pkg:package>
As Office API doesn't have any built-in methods to get these content controls and modify them. I have to read each section of the document, Get the OOXML , modify it and insert it back. Is there any other way to do this ? As this is really cumbersome and error-prone process.

I am assuming that you are using OOXML to insert other types of content controls (i.e. plain text, combo, date, etc.) and if that's the case, yes, in the content control collection we do not support, as of now, other types of content controls other than rich text. This is mostly because of a limitation in Word Online who only supports rich text as of today, and we ship APIs that can guarantee a multiplatform behavior. The plan is that when it eventually supports other types they will be included as part of the collection (hence the type property).
so, yes for now your only way out is to get the OOXML and handle the other types of control via XML. You can probably target the OOXML you get if you wrap them with a rich text content control and only getting the OOXML of the wrapper content controls.

Related

How can I Map from XML HREF+Text to Word Document Hyperlink?

I Have a simple XML file e.g.:
<root>
<some_link_href>http://www.microsoft.com/</some_link_href>
<some_link_text>goto microsoft site</some_link_text>
</root>
I have setup XmlMapping, but I can't seem to get a Hyperlink.
I tried using richTextControl and and providing RTF text
(e.g. '{\rtf1\pc some \b BOLD \b0 text}') but it just shown the raw RTF.
Note: even though I'd like to have a Text with HREF, I can settle for clickable URI
Is there any other control? other good methods to use?
also posted # https://learn.microsoft.com/en-us/answers/questions/720964/place-link-on-winword-from-xmlmapping.html

How to create a text field within a DDX file?

I'm trying to create an adobe form that consists in a text field inside a DDX file that contains properties such as watermarks and other options.
Adobe DDX reference indicates that it supports XDP declarations but I've not been able to make it work.
What I'm trying to accomplish is that every time a user opens a PDF a text field should populate with the current Date and time. I already created a javascript that will be attached in the PDF from the DDX but it's failing in the instruction this.getField("NAME_HERE") because it doesn't exists.
My last attempt was to define a XDP field but it's not recognized since XDP is not bound.
<PDF result="onlyPrinted" return="false">
<XDP>
<!--<XDP:field name="onOpenJS"/>-->
</XDP>
<JavaScript name="getDate" source="File:///PATH"/>
<PDF source="mainWatermark">
</PDF>
</PDF>
Have you ever created a form in a DDX file?

Questions on populating a PDF form with cfpdfform and rich text

So I'm using the following code to create a PDF from data from a query.
<cfpdfform action="populate" source="test.pdf" destination="GeneratedPDFs/test.pdf" overwrite="yes">
<cfpdfformparam name="FirstLine1" value="#Variables.FirstLine#">
<cfpdfformparam name="SecondLine1" value="#Variables.SecondLine#">
<cfpdfformparam name="AddressBox1" value="#Variables.AddressBox#">
<cfpdfformparam name="Body1" value="#Variables.Body1#">
<cfpdfformparam name="FirstLine2" value="#Variables.FirstLine#">
<cfpdfformparam name="SecondLine2" value="#Variables.SecondLine#">
<cfpdfformparam name="AddressBox2" value="#Variables.AddressBox#">
<cfpdfformparam name="Body2" value="#Variables.Body2#">
</cfpdfform>
<cfpdf action="write" source="GeneratedPostCards/!PostCard2013-Vipre.pdf" destination="GeneratedPostCards/!PostCard2013-Vipre-flat.pdf" flatten="yes" overwrite="true">
</cfpdf>
This works fine, and generates the PDF for me, but I've run into three issues:
If I set a form field in Acrobat Pro DC to a Rich Text, then no matter what font I select, I get Courier. In order to get the font I want, I have to turn off Rich Text.
I'd like to change the line spacing or leading in the multi-line fields, but I don't see a way to do that (either in Acrobat or in ColdFusion).
I'd like to be able to bold, italicize, and change the colour of specific words (not the entire field) and I'm wondering if there are codes I can pass from ColdFusion to do this.
Thanks!
Keep in mind that if you set the richText flag of a text field, you will have to use richValue for the value, and richValue is an array of span objects, where each object represents a piece of the text with specific properties. The Acrobat JavaScript documentation is your friend…
As it is not really possible to directly insert arrays into a PDF form, you might consider representing the richValue arrays as strings, and fill them into hidden "shadow fields". When the document opens, some logic interprets those strings, and fills the richText enabled fields with correct richValue arrays.
It may also be good to know that there is no richDefaultValue property, which means that you would have to recreate the richValue when you reset the form.

What is the suitable replacement for this.__LZtextclip.text in Open laszlo 5.0

I want to know what is the suitable replacement for this line.
this.__LZtextclip.text
I am using this to get the string present in the text node. This works fine in Openlaszlo 3.3 but in 4.9 and 5.0 it's giving a problem
I tried updating it to
this.sprite.__LZtextclip.text
And i am getting an error:
79: Error: Access of possibly undefined property __LZtextclip through a reference with static type LzSprite, in line: Debug.write(this.sprite.__LZtextclip.text);
Any idea why this problem is happening?
If you are trying to access the text content of a text field, why don't you just access the attribute text?
<canvas>
<text name="sample" id="gRead" />
<handler name="oninit">
gRead.setAttribute('text',"HI");
Debug.info(gRead.text);
</handler>
</canvas>
In OpenLaszlo 3.3 there is method getText(), which gives you the same value. Accessing mx.textfield in your code does not work for the DHTML runtime.
Edit: Added information regarding the stripping of HTML tags
The Flash Textfield class flash.text.Textfield provides an API to enable HTML tag content in a Textfield instance. There are two different properties, one called text, the other one htmlText. If you want to directly access the Flash Textfield object of an lz.text instance, it's a property of the display object of the lz.text instance:
// Flash Textfield instance
gRead.getDisplayObject().textfield
// Pure text content
gRead.getDisplayObject().textfield.text
// Formatted text
gRead.getDisplayObject().textfield.htmlText
You should be aware of the fact that Flash automatically adds HTML format to any textstring you set as content. When you do
gRead.setAttribute('text',"HI");
the textfield.htmlText value is
<P ALIGN="LEFT"><FONT FACE="Verdana" SIZE="11" COLOR="#000000" LETTERSPACING="0" KERNING="1">HI</FONT></P>
For the DHTML runtime, the text content is added as the innerHTML of a <div> tag, and there is no standardized API to retrieve the pure text content of a DOM structure for a tag with content. You could write your own function to extract the text content, or use JavaScript functions from existing frameworks - like the jQuery text() function - to achieve the same result for the DHTML runtime.
I guess the reason is that Laszlo started using the Dojo based rich text editor for text input with HTML formatting since OpenLaszlo 4.0 or 4.1.
The best approach to have consistent behavior across runtimes when stripping tags is to do the conversion on the server-side. That's especially needed if you wan to have consistent whitespace treatment in multiline text, since there differences in how browsers treat whitespace. The question how to best strip tags from strings in JavaScript has been answered before on Stackoverflow, e.g. JavaScript: How to strip HTML tags from string?
Here is a cross-runtime example which works in DHTML with Firefox, Chrome, and it should work with IE9+:
<canvas>
<text name="sample" id="gRead" />
<handler name="oninit"><![CDATA[
gRead.setAttribute("text", 'Hello <b>World</b> OL');
Debug.info("gRead.text=" + gRead.text);
if ($dhtml) {
Debug.info(gRead.getDisplayObject().textContent);
} else {
Debug.info(gRead.getDisplayObject().textfield.text);
}
]]></handler>
</canvas>
I found what is the problem. The problem is that i have to declare a variable and have to refer the property from that.
<canvas>
<library>
<text name="sample" id="gRead">
<method name="getTextFrom">
Debug.write("this.text" , this.sprite);
var mx = this.sprite;
Debug.write("this.text" , mx.textfield.text);
</method>
</text>
</library>
<handler name="oninit">
gRead.setAttribute('text',"HI");
gRead.getTextFrom();
</handler>
</canvas>

Refining my Dojo/Dijit NumberTextBox numeric validation

I have the following code:
<input type="text" dojoType="dijit.form.NumberTextBox" size=8
constraints="{min:0,max:100000,places:0}"
id="orgNumberOfStudents" name="orgNumberOfStudents"
required="true" invalidMessage="Integer between 0 and 100,000"
value="">
Questions:
1) How do I set the width of the box? Do I have to do it in a style tag or a CSS? Is the traditional "input size" tag ignored?
2) The above sample shows the error when I type in a non-numeric value. But if I tab over the field and don't fill in anything, it's still blank. Is there a quick way to enforce the validation when I click the submit button? Do I need a Dijit submitt button? Do I need to write more JavaScript to make this happen? How does the required="true" actually occur?
(One get-around is to set the value to 0, but I'd rather force the user enter a value rather than just defaulting it).
Thanks,
Neal Walters
You should be able to use both CSS and traditional INPUT attributes like "maxLength" on your NumberTextBox by passing them in to the Widget's constructor. maxLength is available on all dijit.form.TextBox subclasses, but is probably less useful here since you have control over things like min/max and the actual number format.
Yes, you can always write your own JS to test "isValid()" on your widget instance before submission, e.g. in an HTML FORM onSubmit handler, or you could use dijit.form.Form which will check validity for you. The widget itself is only responsible for visual representation of its own validity, according to the options chosen.
HTH