How to create a document and fill it with textboxes based on x and y coords or pixels? - ms-word

Im trying to create a template to print some information on a blank document based in coordinates or pixels or cm, wtv is possible.
why? I have some accounting forms which is to bad fill it manual. Im wondering if it is possible to create a function with some parameters related to the text box positions in document.
eg. txtName goes to (3,15) position in a document. It may be necessary define the size of document
If it is possible, what language you recommend?

Yes, it is possible.
If you use Microsoft Word to insert a text box into a blank document, then save it, and inspect the resulting docx, you'll see Word inserts the text box in 2 formats:
<mc:AlternateContent>
<mc:Choice Requires="wps">
<w:drawing>
<wp:anchor distT="0" distB="0" distL="114300" distR="114300" simplePos="0" relativeHeight="251659264" behindDoc="0" locked="0" layoutInCell="1" allowOverlap="1" wp14:anchorId="44014479" wp14:editId="7FACADD8">
<wp:simplePos x="0" y="0"/>
<wp:positionH relativeFrom="column">
<wp:align>center</wp:align>
</wp:positionH>
<wp:positionV relativeFrom="paragraph">
<wp:posOffset>0</wp:posOffset>
</wp:positionV>
<wp:extent cx="2374265" cy="1403985"/>
<wp:effectExtent l="0" t="0" r="22860" b="23495"/>
<wp:wrapTopAndBottom/>
<wp:docPr id="307" name="Text Box 2"/>
<wp:cNvGraphicFramePr>
<a:graphicFrameLocks xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"/>
</wp:cNvGraphicFramePr>
<a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
<a:graphicData uri="http://schemas.microsoft.com/office/word/2010/wordprocessingShape">
<wps:wsp>
<wps:cNvSpPr txBox="1">
<a:spLocks noChangeArrowheads="1"/>
</wps:cNvSpPr>
<wps:spPr bwMode="auto">
<a:xfrm>
<a:off x="0" y="0"/>
<a:ext cx="2374265" cy="1403985"/>
</a:xfrm>
<a:prstGeom prst="rect">
<a:avLst/>
</a:prstGeom>
<a:solidFill>
<a:srgbClr val="FFFFFF"/>
</a:solidFill>
<a:ln w="9525">
<a:solidFill>
<a:srgbClr val="000000"/>
</a:solidFill>
<a:miter lim="800000"/>
<a:headEnd/>
<a:tailEnd/>
</a:ln>
</wps:spPr>
<wps:txbx>
<w:txbxContent>
<w:p w:rsidR="006C2E97" w:rsidRDefault="006C2E97">
<w:proofErr w:type="gramStart"/>
<w:r>
<w:t>YOUR CONTENT GOES HERE</w:t>
</w:r>
</w:p>
</w:txbxContent>
</wps:txbx>
<wps:bodyPr rot="0" vert="horz" wrap="square" lIns="91440" tIns="45720" rIns="91440" bIns="45720" anchor="t" anchorCtr="0">
<a:spAutoFit/>
</wps:bodyPr>
</wps:wsp>
</a:graphicData>
</a:graphic>
<wp14:sizeRelH relativeFrom="margin">
<wp14:pctWidth>40000</wp14:pctWidth>
</wp14:sizeRelH>
<wp14:sizeRelV relativeFrom="margin">
<wp14:pctHeight>20000</wp14:pctHeight>
</wp14:sizeRelV>
</wp:anchor>
</w:drawing>
</mc:Choice>
<mc:Fallback>
<w:pict>
<v:shapetype id="_x0000_t202" coordsize="21600,21600" o:spt="202" path="m,l,21600r21600,l21600,xe">
<v:stroke joinstyle="miter"/>
<v:path gradientshapeok="t" o:connecttype="rect"/>
</v:shapetype>
<v:shape id="Text Box 2" o:spid="_x0000_s1026" type="#_x0000_t202" style="position:absolute;margin-left:0;margin-top:0;width:186.95pt;height:110.55pt;z-index:251659264;visibility:visible;mso-wrap-style:square;mso-width-percent:400;mso-height-percent:200;mso-wrap-distance-left:9pt;mso-wrap-distance-top:0;mso-wrap-distance-right:9pt;mso-wrap-distance-bottom:0;mso-position-horizontal:center;mso-position-horizontal-relative:text;mso-position-vertical:absolute;mso-position-vertical-relative:text;mso-width-percent:400;mso-height-percent:200;mso-width-relative:margin;mso-height-relative:margin;v-text-anchor:top" >
<v:textbox style="mso-fit-shape-to-text:t">
<w:txbxContent>
<w:p w:rsidR="006C2E97" w:rsidRDefault="006C2E97">
<w:r>
<w:t>YOUR CONTENT GOES HERE</w:t>
</w:r>
</w:p>
</w:txbxContent>
</v:textbox>
<w10:wrap type="topAndBottom"/>
</v:shape>
</w:pict>
</mc:Fallback>
</mc:AlternateContent>
</w:r>
You can use either the w:drawing or the w:pict syntax. I quite like w:pict with its #style
As a first step you'll want to play in Word with how the boxes are positioned - I guess you want them positioned against the page, not a paragraph.
Then its just a matter of replicating the XML in your choice of language.
You could:
unzip, manipulate, then rezip
doing the manipulation with XML aware tool
or doing the manipulation without that
or use a lib, such as:
for .NET, Microsoft's Open XML SDK
for Java, POI, docx4j
for C, libopc
etc...

