1param([Parameter(Mandatory=$true)][string]$Root, [Parameter(Mandatory=$true)][string]$CloneHost)
2# A page of pictures and files, in an outline and on the page, for tagging, linking and OCR
3# by hand in the clone: notebook/photo.png, notebook/ocr.png and notebook/notes.txt ride along
4# with the section.
5Set-StrictMode -Version Latest
6$ErrorActionPreference = 'Stop'
7& "$PSScriptRoot\cold-current.ps1" -Root $Root -CloneHost $CloneHost
8$namespace = 'http://schemas.microsoft.com/office/onenote/2010/onenote'
9$notebook = Join-Path $Root 'notebook'
10$data = { param($name) [Convert]::ToBase64String([IO.File]::ReadAllBytes((Join-Path $notebook $name))) }
11$file = Join-Path $notebook 'notes.txt'
12$app = New-Object -ComObject OneNote.Application
13$notebookId = ''
14try {
15 $app.OpenHierarchy($notebook, '', [ref]$notebookId, 0)
16 $sectionId = ''
17 $app.OpenHierarchy('files.one', $notebookId, [ref]$sectionId, 0)
18 $pageId = ''
19 $app.CreateNewPage($sectionId, [ref]$pageId, 0)
20 $body = '<one:Title><one:OE><one:T><![CDATA[Pictures and files]]></one:T></one:OE></one:Title>'
21 $body += '<one:Outline><one:Position x="36" y="86"/><one:Size width="300" height="200"/><one:OEChildren>'
22 $body += '<one:OE><one:T><![CDATA[Picture below]]></one:T></one:OE>'
23 $body += '<one:OE><one:Image><one:Size width="120" height="90"/><one:Data>' + (& $data 'photo.png') + '</one:Data></one:Image></one:OE>'
24 $body += '<one:OE><one:InsertedFile pathSource="' + $file + '" preferredName="notes.txt"/></one:OE>'
25 $body += '<one:OE><one:T><![CDATA[Text after]]></one:T></one:OE>'
26 $body += '</one:OEChildren></one:Outline>'
27 $body += '<one:Image><one:Position x="400" y="86"/><one:Size width="120" height="90"/><one:Data>' + (& $data 'photo.png') + '</one:Data></one:Image>'
28 $body += '<one:InsertedFile pathSource="' + $file + '" preferredName="notes.txt"><one:Position x="560" y="86"/></one:InsertedFile>'
29 $body += '<one:Image><one:Position x="400" y="260"/><one:Size width="320" height="80"/><one:Data>' + (& $data 'ocr.png') + '</one:Data></one:Image>'
30 $xml = '<one:Page xmlns:one="' + $namespace + '" ID="' + $pageId + '">' + $body + '</one:Page>'
31 $app.UpdatePageContent($xml, [DateTime]::MinValue, 1, $true)
32 $app.SyncHierarchy($notebookId)
33} finally {
34 [void][Runtime.InteropServices.Marshal]::FinalReleaseComObject($app)
35 [GC]::Collect()
36 [GC]::WaitForPendingFinalizers()
37}