Explaining an easy hurdle to overcome with the Page Expander Powertoy for OneNote
One of the reasons it took me too long to finish the Page Expander powertoy (I haven’t used the Adapx pen in several months) was a problem I had when trying to update the page XML after setting the page size I wanted. I alluded to this on Monday when I wrote "I could have done this with OMSpy - but I hit some problems with that that I want to explain later."
Here's what I meant. You can do this on your machine as well if you want. Just be sure to back up your .one files first - the potential for damage here is small, but you probably don't want to take chances. Always have a backup!
First, I started OMSpy and updated the page content with the XML from the page I wanted to modify. Since I knew the page was going to have ink on it, I would need the binary data for importing the page back into OneNote. So I was sure to set OMSpy to export the binary data, like this:
Use the hierarchy tree on the left, browse to the page you want to modify and Get Content (it has a blue highlight around the button in the image above).
Using OMSpy, here's what the XML looked like for a 5x8 page with the node I wanted to change in blue:
And here's what I wanted, with a critical callback ID circled in red:
So what I was doing was removing the page size node:
<one:PageSize>
<one:Orientation landscape="false" />
<one:Dimensions width="360.0" height="432.0" />
<one:Margins top="36.0" bottom="36.0" left="72.0" right="72.0" />
</one:PageSize>
And replacing it with this:
<one:PageSize>
<one:Automatic />
</one:PageSize>
If you haven't tried this, you can cut and paste the text in OMSpy yourself. Then click the Update Content button and OneNote will try to replace the existing XML of the page with what you have in OMSpy. This should work.
No let's jump back to the error I was seeing. Do all the steps above, but when getting the content with OMSpy, do NOT check the box for "Export Binary Data." Now when you get to the step to try and update the page content, you should see this error (if there is ink or any other binary data on the page):
Exception from HRESULT: 0x80042000
Look back to to the callback ID on the outline which contains binary data circled in red above. That is the cause of the problem. Since the ID was trying to be set when I updated the page XML, OneNote rejected the updated XML since it did not include the binary data. The hurdle I needed to overcome was getting the binary data when exporting the XML from OneNote.
The fix for the error in this case was pretty simple in my code. I changed from this line of code:
onApp.GetPageContent(strActivePageID, out origPageXML, OneNote.PageInfo.piBasic );
To this:
onApp.GetPageContent(strActivePageID, out origPageXML, OneNote.PageInfo.piBinaryData );
And now the addin can set the page size to Automatic like I wanted.
That's a lot of work to save 4 clicks, but I think it's worth it. I hope you do too!
Questions, comments, concerns and criticisms always welcome,
John
Comments
- Anonymous
March 12, 2009
PingBack from http://www.clickandsolve.com/?p=21719