Related

How to control the indicator gap on an Apache Royale Jewel form?

I have a simple form:
<j:Form id="myForm3" x="720 "y="120" height="100" width="300">
<j:FormItem label="data24">
<b:TextInput id="data24"/>
</j:FormItem>
<j:FormItem label="data25">
<b:TextInput id="data25"/>
</j:FormItem>
<j:FormItem label="data26">
<b:TextInput id="data26"/>
</j:FormItem>
<j:Form />
I want to control the gap between the label and the text input box. I thought I could do it with CSS but I can't find the right combination. How do do control this gap?
Or is there a better way to do the form?
gap in FormItem is controlled trough the layout bead. By default In the following example (modeled like yours), I added a HorizontalLayout bead only to the first FormItem to show the difference with the rest:
<j:Form id="myForm3" x="720 "y="120" height="100" width="300">
<j:FormItem label="data24">
<j:beads>
<j:HorizontalLayout gap="8"/>
</j:beads>
<j:TextInput localId="data24"/>
</j:FormItem>
<j:FormItem label="data25">
<j:TextInput localId="data25"/>
</j:FormItem>
</j:Form>
I changed id for localId since html doesn't like duplicates, so better use always the later.
Note 1: default gap is in Jewel Theme
j|FormItem
gap: 2
itemsVerticalAlign: itemsCentered
Note 2: a gap = 2 means in default Jewel Theme, 2x3 = 6 pixels. The values are baked in CSS, and are multiples of 4. All the default numbers can be configured in Jewel Theme through SASS for more flexibility.
although the last response was ok. Here's code you'll need for your specific use case. You'll need to add a css rule to hide the "required" part. I did at form level, but it could be done at form item level too, but guess you want to remove in all the form:
<j:Form localId="myForm3" x="720 "y="120" height="100" width="300"
className="remove-required">
<j:FormItem label="data24">
<j:beads>
<j:HorizontalLayout gap="0"/>
</j:beads>
<j:TextInput localId="data24"/>
</j:FormItem>
<j:FormItem label="data25">
<j:beads>
<j:HorizontalLayout gap="0"/>
</j:beads>
<j:TextInput localId="data25"/>
</j:FormItem>
</j:Form>
<fx:Style>
.jewel.form.remove-required .jewel.label.required {
display: none;
}
</fx:Style>

Modify the Outlook CustomUI XML by powershell

