public void AddPage(PDFPage page) { page.Parent = this; _pages.Add(page); }
public PDFPage AddPage() { var pdfPage = new PDFPage(pdfBuilder); return(pdfPage); }
/// <summary> /// Creates a PDF page given the main PDF document and a list of rows. /// </summary> /// <param name="doc">PDFDocument: the main PDF object.</param> /// <param name="tableWidth">Width of the DataTable (needed for scaling the table to fit inside the page).</param> /// <param name="columns">Columns to show inside the PDF.</param> /// <param name="rows">Rows to show inside the PDF.</param> /// <param name="title">Page title, can be on several lines.</param> /// <returns>The PDF page created.</returns> private static PDFPage CreatePage(PDFDocument doc, double tableWidth, List<PDFGraphicObject> columns, List<PDFGraphicObject> rows, List<string> title) { // Scaling double scaling = (PageLayout.Width - (PageLayout.RightMargin + PageLayout.LeftMargin)) / tableWidth; if (scaling > 1) { scaling = 1; } //// // Top position double topXPos = (PageLayout.Width / 2) - (tableWidth / 2); if (topXPos < PageLayout.LeftMargin) { topXPos = PageLayout.LeftMargin; } double topYPos = PageLayout.Height - PageLayout.TopMargin; //// PDFContentStream contentStream = new PDFContentStream(); doc.AddChild(contentStream); double lineYPos = 0; // Page title if any List<PDFGraphicObject> fakeList = new List<PDFGraphicObject>(); foreach (string line in title) { // Title position double lineWidth = FontMetrics.GetTextWidth(line, PDFWriter.TitleFont); double lineXPos = (PageLayout.Width / scaling / 2) - (lineWidth / 2); if (lineXPos < PageLayout.LeftMargin) { lineXPos = PageLayout.LeftMargin; } //// fakeList.Add(CreatePageTitle(line, lineXPos, lineYPos)); lineYPos -= Table.RowHeight; } PDFScaling titleScaling = new PDFScaling(fakeList, scaling, 0, topYPos); contentStream.AddChild(titleScaling); //// // Rows and columns should be below the title topYPos -= Table.RowHeight * (title.Count + 1) * scaling; // Rows PDFScaling rowsScaling = new PDFScaling(rows, scaling, topXPos, topYPos); contentStream.AddChild(rowsScaling); //// // Columns PDFScaling columnsScaling = new PDFScaling(columns, scaling, topXPos, topYPos); contentStream.AddChild(columnsScaling); //// PDFPage page = new PDFPage(); page.ContentStream = contentStream; page.Fonts = PDFWriter.Fonts; doc.AddChild(page); return page; }