Hi
I created pdf file using MigraDoc.
Initially i used the PdfDocumentRenderer class for rendering.. it's work's fine.
later i added the watermark for this and i changed rendering Document using MigraDoc.Rendering.DocumentRenderer class, based on the one of the thread in Pdfsharp forums.
Here water mark is displaying nicely.
1)Image is not displaying
2)Entire page is rotating
what is the mistake in my code?
here is my code...
Code:
Document document = new Document();
document.UseCmykColor = true;
document.DefaultPageSetup.PageFormat = PageFormat.A4;
document.DefaultPageSetup.LeftMargin = 30;
document.DefaultPageSetup.RightMargin = 30;
Section section1 = document.AddSection();
string headerImage = Path.GetFullPath(".") + "\\Resources\\rccPdfLogo.png";
MigraDoc.DocumentObjectModel.Shapes.Image image = section1.AddImage(headerImage);
image.LockAspectRatio = true;
image.RelativeVertical = RelativeVertical.Line;
image.RelativeHorizontal = RelativeHorizontal.Margin;
image.Top = ShapePosition.Top;
image.Left = ShapePosition.Center;
image.Width = document.DefaultPageSetup.PageWidth - (document.DefaultPageSetup.RightMargin +document.DefaultPageSetup. LeftMargin);
image.WrapFormat.Style = WrapStyle.TopBottom;
Paragraph pgDocTitle = section1.AddParagraph();
pgDocTitle.Format.Alignment = ParagraphAlignment.Left;
pgDocTitle.Elements.AddLineBreak();
pgDocTitle.Format.Font.ApplyFont(fontTitles);
pgDocTitle.AddFormattedText("Your patient matches the below patient profile which the panel of experts have assessed", TextFormat.Bold | TextFormat.Underline);
MigraDoc.Rendering.DocumentRenderer docR = new DocumentRenderer(document);
docR.PrepareDocument();
PdfDocument document1 = new PdfDocument();
if (docR.FormattedDocument.PageCount > 0)
{
int pageCount = docR.FormattedDocument.PageCount;
XFont waterfont = new XFont("Arial", 30);
string watermark = "For academic use only";
for (int i = 1; i < pageCount + 1; i++)
{
PdfPage newpage = document1.AddPage();
newpage.Height = XUnit.FromCentimeter(29.7).Point;
newpage.Width = XUnit.FromCentimeter(21.5).Point;
XGraphics gfx = XGraphics.FromPdfPage(newpage, XGraphicsPdfPageOptions.Append, XPageDirection.Downwards);
XSize size = gfx.MeasureString(watermark, waterfont);
gfx.TranslateTransform(newpage.Width / 2, newpage.Height / 2);
gfx.RotateTransform(-Math.Atan(newpage.Height / newpage.Width) * 90 / Math.PI);
gfx.TranslateTransform(-newpage.Width / 2, -newpage.Height / 2);
XGraphicsPath path = new XGraphicsPath();
path.AddString(watermark, waterfont.FontFamily, XFontStyle.BoldItalic, 30,
new XPoint((newpage.Width - size.Width) / 2, (newpage.Height - size.Height) / 2),
XStringFormats.Default);
XPen pen = new XPen(XColor.FromArgb(50, 139, 131, 120), 1);
XBrush brush = new XSolidBrush(XColor.FromArgb(50, 250, 250, 250));
gfx.DrawPath(pen, brush, path);
docR.RenderPage(gfx, i);
}
}
string filename = Path.GetFullPath(".") + "\\PDFImages\\RccToolKit.pdf";
document1.Save(filename);