private void button1_Click(object sender, EventArgs e)
        {
            //Load a pdf document
            string input = "..\\..\\..\\..\\..\\..\\Data\\AddTextStamp.pdf";

            //Open a pdf document
            PdfDocument document = new PdfDocument();

            document.LoadFromFile(input);
            //Get the first page
            PdfPageBase page = document.Pages[0];

            //Create a pdf template
            PdfTemplate     template     = new PdfTemplate(125, 55);
            PdfTrueTypeFont font1        = new PdfTrueTypeFont(new Font("Elephant", 10f, FontStyle.Italic), true);
            PdfSolidBrush   brush        = new PdfSolidBrush(Color.DarkRed);
            PdfPen          pen          = new PdfPen(brush);
            RectangleF      rectangle    = new RectangleF(new PointF(5, 5), template.Size);
            int             CornerRadius = 20;
            PdfPath         path         = new PdfPath();

            path.AddArc(template.GetBounds().X, template.GetBounds().Y, CornerRadius, CornerRadius, 180, 90);
            path.AddArc(template.GetBounds().X + template.Width - CornerRadius, template.GetBounds().Y, CornerRadius, CornerRadius, 270, 90);
            path.AddArc(template.GetBounds().X + template.Width - CornerRadius, template.GetBounds().Y + template.Height - CornerRadius, CornerRadius, CornerRadius, 0, 90);
            path.AddArc(template.GetBounds().X, template.GetBounds().Y + template.Height - CornerRadius, CornerRadius, CornerRadius, 90, 90);
            path.AddLine(template.GetBounds().X, template.GetBounds().Y + template.Height - CornerRadius, template.GetBounds().X, template.GetBounds().Y + CornerRadius / 2);
            template.Graphics.DrawPath(pen, path);

            //Draw stamp text
            String s1 = "REVISED\n";
            String s2 = "by E-iceblue at " + DateTime.Now.ToString("MM dd, yyyy");

            template.Graphics.DrawString(s1, font1, brush, new PointF(5, 10));
            PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Lucida Sans Unicode", 9f, FontStyle.Bold), true);

            template.Graphics.DrawString(s2, font2, brush, new PointF(2, 30));

            //Create a rubber stamp
            PdfRubberStampAnnotation stamp       = new PdfRubberStampAnnotation(rectangle);
            PdfAppearance            apprearance = new PdfAppearance(stamp);

            apprearance.Normal = template;
            stamp.Appearance   = apprearance;

            //Draw stamp into page
            page.AnnotationsWidget.Add(stamp);

            string output = "AddTextStamp.pdf";

            //Save pdf document
            document.SaveToFile(output);

            //Launch the file
            PDFDocumentViewer(output);
        }
示例#2
0
        private void button1_Click(object sender, EventArgs e)
        {
            //pdf file
            string input = "..\\..\\..\\..\\..\\..\\..\\Data\\Sample5.pdf";

            //open a pdf document
            PdfDocument document = new PdfDocument(input);

            //get the first page
            PdfPageBase page = document.Pages[0];

            //create a pdf template
            PdfTemplate     template     = new PdfTemplate(200, 50);
            PdfTrueTypeFont font1        = new PdfTrueTypeFont(new Font("Elephant", 16f, FontStyle.Italic), true);
            PdfSolidBrush   brush        = new PdfSolidBrush(Color.DarkRed);
            PdfPen          pen          = new PdfPen(brush);
            RectangleF      rectangle    = new RectangleF(new PointF(0, 0), template.Size);
            int             CornerRadius = 20;
            PdfPath         path         = new PdfPath();

            path.AddArc(template.GetBounds().X, template.GetBounds().Y, CornerRadius, CornerRadius, 180, 90);
            path.AddArc(template.GetBounds().X + template.Width - CornerRadius, template.GetBounds().Y, CornerRadius, CornerRadius, 270, 90);
            path.AddArc(template.GetBounds().X + template.Width - CornerRadius, template.GetBounds().Y + template.Height - CornerRadius, CornerRadius, CornerRadius, 0, 90);
            path.AddArc(template.GetBounds().X, template.GetBounds().Y + template.Height - CornerRadius, CornerRadius, CornerRadius, 90, 90);
            path.AddLine(template.GetBounds().X, template.GetBounds().Y + template.Height - CornerRadius, template.GetBounds().X, template.GetBounds().Y + CornerRadius / 2);
            template.Graphics.DrawPath(pen, path);

            //draw stamp text
            String s1 = "REVISED\n";
            String s2 = "By Jack at " + DateTime.Now.ToString("HH:mm, MM dd, yyyy");

            template.Graphics.DrawString(s1, font1, brush, new PointF(5, 5));
            PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Gadugi", 12f, FontStyle.Bold), true);

            template.Graphics.DrawString(s2, font2, brush, new PointF(2, 28));

            //create a rubber stamp
            PdfRubberStampAnnotation stamp       = new PdfRubberStampAnnotation(rectangle);
            PdfAppearance            apprearance = new PdfAppearance(stamp);

            apprearance.Normal = template;
            stamp.Appearance   = apprearance;

            //draw stamp into page
            page.AnnotationsWidget.Add(stamp);

            string output = "AddTextStamp.pdf";

            //save pdf document
            document.SaveToFile(output);

            //Launching the Pdf file
            PDFDocumentViewer(output);
        }
示例#3
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Load Pdf document from disk
            PdfDocument doc = new PdfDocument();

            doc.LoadFromFile("../../../../../../../Data/PDFTemplate_HF.pdf");

            //Get the first page
            PdfPageBase page = doc.Pages[0];

            //Get the margins of Pdf
            PdfMargins margin = doc.PageSettings.Margins;

            //Define font and brush
            PdfTrueTypeFont font  = new PdfTrueTypeFont(new Font("Impact", 14f, FontStyle.Regular));
            PdfSolidBrush   brush = new PdfSolidBrush(Color.Gray);

            //Load an image
            PdfImage image = PdfImage.FromFile("../../../../../../../Data/E-iceblueLogo.png");

            //Specify the image size
            SizeF imageSize = new SizeF(image.Width / 2, image.Height / 2);

            //Create a header template
            PdfTemplate headerTemplate = new PdfTemplate(page.ActualSize.Width - margin.Left - margin.Right, imageSize.Height);

            //Draw the image in the template
            headerTemplate.Graphics.DrawImage(image, new PointF(0, 0), imageSize);

            //Create a retangle
            RectangleF rect = headerTemplate.GetBounds();

            //string format
            PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle);

            //Draw a string in the template
            headerTemplate.Graphics.DrawString("Header", font, brush, rect, format1);

            //Create a footer template and draw a text
            PdfTemplate     footerTemplate = new PdfTemplate(page.ActualSize.Width - margin.Left - margin.Right, imageSize.Height);
            PdfStringFormat format2        = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);

            footerTemplate.Graphics.DrawString("Footer", font, brush, rect, format2);

            float x = margin.Left;
            float y = 0;

            //Draw the header template on page at specified location
            page.Canvas.DrawTemplate(headerTemplate, new PointF(x, y));

            //Draw the footer template on page at specified location
            y = page.ActualSize.Height - footerTemplate.Height - 10;
            page.Canvas.DrawTemplate(footerTemplate, new PointF(x, y));

            //Save the document
            string output = "ImageAndTextInHeaderFooterUsingTemplate_out.pdf";

            doc.SaveToFile(output, FileFormat.PDF);

            //Launch the Pdf document
            PDFDocumentViewer(output);
        }