Glorious! That works a treat.
For my particular case, after calling RenderDocument() on my MigraDoc.Rendering.PdfDocumentRenderer instance, I call a custom PostRenderPdf() method that passes the PdfDocumentRenderer instance, for the purpose of applying any PDFSharp operations to the rendered MigraDoc document.
Poor error handling not withstanding, here's what I ended up doing.
Code:
public static void PostRenderPdf(PdfDocumentRenderer pdfDocumentRenderer)
{
double startX = 0;
double startY = 0;
double width = 0;
double height = 0;
double panelBorderWidth = 0.28;
// page numbering starts from 1
var renderInfos = pdfDocumentRenderer.DocumentRenderer.GetRenderInfoFromPage(1);
if (renderInfos != null && renderInfos.Length > 0)
{
for (int g = 0; g < renderInfos.Length; g++)
{
switch (renderInfos[g].DocumentObject.Tag as string)
{
case "JobMatchPanel":
startX = renderInfos[g].LayoutInfo.ContentArea.X - panelBorderWidth;
startY = renderInfos[g].LayoutInfo.ContentArea.Y - panelBorderWidth;
width = renderInfos[g].LayoutInfo.ContentArea.Width + (panelBorderWidth * 2);
height = renderInfos[g].LayoutInfo.ContentArea.Height + (panelBorderWidth * 2);
break;
}
}
}
var page = pdfDocumentRenderer.PdfDocument.Pages[0];
var gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Prepend);
var rect = new XRect(startX, startY, width, height);
var ellipseSize = new Size(9, 9);
var color = new XSolidBrush(XColor.FromArgb(240, 240, 240));
gfx.DrawRoundedRectangle(color, rect, ellipseSize);
var pen = new XPen(XColor.FromArgb(128, 128, 128), 1);
gfx.DrawRoundedRectangle(pen, rect, ellipseSize);
}
The intention is to find the table that has been given a tag "JobMatchPanel" on the first page of my document, and apply a bordered panel effect that is 0.28 points around the original table.
There are things that probably could be done better (like build the anticipated border into the table itself, so I don't have to adjust the rectangle dimensions, and leave the loop early, once I have located the panel, since it's the only one in the document).
However, it's a good start, and DocumentObject Tags are now my friend.
Thank you for your help, Thomas.