Release of PowerTools for Open XML v1.1.1

PowerTools for Open XML v1.1.1 source code and binaries are now available.  PowerTools for Open XML is an open source project on CodePlex that enables creation and processing of Open XML documents using PowerShell.  This is a minor release that addresses four issues.

This blog is inactive.
New blog: EricWhite.com/blog

Blog TOCFor information about PowerTools for Open XML v1.1, see Release of PowerTools for Open XML v1.1.

For more basic information on PowerTools for Open XML, see Automated Processing of Open XML Documents using PowerShell.

We’ve also updated the DocumentBuilder class in DocumentBuilder.zip.  The post Move/Insert/Delete Paragraphs in Word Processing Documents using the Open XML SDK introduces the DocumentBuilder class.

Elimination of Creation of Duplicate Images in the Merged Document

When using Merge-OpenXmlDocument in the previous version, if the same image was referenced multiple times in the source documents, it was duplicated in the newly constructed document.  A user of the PowerTools reported this – they were merging hundreds of documents where a header contained the same image in each of the source documents.  We added a small amount of optimization where we checked to see if an image had already been moved to the destination document before creating a new part.  The implementation is pretty efficient – to determine if an image already exists, it first checks sizes, then does a binary compare of the images.  This is a good optimization all around – it executes faster, and the newly merged document is smaller.

Better Control of Sections

When specifying sources, you can specify that Merge-OpenXmlDocument keep the section information or not.  You specify this by setting the public property KeepSection to $True after newing up the OpenXml.PowerTools.DocumentSource object.  Then, if the specified source range contains any section markers, those section markers are moved to the newly merged document.

For example, if you have one document with landscape orientation and another document with portrait orientation, you can merge them with the following script:

$doc1 = New-Object `
-TypeName OpenXml.PowerTools.DocumentSource `
-ArgumentList C:\Users\ericwhit\Documents\09-04-19-PowerTools-Test\Landscape.docx
$doc1.KeepSection = $true
$doc2 = New-Object `
-TypeName OpenXml.PowerTools.DocumentSource `
-ArgumentList C:\Users\ericwhit\Documents\09-04-19-PowerTools-Test\Portrait.docx
$doc2.KeepSection = $true
Merge-OpenXmlDocument -OutputPath Test.docx -Sources $doc1,$doc2

The resulting document will look like this:

Fixed Bug in Merge-OpenXmlDocument associated with Numbering

We added checks when finding the current maximum ID. The previous version would fail if the document had a part (e.g. Numbering), but there were no elements in the part.

Fixed Bug in Merge-OpenXmlDocument if no Styles or FontTable Part

Merge-OpenXmlDocument would fail if the document did not have a Styles part or a FontTable part. This has been fixed.