我一直在尝试在 OneNote 中创建一个新页面来显示渲染的 PDF 页面,我的代码如下
$n = [System.Guid]::NewGuid().ToString();
$content = @"
<!DOCTYPE html>
<html>
<head>
<title>$n</title>
</head>
<body>
<img data-render-src =`"name:$n`" />
</body>
</html>
"@
$fileBytes = [System.IO.File]::ReadAllBytes($FilePath);
$fileEnc = [System.Text.Encoding]::GetEncoding('ISO-8859-1').GetString($fileBytes);
$boundary = [System.Guid]::NewGuid().ToString();
$LF = "`r`n";
$bodyLines = (
"--$boundary`r`nContent-Disposition: form-data; name=`"Presentation`"",
"Content-Type: text/html$LF",
$content,
"--$boundary`r`nContent-Disposition: form-data; name=`"$n`"",
"Content-Type: application/pdf$LF",
$fileEnc,
"--$boundary--$LF"
) -join $LF
$r = Invoke-RestMethod -Headers @{Authorization = "Bearer $($myAccessToken.AccessToken)"; Boundary = $boundary } `
-Uri "https://graph.microsoft.com/v1.0/groups/$group/onenote/sections/$sectionId/pages" `
-Method POST `
-ContentType "multipart/form-data; boundary=`"$boundary`"" -Body $bodyLines
该代码有时可以正常工作。没有理由或押韵,有时页面会像我想要的那样使用渲染的 pdf 创建。其他时候,该页面将使用文件附件创建。该文件是正确的,可以从一个注释中下载和打开。