OOXML Hacking: Locking Graphics

Locking graphics in Office documents must be #1 on most designers’ wish lists, judging by the number of requests we get. While Word and Excel already do a fairly good job of locking, they can still benefit from this technique. PowerPoint remains wide open. If you can see it, you can move, resize or delete it. Placing items on the Slide Master or Layouts helps, but this is minimal protection against a savvy user. Your users love to be “creative”, so how can we protect the brand from their enthusiasm?

Fortunately, it’s possible to provide protection for important logos and maintain slide layout integrity by editing the template XML. But this power comes with a responsibility to design the protection carefully. It can be a very thin line between a deck that is protected and one that is unusable. If you decide to protect your presentation, it is incumbent on you to test it repeatedly to ensure your users can still get work done with it.

Before trying this, please read my Introduction to XML Hacking. If you’re using OS X, it’s also important to read my notes about Editing XML in OS X.

Locking takes place mostly in the Slide Master and Layouts. A minimal approach is best, as each additional locked item will create more feedback from your users with the potential to increase tech support costs. On the Slide Master, you will probably only lock a company logo.


Locking Graphics: Logos

Start by placing a logo on the Slide Master. Of course, you’re not using a JPEG file, because you already know that’s the worst format for line art. If you still think JPEGs for logos are a good idea, please read JPEG Logos? Fail! and Logo Production Secrets. After the logo is in place, expand the presentation to view the XML. Open ppt\slideMasters\slideMaster1.xml. All the placeholder coding comes first, so scroll down about halfway until you see XML that looks like this:

<p:pic>
  <p:nvPicPr>
    <p:cNvPr id="7" name="Picture 6"/>
    <p:cNvPicPr>
      <a:picLocks noChangeAspect="1"/>
    </p:cNvPicPr>
    <p:nvPr userDrawn="1"/>
  </p:nvPicPr>

To lock this, we can add just one small parameter (in bold):

<p:pic>
  <p:nvPicPr>
    <p:cNvPr id="7" name="Picture 6"/>
    <p:cNvPicPr>
      <a:picLocks noChangeAspect="1" noSelect="1"/>
    </p:cNvPicPr>
    <p:nvPr userDrawn="1"/>
  </p:nvPicPr>

Test this out by re-zipping the files and opening in PowerPoint. Try to select the logo. noSelect=”1″ has the effect of making it unselectable, so the user can’t do anything creative with it, even if they open the master.

This is a super-simple technique, but it has a potential down side. Many add-ins and VBA macros work on a presentation by going through every shape on a slide until it finds the one it needs to revise. The noSelect tag can play havoc with code like that and possibly cause the programming to fail for no apparent reason. So here’s a more professional lock that has the same effect, but won’t disrupt any add-ins:

<p:pic>
  <p:nvPicPr>
    <p:cNvPr id="7" name="Picture 6"/>
    <p:cNvPicPr>
      <a:picLocks noChangeAspect="1" noMove="1" noResize="1" noRot="1"/>
    </p:cNvPicPr>
    <p:nvPr userDrawn="1"/>
  </p:nvPicPr>

Locking Graphics: Shapes

Different graphic objects use a slightly different syntax. The noSelect=”1″ parameter remains the same, but you have to expand a tag and add a new line to include it. For all AutoShapes except lines, the default XML will resemble the following:

<p:sp>
  <p:nvSpPr>
    <p:cNvPr id="9" name="Rectangle 8"/>
    <p:cNvSpPr/>
    <p:nvPr userDrawn="1"/>
  </nvSpPr>

Editing the p:cNvSpPr tag as shown below will make the shape unselectable:

<p:sp>
  <p:nvSpPr>
    <p:cNvPr id="9" name="Rectangle 8"/>
    <p:cNvSpPr>
      <a:spLocks noMove="1" noResize="1" noRot="1"/>
    </p:cNvSpPr>
    <p:nvPr userDrawn="1"/>
  </nvSpPr>

Locking Graphics: Lines

At the XML level, lines are referred to as Connectors rather than Shapes. The original XML will look like this:

<p:cxnSp>
  <p:nvCxnSpPr>
    <p:cNvPr id="8" name="Straight Connector 7"/>
    <p:cNvCxnSpPr/>
    <p:nvPr userDrawn="1"/>
  </nvCxnSpPr>

