private void DrawCover(PdfSection section, PdfMargins margin) { section.PageNumber = new PdfPageNumber(); section.PageNumber.NumberStyle = PdfNumberStyle.LowerRoman; section.PageNumber.Prefix = "cover "; section.PageSettings.Size = PdfPageSize.A4; section.PageSettings.Margins.All = 0; PdfPageBase page = section.Pages.Add(); DrawPageHeaderAndFooter(page, margin, true); //Reference content PdfBrush brush1 = PdfBrushes.LightGray; PdfBrush brush2 = PdfBrushes.Blue; PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 8f)); PdfStringFormat format = new PdfStringFormat(); format.MeasureTrailingSpaces = true; String text1 = "(All text and picture from "; String text2 = "Wikipedia"; String text3 = ", the free encyclopedia)"; float x = 0, y = 10; x = x + margin.Left; y = y + margin.Top; page.Canvas.DrawString(text1, font1, brush1, x, y, format); x = x + font1.MeasureString(text1, format).Width; page.Canvas.DrawString(text2, font1, brush2, x, y, format); x = x + font1.MeasureString(text2, format).Width; page.Canvas.DrawString(text3, font1, brush1, x, y, format); //Cover PdfBrush brush3 = PdfBrushes.Black; PdfBrush brush4 = new PdfSolidBrush(new PdfRGBColor(0xf9, 0xf9, 0xf9)); PdfImage image = PdfImage.FromFile(@"..\..\..\..\..\..\Data\SciencePersonificationBoston.jpg"); String text = Pagination.Properties.Resources.ImageDescription; float r = image.PhysicalDimension.Height / image.Height; PdfPen pen = new PdfPen(brush1, r); SizeF size = font1.MeasureString(text, image.PhysicalDimension.Width - 2); PdfTemplate template = new PdfTemplate(image.PhysicalDimension.Width + 4 * r + 4, image.PhysicalDimension.Height + 4 * r + 7 + size.Height); template.Graphics.DrawRectangle(pen, brush4, 0, 0, template.Width, template.Height); x = y = r + 2; template.Graphics.DrawRectangle(brush1, x, y, image.PhysicalDimension.Width + 2 * r, image.PhysicalDimension.Height + 2 * r); x = y = x + r; template.Graphics.DrawImage(image, x, y); x = x - 1; y = y + image.PhysicalDimension.Height + r + 2; template.Graphics.DrawString(text, font1, brush3, new RectangleF(new PointF(x, y), size)); float x1 = (page.Canvas.ClientSize.Width - template.Width) / 2; float y1 = (page.Canvas.ClientSize.Height - margin.Top - margin.Bottom) * (1 - 0.618f) - template.Height / 2 + margin.Top; template.Draw(page.Canvas, x1, y1); //Title format.Alignment = PdfTextAlignment.Center; PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 24f, FontStyle.Bold)); x = page.Canvas.ClientSize.Width / 2; y = y1 + template.Height + 10; page.Canvas.DrawString(Pagination.Properties.Resources.Title, font2, brush3, x, y, format); }
private void DrawCover(PdfSection section, PdfMargins margin) { section.PageNumber = new PdfPageNumber(); section.PageNumber.NumberStyle = PdfNumberStyle.LowerRoman; section.PageNumber.Prefix = "cover "; section.PageSettings.Size = PdfPageSize.A4; section.PageSettings.Margins.All = 0; PdfPageBase page = section.Pages.Add(); DrawPageHeaderAndFooter(page, margin, true); //refenrence content PdfBrush brush1 = PdfBrushes.LightGray; PdfBrush brush2 = PdfBrushes.Blue; PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 8f)); PdfStringFormat format = new PdfStringFormat(); format.MeasureTrailingSpaces = true; String text1 = "(All text and picture from "; String text2 = "Wikipedia"; String text3 = ", the free encyclopedia)"; float x = 0, y = 10; x = x + margin.Left; y = y + margin.Top; page.Canvas.DrawString(text1, font1, brush1, x, y, format); x = x + font1.MeasureString(text1, format).Width; page.Canvas.DrawString(text2, font1, brush2, x, y, format); x = x + font1.MeasureString(text2, format).Width; page.Canvas.DrawString(text3, font1, brush1, x, y, format); //cover PdfBrush brush3 = PdfBrushes.Black; PdfBrush brush4 = new PdfSolidBrush(new PdfRGBColor(0xf9, 0xf9, 0xf9)); PdfImage image = PdfImage.FromFile(@"..\..\..\..\..\..\Data\SciencePersonificationBoston.jpg"); String text = Pagination.Properties.Resources.ImageDescription; float r = image.PhysicalDimension.Height / image.Height; PdfPen pen = new PdfPen(brush1, r); SizeF size = font1.MeasureString(text, image.PhysicalDimension.Width - 2); PdfTemplate template = new PdfTemplate(image.PhysicalDimension.Width + 4 * r + 4, image.PhysicalDimension.Height + 4 * r + 7 + size.Height); template.Graphics.DrawRectangle(pen, brush4, 0, 0, template.Width, template.Height); x = y = r + 2; template.Graphics.DrawRectangle(brush1, x, y, image.PhysicalDimension.Width + 2 * r, image.PhysicalDimension.Height + 2 * r); x = y = x + r; template.Graphics.DrawImage(image, x, y); x = x - 1; y = y + image.PhysicalDimension.Height + r + 2; template.Graphics.DrawString(text, font1, brush3, new RectangleF(new PointF(x, y), size)); float x1 = (page.Canvas.ClientSize.Width - template.Width) / 2; float y1 = (page.Canvas.ClientSize.Height - margin.Top - margin.Bottom) * (1 - 0.618f) - template.Height / 2 + margin.Top; template.Draw(page.Canvas, x1, y1); //title format.Alignment = PdfTextAlignment.Center; PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 24f, FontStyle.Bold)); x = page.Canvas.ClientSize.Width / 2; y = y1 + template.Height + 10; page.Canvas.DrawString(Pagination.Properties.Resources.Title, font2, brush3, x, y, format); }