Skip to content

Enhancement (config): Add option $mergeInkStrokes to merge strokes of pen/hand written drawings into a single image - #203

Open
El1as42 wants to merge 2 commits into
theohbrothers:masterfrom
El1as42:enhancement/config-add-option-mergeinkstrokes-to-merge-strokes-of-pen-hand-written-drawings-into-a-single-image
Open

El1as42 wants to merge 2 commits into
theohbrothers:masterfrom
El1as42:enhancement/config-add-option-mergeinkstrokes-to-merge-strokes-of-pen-hand-written-drawings-into-a-single-image

Conversation

@El1as42

@El1as42 El1as42 commented Oct 13, 2026

Copy link
Copy Markdown

Closes #200

OneNote exports each stroke of a pen/hand written drawing (InkDrawing) to the .docx as a separate image, without its position. So in the markdown, the strokes of a drawing are lined up next to each other, and strokes drawn on an image (e.g. annotations on a pasted lecture slide) end up below that image. See Known Issues in README.md.

Changes

  • New config option $mergeInkStrokes: 1 keeps each stroke as a separate image (default, existing behavior), 2 merges the strokes:
    • The strokes of each drawing are rendered into a single image that preserves the position of each stroke. The strokes are read from the page content (Ink Serialized Format), which contains their positions, and rendered with WPF. So this requires Windows PowerShell 5.1 or PowerShell 7.0 on Windows, which the conversion needs anyway for OneNote.
    • Strokes drawn on an image are drawn on that image, in the image's resolution. Images in outlines have no position in the page content, so their position is calculated from the outline's position and the heights of the images and empty paragraphs before or after the image, and checked against the outline's height. If it cannot be determined, the strokes are merged into a separate image instead.
    • The stroke images in the .docx are identified by their size (the stroke's size plus a padding of about 8.25 points), in page order. Stroke images that cannot be identified are kept as they are.
  • README.md: Known Issues mention the option.

Tests: unit tests for the new functions and the config option (rendering tests are skipped on non-Windows). Unit tests pass on Windows PowerShell 5.1 and PowerShell 7.0. In this repo's CI (run on my fork), all jobs that can currently run pass: Windows PowerShell 5.1 (windows-2022) and PowerShell 7.1 to 7.4. The other jobs currently fail for any PR, before checkout: the windows-2019 runner image was retired, and the PowerShell 6.0 to 7.0 container images are too old for actions/checkout (GLIBC_2.28' not found). Also tested on real notebook pages: the calculated image positions matched OneNote's own PDF export within 0.2 points, and the pages convert identically on both PowerShell versions.

🤖 Generated with Claude Code

El1as42 and others added 2 commits October 12, 2026 22:19
…of pen/hand written drawings into a single image

OneNote exports each stroke of a pen/hand written drawing (`InkDrawing`) as a separate image in the `.docx`, without its position. In the converted markdown, the strokes of a drawing end up lined up next to each other.

`$mergeInkStrokes = 2` renders the strokes of each drawing into a single image, preserving the position of each stroke:
- The strokes are read from the page content (Ink Serialized Format), which contains their positions on the page, and are rendered using WPF.
- The stroke images in the `.docx` are identified by their size, which is the size of the stroke plus a padding of about 8.25 points, in the same order as in the page content.
- Each group of adjacent stroke image references in the markdown is replaced with a single image.

The default `$mergeInkStrokes = 1` keeps the existing behavior.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…eInkStrokes = 2`

Strokes drawn on an image, e.g. annotations on a pasted lecture slide, were merged into a separate image below the image they were drawn on.

Now such strokes are rendered on a copy of the image they were drawn on, in the image's resolution:
- Images in outlines have no position in the page content. Their position is determined from the outline's position and the heights of the paragraphs preceding or following the image, if those are known, i.e. images and empty paragraphs (a single line in the paragraph style's font). If all heights are known, they must add up to the outline's height, or else no position is determined.
- The images in the `.docx` are identified by their size, in the same order as in the page (top to bottom).
- A stroke is drawn on an image if its center is within the image. The image is extended if strokes exceed it.
- Strokes that are not drawn on an image are merged into a single image as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Option to merge the strokes of pen/hand written drawings into a single image

1 participant