To lock this, edit the p:cNvCxnSpPr tag:

<p:cxnSp>
  <p:nvCxnSpPr>
    <p:cNvPr id="8" name="Straight Connector 7"/>
    <p:cNvCxnSpPr>
      <a:cxnSpLocks noMove="1" noResize="1" noRot="1"/>
    </p:cNvCxnSpPr>
    <p:nvPr userDrawn="1"/>
  </nvCxnSpPr>

Locking Graphics: Placeholders

Placeholders are the boxes on slide layouts that can hold different types of content. The layouts are found in ppt\slideLayouts. They are numbered in the order that they appear in the left-hand list of layouts in Slide Master view. By default slideLayout1.xml is the Title slide. The XML tag is <p:sp> instead of <p:pic>, but otherwise the syntax is the same for locking. Placeholders do not inherit the lock parameters, so locking a placeholder on the master doesn’t affect the layouts and locked placeholders on the layouts have no effect on the slide placeholders.

You can see what other parameters are possible for the spLocks tag at Datypic’s a:spLocks page. There are options here to prevent grouping the image, rotating, moving or resizing it, changing it’s aspect ratio and several other less useful options. Let’s use some of the other parameters to lock down the shape. Here is the start of a Title placeholder:

<p:sp>
  <p:nvSpPr>
    <p:cNvPr id="2" name="Title 1"/>
      <p:cNvSpPr>
    <a:spLocks noGrp="1"/>
  </p:cNvSpPr>

After we add parameters to prevent moving and resizing, the XML looks like this:

<p:sp>
  <p:nvSpPr>
    <p:cNvPr id="2" name="Title 1"/>
      <p:cNvSpPr>
    <a:spLocks noGrp="1" noMove="1" noResize="1"/>
  </p:cNvSpPr>

Don’t expect that slides based on this will still have unmoveable placeholders. The lock parameters are not included when a slide is created from a layout. This locking ensures only that the layout remains the same, so when a slide is reset, it will always return to the correct format.

If the placeholders must remain in place on the slides, then you must first create the slide, then edit the XML before distributing the deck. For this, look in ppt/slides. The files are numbered in the order they appear in the presentation, so slide1.xml is usually the title. Here is the XML for a locked title placeholder:

<p:sp>
  <p:nvSpPr>
    <p:cNvPr id="2" name="Title 1"/>
      <p:cNvSpPr>
    <a:spLocks noGrp="1" noMove="1" noResize="1" noRot="1"/>
  </p:cNvSpPr>

When the user clicks on this, all the adjustment handles have a diagonal through them and the user is unable to change the shape size or position:

Locked Title Placeholder


Locking Graphics: Other Objects

By default, the picture and placeholders already include a p:locks or sp:locks tag, which is where we add the locking information. But what if you insert a text box on a layout for a legal disclaimer and want to make it ineditable? The text box XML initially looks like this:

<p:sp>
  <p:nvSpPr>
    <p:cNvPr id="7" name="TextBox 6"/>
    <p:cNvSpPr txBox="1"/>
    <p:nvPr userDrawn="1"/>
  </p:nvSpPr>

To lock this, we need to expand the <p:cNvSpPr txBox=”1″/> tag. In case it’s not obvious, to expand a closed tag, you must first delete the slash at the end that closes it. Then you create a new closing tag and put the <a:spLocks&gt> information between the two. The noTextEdit parameter should mean the text can’t be edited, and to a limited extent it does that. A single click on text box text does not put it in edit mode, as would normally happen. But if you double-click, you can still edit the text. So this parameter on its own is not enough to do the job, it will only provide a little discouragement.

<p:sp>
  <p:nvSpPr>
    <p:cNvPr id="7" name="TextBox 6"/>
    <p:cNvSpPr txBox="1">
      <a:spLocks noTextEdit="1"/>
    </p:cNvSpPr>
    <p:nvPr userDrawn="1"/>
  </p:nvSpPr>

Handy Trick: Grouping Tables with Other Shapes

Normally, you can’t group a table with other shapes in PowerPoint. That’s because tables include this markup by default:

<p:cNvGraphicFramePr>
  <a:graphicFrameLocks noGrp="1"/>
</p:cNvGraphicFramePr>

