Exemplo n.º 1
0
        private static void AddWaterMark(PdfGraphics graphics, DrawText drawText, PointF pointF)
        {
            SizeF waterTextSize = graphics.MeasureString(drawText.Text, drawText.FontText, PdfStringFormat.GenericDefault, DrawIngDpi, DrawIngDpi);

            graphics.RotateTransform(degree);//55 vertical letter//40horizontar letter//65LegarV//30 LegalH
            graphics.DrawString(drawText.Text, drawText.FontText, drawText.SolidBrush, pointF);
        }
Exemplo n.º 2
0
    protected float DocxAddPageHeader(PdfGraphics g, int pagenumber, string projtitle, string datafile, string selecteddata)
    {
        float      y       = 10f;
        float      x       = 10f;
        float      x_right = 760f;
        float      yoffset = 4f;
        SolidBrush black   = (SolidBrush)Brushes.Black;

        using (Font font16 = new Font("Arial", 16, FontStyle.Bold | FontStyle.Underline))
            using (Font font12 = new Font("Segoe UI", 12))
                using (Font font = new Font("Segoe UI", 10))
                {
                    string page = String.Format("pg. {0}", pagenumber.ToString());
                    string s1   = projtitle;
                    string s2   = datafile;
                    string s3   = selecteddata;


                    string user_time = String.Format("{0}     {1:MM/dd/yy H:mm}", _creator_netid, System.DateTime.Now);


                    //page number
                    g.DrawString(page, font, black, x_right - (g.MeasureString(page, font).Width), 10);
                    //project title
                    g.DrawString(s1, font16, black, x, y);
                    y = y + g.MeasureString(s1, font16).Height - yoffset;
                    //file, user, date
                    g.DrawString(s2, font12, black, x, y);
                    float x2 = x_right - g.MeasureString(user_time, font).Width;
                    g.DrawString(user_time, font, black, x2, y);
                    y = y + g.MeasureString(s2, font12).Height - yoffset;
                    //Worksheet & filter
                    g.DrawString(s3, font, black, x, y);
                    y = y + g.MeasureString(s3, font).Height - yoffset;
                }


        return(y);
    }
        static void AddGraphics(PdfDocumentProcessor processor, string text, SolidBrush textBrush)
        {
            IList <PdfPage> pages = processor.Document.Pages;

            for (int i = 0; i < pages.Count; i++)
            {
                PdfPage page = pages[i];
                using (PdfGraphics graphics = processor.CreateGraphics()) {
                    SizeF actualPageSize = PrepareGraphics(page, graphics);
                    using (Font font = new Font("Segoe UI", 20, FontStyle.Regular)) {
                        SizeF  textSize    = graphics.MeasureString(text, font, PdfStringFormat.GenericDefault, DrawingDpi, DrawingDpi);
                        PointF topLeft     = new PointF(0, 0);
                        PointF bottomRight = new PointF(actualPageSize.Width - textSize.Width, actualPageSize.Height - textSize.Height);
                        graphics.DrawString(text, font, textBrush, topLeft);
                        graphics.DrawString(text, font, textBrush, bottomRight);
                        graphics.AddToPageForeground(page, DrawingDpi, DrawingDpi);
                    }
                }
            }
        }
Exemplo n.º 4
0
        public void AddWatermark(string text, string fileName, string resultFileName)
        {
            using (PdfDocumentProcessor documentProcessor = new PdfDocumentProcessor())
            {
                string          fontName     = "Arial Black";
                int             fontSize     = 12;
                PdfStringFormat stringFormat = PdfStringFormat.GenericTypographic;
                stringFormat.Alignment     = PdfStringAlignment.Center;
                stringFormat.LineAlignment = PdfStringAlignment.Center;
                documentProcessor.LoadDocument(fileName);
                using (SolidBrush brush = new SolidBrush(Color.FromArgb(63, Color.Black)))
                {
                    using (Font font = new Font(fontName, fontSize))
                    {
                        foreach (var page in documentProcessor.Document.Pages)
                        {
                            var watermarkSize = page.CropBox.Width * 0.75;
                            using (PdfGraphics graphics = documentProcessor.CreateGraphics())
                            {
                                SizeF  stringSize = graphics.MeasureString(text, font);
                                Single scale      = Convert.ToSingle(watermarkSize / stringSize.Width);
                                graphics.TranslateTransform(Convert.ToSingle(page.CropBox.Width * 0.5), Convert.ToSingle(page.CropBox.Height * 0.5));
                                graphics.RotateTransform(-45);
                                graphics.TranslateTransform(Convert.ToSingle(-stringSize.Width * scale * 0.5), Convert.ToSingle(-stringSize.Height * scale * 0.5));
                                using (Font actualFont = new Font(fontName, fontSize * scale))
                                {
                                    RectangleF rect = new RectangleF(0, 0, stringSize.Width * scale, stringSize.Height * scale);
                                    graphics.DrawString(text, actualFont, brush, rect, stringFormat);
                                }

                                graphics.AddToPageForeground(page, 72, 72);
                            }
                        }
                    }
                }

                documentProcessor.SaveDocument(resultFileName);
            }
        }
Exemplo n.º 5
0
        private static void AddDraw(PdfGraphics graphics, DrawText drawText, PointF pointF)
        {
            SizeF TextSize = graphics.MeasureString(drawText.Text, drawText.FontText, PdfStringFormat.GenericDefault, DrawIngDpi, DrawIngDpi);

            graphics.DrawString(drawText.Text.ToString(), drawText.FontText, drawText.SolidBrush, pointF);
        }
Exemplo n.º 6
0
        Size GetTextSize(string text, XFont font)
        {
            var gdiSize = PdfGraphics.MeasureString(text, font);

            return(new Size((int)gdiSize.Width, (int)gdiSize.Height));
        }