friends. I want to check every of my company users' outlook customUI configuration file. Delete 2 UI buttons if any. I am trying to do it by powershell. But failed to do so. Any advice for my script?
Below is the XML content of olkexpplorer.officeUI. I need to check & delete the items in blockquotes in case they are existed in the configuration file.
<mso:customUI xmlns:x1="Microsoft.Forefront.SpamReporterAddin.Connect" xmlns:mso="http://schemas.microsoft.com/office/2009/07/customui">
<mso:ribbon>
<mso:qat />
<mso:tabs>
<mso:tab idQ="mso:TabMail">
<mso:group id="mso_c1.45620CF" label="Phishing Report" imageMso="TrustCenter" autoScale="true"
<mso:control idQ="x1:ExplorerPhishReportMenuButton" imageMso="TrustCenter" visible="true"/>
</mso:group>
> <mso:group id="mso_c2.14817EBA" label="Junk" autoScale="true">
> <mso:control idQ="x1:ExplorerSpamReportMenuButton" visible="true" />
> <mso:control idQ="x1:ExplorerPhishReportMenuButton" imageMso="GreenBall" visible="true" />
> </mso:group>
</mso:tab>
</mso:tabs>
</mso:ribbon>
</mso:customUI>
Here is my script
$input = [xml](Get-Content -Path “$path_to_office\olkexplorer.officeUI”)
$deletenames="mso_c2.14817EBA"
($input.customUI.ChildNodes |Where-object { $deletenames -contains $_.Name}) | ForEach-
Object{[void]$_.ParentNode.RemoveChild($_)}
$input.save(“$path_to_office\new.officeUI”)
First of all, it is not clear how the ribbon XML looks like after running your code:
$input.save(“$path_to_office\new.officeUI”)
Anyway, you can do any modifications until the ribbon XML is loaded by the host application. At runtime, you may consider using callbacks where they are available and call the IRIbbonUI.Invalidate or IRibbonUI.InvalidateControl methods to get your custom UI invalidated and callbacks triggered. Here is what MSDN states:
For each of the callbacks the add-in implements, the responses are cached. For example, if an add-in writer implements the getImage callback procedure for a button, the function is called once, the image loads, and then if the image needs to be updated, the cached image is used instead of recalling the procedure. This process remains in-place until the add-in signals that the cached values are invalid by using the Invalidate method, at which time, the callback procedure is again called and the return response is cached. The add-in can then force an immediate update of the UI by calling the Refresh method.
The problem with your approach is that ChildNodes() only returns the immediate child nodes and not all child nodes (and using $input as a variable name is not considered a good practice anyway because its a reserved variable name).
So instead of ChildNodes() I would access the child node directly like so
$input.customUI.ribbon.tabs.tab.group | where-object { $DeleteNames -contains $_.id}
I would prefer the System.Xml.Linq classes like XDocument and XElement over the [xml] type alias because they make dealing with Xml inside a PowerShell script a little more convenient.
if this is the input xml:
$XmlCode = #'
<mso:customUI xmlns:mso="http://schemas.microsoft.com/office/2009/07/customui">
<mso:ribbon>
<mso:qat><mso:sharedControls>
<mso:control idQ="mso:FileNewDefault" visible="false"/>
<mso:control idQ="mso:FileOpen" visible="false"/>
<mso:control idQ="mso:FileSave" visible="true"/>
<mso:control idQ="mso:FileSendAsAttachment" visible="false"/>
<mso:control idQ="mso:FilePrintQuick" visible="false"/>
<mso:control idQ="mso:SpellingAndGrammar" visible="false"
insertBeforeQ="mso:PrintPreviewAndPrint"/>
<mso:control idQ="mso:Undo" visible="true"
insertBeforeQ="mso:PrintPreviewAndPrint"/>
<mso:control idQ="mso:RedoOrRepeat" visible="true"
insertBeforeQ="mso:PrintPreviewAndPrint"/>
<mso:control idQ="mso:TableDrawTable" visible="false"
insertBeforeQ="mso:PrintPreviewAndPrint"/>
<mso:control idQ="mso:FileOpenRecentFile" visible="false"
insertBeforeQ="mso:PrintPreviewAndPrint"/>
<mso:control idQ="mso:FontDialog" visible="true"
insertBeforeQ="mso:PrintPreviewAndPrint"/>
<mso:control idQ="mso:FontSizeDecreaseWord" visible="true"
insertBeforeQ="mso:PrintPreviewAndPrint"/>
<mso:control idQ="mso:FontSize" visible="true"
insertBeforeQ="mso:PrintPreviewAndPrint"/>
<mso:control idQ="mso:PageSetupDialog" visible="true"
insertBeforeQ="mso:PrintPreviewAndPrint"/>
<mso:control idQ="mso:PrintPreviewAndPrint" visible="true"/>
</mso:sharedControls>
</mso:qat>
</mso:ribbon>
</mso:customUI>
'#
the following Powershell commands would remove all mso:control nodes with visible="false":
using namespace System.Xml.Linq
Add-Type -Assembly System.Xml.Linq
$xmlCode = "<<as shown above>>"
$xRoot = [XDocument]::Parse($xmlCode)
$msoNs = [XNamespace]::get("http://schemas.microsoft.com/office/2009/07/customui")
$DeleteNodes = $xRoot.Descendants($msoNs + "control").where{$_.Attribute("visible").Value -eq "false"}
$DeleteNodes.ForEach{$_.Remove()}
$xRoot.ToString()
# Save the new xml
$XmlPath = [System.IO.Path]::GetTempFileName()
$xRoot.Save($XmlPath)
XDocument has a Load() method for loading a xml file directly so there is no need to use the Parse() method (I was using for the sake of this example).
The only small drawback comparing to [xml] is that you have to consider namespaces.