Change the 1 to a 0. Re-open the file in PowerPoint and group the table with other shapes. Easy!


Unlocking Graphics: Design Ideas

PowerPoint users who can’t afford a graphic designer love the Design Ideas feature in PowerPoint. As I write this, this feature is only available in Microsoft 365, the subscription version of Office. Microsoft uses AI technology to present the user with designs that Microsoft thinks are relevant to your content. Any company with branding guidelines should turn this feature off for their users.

Many Design Ideas have shapes that are locked in the XML. When Microsoft locks a shape, they throw the kitchen sink at it:

<a:spLocks noGrp="1" noRot="1" noChangeAspect="1" noMove="1" noResize="1" noEditPoints="1" noAdjustHandles="1" noChangeArrowheads="1" noChangeShapeType="1" noTextEdit="1"/>

Some of those locks don’t even make sense for most shapes, like noChangeArrowheads. The only lock they don’t apply is noSelect, avoiding the macro problem I mentioned earlier. To turn the lock shape into something you can copy, paste and revise, just delete all the attributes:

<a:spLocks />

Locking Graphics in Word and Excel

The principles are very similar to locking in PowerPoint. This can give you locked graphics and/or ineditable text boxes in both those programs without have to apply any document protection.

In Word, picture locks must be applied to the graphic frame that holds the picture, not the picture itself. This works:

<wp:cNvGraphicFramePr>
  <<a:graphicFrameLocks xmlns:a="http://schemas.
openxmlformats.org/drawingml/2006/main" noSelect="1" />
</wp:cNvGraphicFramePr>

This does not:

<pic:cNvPicPr>
  <<a:picLocks noSelect="1" />
</pic:cNvPicPr>

To lock a text box in Excel, expand:

<xdr:cNvSpPr txBox="1"/>

To:

<xdr:cNvSpPr txBox="1">
  <a:spLocks noSelect="1"/>
</xdr:cNvSpPr>

You can make the text in the box ineditable while still allowing it to be selected and moved:

<xdr:cNvSpPr txBox="1">
  <a:spLocks noTextEdit="1"/>
</xdr:cNvSpPr>

Locking Graphics: Gotchas and Exceptions

After a few months of practical testing, some real-life limitations on shape locking have become evident. Adding the noChangeAspect=”1″ has the same effect as checking the Lock aspect ratio option on the Size pane of the Format Shape dialog. But just as when you check this option manually, clicking on the shape and dragging the adjust handles will still distort the shape. On top of this, I found this page on MSDN: 2.1.1255 Part 4 Section 5.1.2.1.34, spLocks (Shape Locks). The pages states that “Office ignores attributes noChangeArrowheads and noRot when applied to a shape. PowerPoint additionally ignores the attribute noAdjustHandles when applied to a shape and noChangeShapeType when the converting the shape to a freeform.” So a user can circumvent noChangeAspect by dragging on the handles and you can’t prevent the handles from displaying either. Office simply doesn’t implement Microsoft’s own spec completely. There’s nothing you can do about this. It should be noted, that the accuracy of Microsoft’s information is not the best. Their statement that Office ignores noRot=”1″ when applied to a shape is not true, you can successfully prevent rotation with this parameter. You really have to test everything to really know what works and what doesn’t.


Locking Graphics: The Designer’s Responsibility

Powerful? Yes. But with power comes responsibility. Company presentation templates need to be revised, but after you lock items in XML, those shapes can no longer be revised through the program interface. So it’s essential that if you use these techniques, that you document your changes when you send the file to your users. Using these methods secretly to get repeat business from captive clients is dishonest and is definitely not a best practice.

Brandwares knows every detail about shape locking and we can do all this for you. Email me with the details of your requirements at production@brandwares.com.

12:56 pm

