static void SamplePage2(PdfDocument document)
{
PdfPage page = document.AddPage();
XGraphics gfx = XGraphics.FromPdfPage(page);
// HACK²
gfx.MUH = PdfFontEncoding.Unicode;
gfx.MFEH = PdfFontEmbedding.Default;
// Create document from HalloMigraDoc sample
Document doc = HelloMigraDoc.Documents.CreateDocument();
// Create a renderer and prepare (=layout) the document
MigraDoc.Rendering.DocumentRenderer docRenderer = new DocumentRenderer(doc);
docRenderer.PrepareDocument();
// For clarity we use point as unit of measure in this sample.
// A4 is the standard letter size in Germany (21cm x 29.7cm).
XRect A4Rect = new XRect(0, 0, A4Width, A4Height);
int pageCount = docRenderer.FormattedDocument.PageCount;
for (int idx = 0; idx < pageCount; idx++)
{
XRect rect = GetRect(idx);
// Use BeginContainer / EndContainer for simplicity only. You can naturaly use you own transformations.
XGraphicsContainer container = gfx.BeginContainer(rect, A4Rect, XGraphicsUnit.Point);
// Draw page border for better visual representation
gfx.DrawRectangle(XPens.LightGray, A4Rect);
// Render the page. Note that page numbers start with 1.
docRenderer.RenderPage(gfx, idx + 1);
// Note: The outline and the hyperlinks (table of content) does not work in the produced PDF document.
// Pop the previous graphical state
gfx.EndContainer(container);
}
}