Expected behavior of the renderer for superscripts and subscripts in Word Open XML

It looks like ECMA specification for Word Open XML doesn't specify how to render "runs" with vertAlign attribute. Is there a document describing the expected behavior:
What font size to use for superscripts and subscripts?
For how much to shift the superscript/subscript text relatively to the baseline?
Just for reference, here's a document.xml generated by MS Word for a trivial document containing text "X²" (XML namespaces are omitted for brevity):
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:document>
<w:body>
<w:p w14:paraId="4B8ED8F1" w14:textId="3891D3E1"
w:rsidR="00CE1223" w:rsidRDefault="00886D56">
<w:r>
<w:t>X</w:t>
</w:r>
<w:r w:rsidRPr="00886D56">
<w:rPr>
<w:vertAlign w:val="superscript"/>
</w:rPr>
<w:t>2</w:t>
</w:r>
<w:bookmarkStart w:id="0" w:name="_GoBack"/>
<w:bookmarkEnd w:id="0"/>
</w:p>
<w:sectPr w:rsidR="00CE1223">
<w:pgSz w:w="12240" w:h="15840"/>
<w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440"
w:header="720" w:footer="720" w:gutter="0"/>
<w:cols w:space="720"/>
<w:docGrid w:linePitch="360"/>
</w:sectPr>
</w:body>
</w:document>
The RunProperties elements has following two child elements which can be used to set the position and the font of a Run which has a VerticalTextAlignment:
The RunFonts element which can be used to set the type of font
The Position element which can be used to lower or raise the the run in relation to its default baseline.
Using these elements you can create a run which is in superscript and has an adjusted font:
// Creates an RunProperties instance and adds its children.
public RunProperties GenerateRunProperties()
{
RunProperties runProperties1 = new RunProperties();
RunFonts runFonts1 = new RunFonts(){ Ascii = "Times New Roman", HighAnsi = "Times New Roman", ComplexScript = "Times New Roman" };
FontSize fontSize1 = new FontSize(){ Val = "48" };
VerticalTextAlignment verticalTextAlignment1 = new VerticalTextAlignment(){ Val = VerticalPositionValues.Superscript };
runProperties1.Append(runFonts1);
runProperties1.Append(fontSize1);
runProperties1.Append(verticalTextAlignment1);
return runProperties1;
}
This will output the follwing openxml:
<w:rPr xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
<w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman" w:cs="Times New Roman" />
<w:sz w:val="48" />
<w:vertAlign w:val="superscript" />
</w:rPr>
And you can shift the vertical aligned run using these elements:
// Creates an RunProperties instance and adds its children.
public RunProperties GenerateRunProperties()
{
RunProperties runProperties1 = new RunProperties();
RunFonts runFonts1 = new RunFonts(){ Ascii = "Times New Roman", HighAnsi = "Times New Roman", ComplexScript = "Times New Roman" };
Position position1 = new Position(){ Val = "-10" };
FontSize fontSize1 = new FontSize(){ Val = "48" };
VerticalTextAlignment verticalTextAlignment1 = new VerticalTextAlignment(){ Val = VerticalPositionValues.Superscript };
runProperties1.Append(runFonts1);
runProperties1.Append(position1);
runProperties1.Append(fontSize1);
runProperties1.Append(verticalTextAlignment1);
return runProperties1;
}
Generating the follwing openXML:
<w:rPr xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
<w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman" w:cs="Times New Roman" />
<w:position w:val="-10" />
<w:sz w:val="48" />
<w:vertAlign w:val="superscript" />
</w:rPr>
Depending on the value that you assign to the position element the run will be raised or lowered in relation to its baseline:
Positve => Raised
Negative => Lowered

