Partager via


OneNote: Positioning Imported Content on Right-To-Left Pages

Here’s something I found in a code comment in the OneNoteImporter managed assembly source code. It applies to both the OneNoteImporter and the SimpleImporter API itself, and I haven’t seen it documented anywhere else, so I thought I’d pass it on here.

It concerns positioning objects on OneNote pages that read right-to-left. If you’ve used either the OneNoteImporter and the SimpleImporter API itself, you know you can use the RTL attribute of the <Page> element to set whether you want the page to read right-to-left or vice versa. You can then set the x and y attributes of an object’s <Position> element to determine where you want the object placed on the page. (If you’re using the OneNoteImporter assembly, then set the RTL property of the Page object, and the X and Y properties of the Position object, respectively.)

OneNote places the objects it imports onto the page based on absolute coordinates, expressed in points. Turns out that the coordinates differ, based on whether the page reads left-to-right or right-to-left.

Here’s how it works:

If you set the page to read left-to-right, then the origin (that is, the place there both x and y equal 0) is the upper left hand corner of the OneNote page. X coordinates advance in positive numbering from the left to the right; y coordinates advance in positive numbering horizontally down the page. Pretty straightforward.

Things get a little more complicated when you set the page to read right-to-left. In this case, the origin (0,0) is the upper right hand corner. But the x and y coordinates still advance in positive numbering in the same directions: x to the left, y horizontally down the page. So for any objects on a right-to-left OneNote page, the x coordinate will actually be a negative number. Indeed, the x coordinates are increasingly negative as you to the left across the page.

Also remember that the x coordinate refers to the upper left corner of the object, regardless of the direction in which the OneNote page reads.

So let’s look at an example. The figure below represents a OneNote page, set to read right-to-left. For the sake of argument, assume the page is 600 pixels wide by 750 pixels long (I have no idea what the default size of a OneNote page is.) In this case, the upper left corner coordinates are (-600, 0); the lower left corner coordinates are (-600, 750). The (x, y) coordinates of the object A refer to the position of the upper left corner, and so would be (-400, 100), and not (-250, 100), which is the object’s upper right corner.

Make sense?

 One last thing: you should also consider page margins when positioning an object on the page. While (0,0) is the absolute origin of the page, depending on user’s preference, their upper left hand corner margin should be at (½”,½”), or (36,36) in points. Which is (-36,36) if the page reads right-to-left.