23 thoughts on “OOXML Hacking: Locking Graphics

      • I have Avopress Designer but unfortunately it has a number of serious flaws. So long as you use the xml it creates as just a starting point for further hacking it is fine, but if you need a product that you can rely on to produce the finished xml then I cannot recommend it.
        I have found ShapeLocker to be completely reliable though, it is just a shame that it can’t be made available for the Mac.

  1. I have a group consisting of several shapes and a textfield. I want to lock the group so that the text can be edited but the group can’t be decompiled, while the group can be moved around / resized etc. as whole. Is this possible via xml. Haven’t found a way yet.

    • Probably your “textfield” is a text box, since the only fields in PowerPoint are for the date, slide number and footer.

      As you probably already know, you can group shapes and text boxes in PowerPoint. After grouping, the text in the text box remains editable. Unfortunately, while there is a Shape Lock to prevent grouping, there isn’t one to prevent ungrouping. Groups of shapes do not obey the shape locks that individual shapes do, so even a noSelect=”1″ lock will not be honored by PowerPoint. I’m afraid you’re going to have to trust your users not to ungroup, because you can’t stop them.

  2. Hello, This is a great article. Is there a command similar to noSelect which will allow VBA commands to run. For example a combination of noMove, noRotate, noResize and noDelete but I haven’t found a no delete command. Does something exist?
    Thanks

    • I think you’re asking if you can apply these attributes by VBA. The only lock that is in the VBA object model is noChangeAspect, which you can apply with a command like ActivePresentation.Slides(1).Shapes(1).LockAspectRatio = msoTrue. This lock only applies when you are changing the shape size numerically via height and width fields. It’s easily defeated by dragging the shape handles. If I have misunderstood your question, please clarify.

  3. Is there a way to prevent the content placeholders to adjust pictures. Pictures should work like with a picture placeholder. I tried
    “<” p:cNvSpPr”>”
    “<” a:spLocks noGrp=”1″ noResize=”1″ noAdjustHandles=”1″ noChangeAspect=”1″ /”>”
    “<” /p:cNvSpPr”>”

    but nothing of it is working.
    Thx a lot for your help!

    • Shape locks cannot make a Content placeholder act like a Picture placeholder. That’s determined by PowerPoint’s programming. Is there some reason you can’t just use a Picture placeholder?

      As mentioned in the article, shape locks on layout placeholders are not inherited by the slides made from them, so their only real value is protecting the arrangement of the slide layout from tampering.

  4. It appears that in the current version of Word (both Windows and Mac), the noTextEdit attribute for a text frame is not recognized. I’ve tried setting in both the a:graphicFrameLocks and a:spLocks elements with no luck. Using noSelect will prevent text editing on the Mac, but not on Windows. Unless I’m missing something, there doesn’t appear to be a foolproof way to lock down text in a text frame that works on both platforms.

    • Thanks for writing, I’ve been meaning to update that part of the article. The noTextEdit parameter only prevents a single click from putting the text box or placeholder into edit mode. A double-click will still make text editing possible, on both Windows and Mac. So it only provides a little discouragement instead of a complete solution. I’ve updated the article with this information.

  5. This is great.
    I’m locking objects in PowerPoint with this method for years 🙂

    But I’m struggling to lock a table object in PowerPoint.
    The hole table object can be looked (e.g. noResize) but I couldn’t figure out yet how to lock cells and rows.
    Is there way to lock cells, rows, especially NoResize?

    THANKS!

  6. John, could you clarify how to access the XML of a PowerPoint pptx? The language in your instructions says to “expand” the file, but it’s unclear how exactly to do that. Once I can access the XML, then rest of your instruction seem very straightforward. Thank you!

  7. This worked great for a graphic in my word doc (Mac), but although the graphic can’t be clicked on and selected, it can still be grabbed when highlighting all of the text, and then deleted along with the text. I take it there’s no fool-proof way to prevent deletion? Thanks.

    • For a scenario like yours, you would have to apply some protection to the document to prevent deletion. Using Protected Area Exceptions, you can make some areas of a document editable while leaving the paragraphs containing the images protected, so the text and image can’t be deleted.

  8. Pingback: How To Lock Images In PowerPoint – 2 Easiest Methods! – PPT Central

  9. Hi,
    I followed the instructions but it did not work on office 2019 pro plus.
    Could you give an advise on this matter?

    • All the steps in the article have been tested in all modern versions of Office. You should check your XML for errors.

      If any of the advice in these articles are too complicated for you to implement, you can always hire us to do it for you.

Leave a Reply

*Required fields. Your email address will not be published.

Posting XML? To enter XML code, please replace all less than signs "<" with "&lt;" and greater than signs ">" with "&gt;". Otherwise, Wordpress will strip them out and you will see only a blank area where your code would have appeared.