Strip whitespace in FOP inline element

I fail stripping whitespaces inside of inline elements in FOP with DITA-OT PDF2. This is my code snippet:
<p>1 BEFORE <uicontrol>test</uicontrol> AFTER</p>
<p>2 BEFORE <uicontrol> test</uicontrol> AFTER</p>
<p>3 BEFORE <uicontrol>test </uicontrol> AFTER</p>
<p>4 BEFORE <uicontrol><keyword keyref="test"/> </uicontrol> AFTER</p>
<p>5 BEFORE <uicontrol> <keyword keyref="test"/></uicontrol> AFTER</p>
<p>6 BEFORE <uicontrol>
<keyword keyref="test"/>
</uicontrol> AFTER</p>
<p>7 BEFORE <uicontrol>
<keyword keyref="test"/>
</uicontrol> AFTER</p>
Renders to:
This is my attribute set:
<xsl:attribute-set name="uicontrol">
<xsl:attribute name="white-space">nowrap</xsl:attribute>
<xsl:attribute name="white-space-treatment">ignore</xsl:attribute>
<xsl:attribute name="white-space-collapse">true</xsl:attribute>
<xsl:attribute name="linefeed-treatment">treat-as-zero-width-space</xsl:attribute>
<xsl:attribute name="background-color">#ff0000</xsl:attribute>
</xsl:attribute-set>
All red whitespaces have to be stripped. Where is my mistake?
FOP seems to have difficulty in "white-space-treatment":
XSL-FO Property Support Table (§7)
So it may be needed to use <xsl:strip-space elements="uicontrol"> plus normalize-space() function for text() in uicontrol.
Following is the result when specifying <xsl:strip-space elements="uicontrol">
For your reference, Antenna House renders your original style definition as follows:
Hope this helps your development.

Orbeon control details in own component

I'm making my own component, and I want to have oportunity to set some properties in form builder. In all I want to reach effect similar to autocomplete control, where I can set 3 properties (URI, xpath, and relative xpath). I read, that I can do it using control-details markup, but unfortunately it does not work. This is code (I working on davinci tutorial):
<xbl:binding element="fr|tutorial-davinci" id="fr-tutorial-davinci" xxbl:mode="lhha binding value">
<metadata xmlns="http://orbeon.org/oxf/xml/form-builder" xmlns:xf="http://www.w3.org/2002/xforms">
<display-name lang="en">davinci-modified</display-name>
<templates>
<instance label=""/>
<view>
<fr:tutorial-davinci id="" appearance="minimal" labelref="#label" xmlns="" resource="" >
<xf:label ref=""/>
<xf:hint ref=""/>
<xf:help ref=""/>
<xf:alert ref=""/>
</fr:tutorial-davinci>
</view>
</templates>
<control-details>
<xf:input>
<xf:label lang="en">Some param</xf:label>
</xf:input>
</control-details>
</metadata>
<xbl:template>
<xf:model>
<xf:instance id="id1"><value/></xf:instance>
</xf:model>
<xf:input ref="instance('id1')" />
</xbl:template>
</xbl:binding>
You must have a ref attribute on<xf:input> which points to an attribute or element where the information will be stored. In autocomplete.xml, there is in particular theresource` attribute, which:
is pointed to by <xf:input>
is present on the <fr:autocomplete> template