Skip to content

Commit

Permalink
First release
Browse files Browse the repository at this point in the history
  • Loading branch information
faisal-fawad committed Sep 6, 2023
1 parent ec0dbd1 commit 3857a22
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions PrintNoteAddin/AddIn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ public void AddInButtonClicked(IRibbonControl control)
}

// Gets the max height and width based off of the contents of the page
float paperWidth = (float)215.9 /* 8.5in */;
float paperHeight = (float)279.4 /* 11in */;
float mmHeight;
float mmWidth;
if (heights.Count > 0 & widths.Count > 0)
Expand All @@ -151,31 +153,25 @@ public void AddInButtonClicked(IRibbonControl control)
}
else
{
mmHeight = (float)279.4 /* 11in */;
mmWidth = (float)215.9 /* 8.5in */;
mmHeight = paperHeight;
mmWidth = paperWidth;
}

// Make sures the height meets the minimum requirement
if (mmHeight < 279.4 /* 11in - Letter height */)
if (mmHeight < paperHeight /* 11in - Letter height */)
{
mmHeight = (float)279.4;
mmHeight = paperHeight;
}

// OneNote scales content to paper width using a ratio, which can be used to obtain the new height before printing
if (mmWidth > 215.9 /* 8.5in - Letter width */)
{
float ratio = (float)215.9 / (mmWidth - (float)12.7 /* .5in for safety */);
mmHeight = ratio * mmHeight;
}
else // For content smaller than the paper width, a scalar constant is used to obtain the new height before printing
{
float ratio = (float)1.4;
mmHeight = ratio * mmHeight;
}
float ratio = (paperWidth + (float)12.7 /* .5in for safety */) / mmWidth;
if (ratio > 1.4) { ratio = (float)1.4; /* Upper limit for ratio */ }
else if (ratio < 0.8) { ratio += (ratio / 8); /* Small ratios need a readjustment to fit the page */ }
mmHeight *= ratio;

// Adds a custom paper size named PrintNote - needs administrative permissions
// It may be possible to use the OneNote Publish feature with a IMsoDocExporter interface to avoid the use of administrative permissions
AddCustomPaperSize("Microsoft Print to PDF", "PrintNote", (float)215.9, mmHeight);
AddCustomPaperSize("Microsoft Print to PDF", "PrintNote", paperWidth, mmHeight);
}
catch (Exception e)
{
Expand Down

0 comments on commit 3857a22

Please sign in to comment.