示例#1
0
        static void Main()
        {
            // Create new document
            Document pdfDocument = new Document();

            pdfDocument.RegistrationName = "demo";
            pdfDocument.RegistrationKey  = "demo";
            // Add page
            Page page = new Page(PaperFormat.A4);

            pdfDocument.Pages.Add(page);

            Canvas canvas = page.Canvas;

            SolidPen solidPen  = new SolidPen();
            SolidPen dashedPen = new SolidPen();

            dashedPen.DashPattern = new DashPattern(new float[] { 2, 2 });

            // Draw dashed lines
            canvas.DrawLine(dashedPen, 100, 100, 200, 100);
            canvas.DrawLine(dashedPen, 200, 100, 200, 200);
            canvas.DrawLine(dashedPen, 200, 200, 100, 200);
            // Draw besier curve by the same points
            canvas.DrawCurve(solidPen, 100, 100, 200, 100, 200, 200, 100, 200);

            // Save document to file
            pdfDocument.Save("result.pdf");

            // Cleanup
            pdfDocument.Dispose();

            // Open document in default PDF viewer app
            Process.Start("result.pdf");
        }
        public void TestRise()
        {
            Document document = new Document();

            document.Pages.Add(new Page(PaperFormat.A4));
            Canvas     canvas = document.Pages[0].Canvas;
            SolidBrush brush  = new SolidBrush();
            Font       font   = new Font("Arial", 16);

            float        x  = 0;
            StringFormat sf = new StringFormat();

            canvas.DrawString("Test string", font, brush, x, 0, sf);
            sf.Rise = -font.Size / 2;
            x      += font.GetTextWidth("Test string");
            canvas.DrawString("Test string rise -8", font, brush, x, 0, sf);
            sf.Rise = -font.Size / 4;
            x      += font.GetTextWidth("Test string rise -8");
            canvas.DrawString("Test string rise -4", font, brush, x, 0, sf);
            x += font.GetTextWidth("Test string rise -4");
            Pen pen = new SolidPen();

            canvas.DrawLine(pen, 0, font.Size * 1.5f + 3, x, font.Size * 1.5f + 3);
            font.Size = 10;
            canvas.DrawString("A line for visiblity", font, brush, x, font.Size * 1.5f + 5);
            document.Save(OutputFolder + @"\TestRiseString.pdf");
            document.Dispose();
        }
        public void TestTillingPattern()
        {
            Document document = new Document();

            document.Pages.Add(new Page(PaperFormat.A4));
            Canvas   canvas = document.Pages[0].Canvas;
            ColorRGB red    = new ColorRGB(255, 0, 0);
            ColorRGB green  = new ColorRGB(0, 255, 0);
            ColorRGB blue   = new ColorRGB(0, 0, 255);
            SolidPen pen    = new SolidPen();

            ColoredTilingBrush   tillingbrush   = new ColoredTilingBrush(50, 50);
            UncoloredTilingBrush untillingbrush = new UncoloredTilingBrush(10, 10);

            canvas = untillingbrush.Canvas;
            canvas.DrawCircle(new SolidPen(green), new SolidBrush(blue), 5, 5, 4);
            untillingbrush.Color = green;
            canvas = tillingbrush.Canvas;
            canvas.DrawEllipse(pen, untillingbrush, 0, 0, 49, 25);
            canvas.RotateTransform(45);
            canvas.DrawRectangle(new SolidBrush(new ColorRGB(100, 100, 100)), 33, 5, 10, 20);
            canvas = document.Pages[0].Canvas;
            canvas.DrawRoundedRectangle(pen, tillingbrush, 100, 100, 200, 300, 30);
            document.Save(OutputFolder + @"\TestTillingPattern.pdf");
            document.Dispose();
        }
        public void TestCirclesAndEllipses()
        {
            Document document = new Document();

            document.Pages.Add(new Page(PaperFormat.A4));
            Canvas      canvas = document.Pages[0].Canvas;
            DeviceColor red    = new ColorRGB(255, 0, 0);
            DeviceColor green  = new ColorRGB(0, 255, 0);
            DeviceColor blue   = new ColorRGB(0, 0, 255);
            SolidBrush  brush  = new SolidBrush(red);
            SolidPen    pen    = new SolidPen();

            canvas.BlendMode = BlendMode.Screen;
            canvas.DrawCircle(brush, 100, 100, 50);
            canvas.DrawEllipse(pen, brush, 300, 100, 200, 100);
            brush.Color = green;
            canvas.DrawCircle(brush, 100, 150, 50);
            canvas.DrawEllipse(pen, brush, 300, 200, 200, 100);
            brush.Color = blue;
            canvas.DrawCircle(brush, 150, 100, 50);
            canvas.DrawEllipse(pen, brush, 300, 300, 200, 100);

            document.Save(OutputFolder + @"\TestCirclesAndEllipses.pdf");
            document.Dispose();
        }
        public void TestBezierCurves()
        {
            Document document = new Document();

            document.Pages.Add(new Page(PaperFormat.A4));
            Canvas canvas = document.Pages[0].Canvas;

            Font       font     = new Font(StandardFonts.Helvetica, 8, false, false);
            SolidPen   penCurve = new SolidPen();
            SolidPen   penLine  = new SolidPen();
            SolidBrush brush    = new SolidBrush();

            penLine.DashPattern = new DashPattern(new float[] { 2, 2 }, 1);

            canvas.DrawCurve(penCurve, 100, 100, 200, 200, 100, 300, 200, 400);
            canvas.DrawLine(penLine, 100, 100, 200, 200);
            canvas.DrawLine(penLine, 100, 300, 200, 400);
            canvas.DrawCurve(penCurve, 300, 100, 200, 300, 400, 200, 400, 100);
            canvas.DrawLine(penLine, 300, 100, 200, 300);
            canvas.DrawLine(penLine, 400, 200, 400, 100);
            canvas.DrawString("100,100", font, brush, 100, 90);
            canvas.DrawString("200,200", font, brush, 200, 200);
            canvas.DrawString("100,300", font, brush, 100, 290);
            canvas.DrawString("200,400", font, brush, 200, 400);

            document.Save(OutputFolder + @"\TestBezierCurves.pdf");
            document.Dispose();
        }
示例#6
0
        /// <summary>
        /// Allows the creation of a shallow copy of this Bytescout.PDF.SolidPen.
        /// </summary>
        /// <returns cref="object" href="http://msdn.microsoft.com/en-us/library/system.object.aspx">Returns a shallow copy of this Bytescout.PDF.SolidPen.</returns>
        public override object Clone()
        {
            SolidPen p = this.MemberwiseClone() as SolidPen;

            p._color = _color.Clone() as Color;
            return(p);
        }
示例#7
0
        static void Main()
        {
            // Create new document
            Document pdfDocument = new Document();

            pdfDocument.RegistrationName = "demo";
            pdfDocument.RegistrationKey  = "demo";

            // If you wish to load an existing document uncomment the line below and comment the Add page section instead
            // pdfDocument.Load(@".\existing_document.pdf");

            // Add page
            Page page = new Page(PaperFormat.A4);

            pdfDocument.Pages.Add(page);


            Font         font         = new Font("Arial", 16);
            Brush        brush        = new SolidBrush();
            StringFormat stringFormat = new StringFormat();
            float        xPosition    = 20;

            // Draw normal string
            page.Canvas.DrawString("Normal text ", font, brush, xPosition, 50, stringFormat);
            xPosition += font.GetTextWidth("Normal text ");

            // Draw subscript string
            stringFormat.Rise = -5;
            page.Canvas.DrawString("Subscript", font, brush, xPosition, 50, stringFormat);
            xPosition += font.GetTextWidth("Subscript");

            // draw superscript string
            stringFormat.Rise = +5;
            page.Canvas.DrawString("Superscript", font, brush, xPosition, 50, stringFormat);
            xPosition += font.GetTextWidth("Superscript");

            // Draw the baseline
            Pen pen = new SolidPen(new ColorRGB(0, 0, 255));

            pen.Opacity = 50;
            page.Canvas.DrawLine(pen, 20, 50 + font.Size, xPosition, 50 + font.Size);


            // Save document to file
            pdfDocument.Save("result.pdf");

            // Cleanup
            pdfDocument.Dispose();

            // Open result document in default associated application (for demo purpose)
            ProcessStartInfo processStartInfo = new ProcessStartInfo("result.pdf");

            processStartInfo.UseShellExecute = true;
            Process.Start(processStartInfo);
        }
示例#8
0
            public static SolidPen CreateInstance( int color,  int width,  int height)
            {
                var key = color.ToString();
                SolidPen b;

                if (!Factory.Get(key, out b, ObjType.Buffer))
                    b = new SolidPen(color);
                b.Width = width;
                b.Height = height;
                return b;
            }
示例#9
0
        static void Main()
        {
            // Create new document
            Document pdfDocument = new Document();

            pdfDocument.RegistrationName = "demo";
            pdfDocument.RegistrationKey  = "demo";

            // If you wish to load an existing document uncomment the line below and comment the Add page section instead
            // pdfDocument.Load(@".\existing_document.pdf");

            // Add page
            Page page = new Page(PaperFormat.A4);

            pdfDocument.Pages.Add(page);

            Canvas canvas = page.Canvas;

            // Prepare pens
            Pen blackPen = new SolidPen(new ColorRGB(0, 0, 0), 2f);

            blackPen.Opacity = 50;
            Pen bluePen = new SolidPen(new ColorRGB(0, 0, 255), 2f);

            bluePen.Opacity = 50;
            Pen greenPen = new SolidPen(new ColorRGB(0, 255, 0), 2f);

            greenPen.Opacity = 50;

            // Move coordinate space zero point to (200, 200) and draw a rectangle of 50x50 dize
            canvas.TranslateTransform(200, 200);
            canvas.DrawRectangle(blackPen, 0, 0, 50, 50);

            // Now zoom the coordinate space in twice and draw the same rectangle in green
            canvas.ScaleTransform(2, 2);
            canvas.DrawRectangle(greenPen, 0, 0, 50, 50);

            // Now rotate the coordinate space by 30 degrees and draw the same rectangle in blue
            canvas.RotateTransform(30);
            canvas.DrawRectangle(bluePen, 0, 0, 50, 50);

            // Save document to file
            pdfDocument.Save("result.pdf");

            // Cleanup
            pdfDocument.Dispose();

            // Open result document in default associated application (for demo purpose)
            ProcessStartInfo processStartInfo = new ProcessStartInfo("result.pdf");

            processStartInfo.UseShellExecute = true;
            Process.Start(processStartInfo);
        }
示例#10
0
        static void Main()
        {
            // Create new document
            Document pdfDocument = new Document();

            pdfDocument.RegistrationName = "demo";
            pdfDocument.RegistrationKey  = "demo";

            // If you wish to load an existing document uncomment the line below and comment the Add page section instead
            // pdfDocument.Load(@".\existing_document.pdf");

            // Add page
            Page page = new Page(PaperFormat.A4);

            pdfDocument.Pages.Add(page);

            Canvas canvas = page.Canvas;

            // Prepare pens and brushes
            Pen borderPen = new SolidPen(new ColorRGB(0, 0, 0), 2f);

            SolidBrush brush1 = new SolidBrush(new ColorRGB(255, 0, 0));
            SolidBrush brush2 = new SolidBrush(new ColorRGB(0, 0, 255));

            borderPen.Opacity = 50;
            brush1.Opacity    = 30;
            brush2.Opacity    = 60;

            // Draw normal rectangles
            canvas.DrawRectangle(brush1, 100, 100, 100, 100);
            canvas.DrawRectangle(borderPen, brush2, 150, 150, 100, 100);

            borderPen.Opacity = 80;
            brush1.Opacity    = 60;
            brush2.Opacity    = 30;

            // Draw rounded rectangles
            canvas.DrawRoundedRectangle(brush1, 220, 100, 100, 100, 10);
            canvas.DrawRoundedRectangle(borderPen, brush2, 270, 150, 100, 100, 10);

            // Save document to file
            pdfDocument.Save("result.pdf");

            // Cleanup
            pdfDocument.Dispose();

            // Open result document in default associated application (for demo purpose)
            ProcessStartInfo processStartInfo = new ProcessStartInfo("result.pdf");

            processStartInfo.UseShellExecute = true;
            Process.Start(processStartInfo);
        }
        static void Main()
        {
            // Create new document
            Document pdfDocument = new Document();

            pdfDocument.RegistrationName = "demo";
            pdfDocument.RegistrationKey  = "demo";

            // If you wish to load an existing document uncomment the line below and comment the Add page section instead
            // pdfDocument.Load(@".\existing_document.pdf");

            // Add page
            Page page = new Page(PaperFormat.A4);

            pdfDocument.Pages.Add(page);

            // Draw simple text
            Font  font       = new Font("Arial", 24);
            Brush blackBrush = new SolidBrush();

            page.Canvas.DrawString("Simple text.", font, blackBrush, 20, 20);

            // Draw text with alignment in specified rectangle
            StringFormat stringFormat = new StringFormat();

            stringFormat.HorizontalAlign = HorizontalAlign.Right;
            stringFormat.VerticalAlign   = VerticalAlign.Bottom;
            page.Canvas.DrawString("Aligned text", font, blackBrush, new RectangleF(20, 100, 200, 60), stringFormat);
            page.Canvas.DrawRectangle(new SolidPen(), 20, 100, 200, 60);

            // Draw colored text
            Font  boldFont = new Font("Arial", 32, true, false, false, false);
            Brush redBrush = new SolidBrush(new ColorRGB(255, 0, 0));
            Pen   bluePen  = new SolidPen(new ColorRGB(0, 0, 255));

            page.Canvas.DrawString("Colored text", boldFont, redBrush, 20, 200);
            page.Canvas.DrawString("Outlined colored text", boldFont, redBrush, bluePen, 20, 240);
            page.Canvas.DrawString("Outlined transparent text", boldFont, bluePen, 20, 280);

            // Save document to file
            pdfDocument.Save("result.pdf");

            // Cleanup
            pdfDocument.Dispose();

            // Open result document in default associated application (for demo purpose)
            ProcessStartInfo processStartInfo = new ProcessStartInfo("result.pdf");

            processStartInfo.UseShellExecute = true;
            Process.Start(processStartInfo);
        }
示例#12
0
        static void Main(string[] args)
        {
            // Create ByteScout.PDFEditor.PDFEditor object instance.
            PDFEditor pdfEditor = new PDFEditor();

            // Load document
            pdfEditor.Load(@".\sample.pdf");

            // Delete last page
            pdfEditor.Pages.RemoveAt(pdfEditor.Pages.Count - 1);
            // Add new page instead
            pdfEditor.Pages.Add(PaperSize.Letter);

            // Remove image from point
            pdfEditor.Pages[0].RemoveImage(100, 200);

            // Remove image by index
            Rectangle imageRect = pdfEditor.Pages[0].Images[0].Bounds;

            pdfEditor.Pages[0].Images.RemoveAt(0);
            // ... and replace it with new image
            pdfEditor.Pages[0].AddImage(new Image(@".\image1.png"), imageRect);

            // Remove all annotations
            pdfEditor.Pages[0].Annotations.Clear();

            // Find and replace text
            pdfEditor.Pages[0].ReplaceText("Joe Carpenter", "John Doe");

            // Remove text from rectangle
            pdfEditor.Pages[0].RemoveText(new Rectangle(100, 100, 200, 200))

            // Find text and highlight it with transparent red
            Rectangle textRect = pdfEditor.Pages[0].Find("top secret");

            pdfEditor.Pages[0].FillRectangle(textRect, Color.FromArgb(196, 255, 0, 0));

            // Draw new text
            Font font     = new Font("Arial", 18);
            Pen  blackPen = new SolidPen(0, 0, 0);

            page.DrawString("The quick brown fox jumps over the lazy dog", font, blackPen, 20, 20);


            // Save PDF document.
            pdfEditor.Save(@".\result.pdf");

            // Cleanup.
            pdfEditor.Dispose();
        }
示例#13
0
        private void drawContents(GraphicsTemplate xObj)
        {
            if (BackgroundColor != null)
            {
                Brush br = new SolidBrush(BackgroundColor);
                xObj.DrawCircle(br, Width / 2, Height / 2, Math.Min(Width, Height) / 2 - BorderWidth);
            }

            if (BorderColor != null)
            {
                Pen pen = new SolidPen(BorderColor);
                pen.Width = BorderWidth;
                xObj.DrawCircle(pen, Width / 2, Height / 2, Math.Min(Width, Height) / 2 - BorderWidth);
            }
        }
示例#14
0
        static void Main()
        {
            // Create new document
            Document pdfDocument = new Document();

            pdfDocument.RegistrationName = "demo";
            pdfDocument.RegistrationKey  = "demo";
            // Add page
            Page page = new Page(PaperFormat.A4);

            pdfDocument.Pages.Add(page);


            Font         font         = new Font("Arial", 16);
            Brush        brush        = new SolidBrush();
            StringFormat stringFormat = new StringFormat();
            float        xPosition    = 20;

            // Draw normal string
            page.Canvas.DrawString("Normal text ", font, brush, xPosition, 50, stringFormat);
            xPosition += font.GetTextWidth("Normal text ");

            // Draw subscript string
            stringFormat.Rise = -5;
            page.Canvas.DrawString("Subscript", font, brush, xPosition, 50, stringFormat);
            xPosition += font.GetTextWidth("Subscript");

            // draw superscript string
            stringFormat.Rise = +5;
            page.Canvas.DrawString("Superscript", font, brush, xPosition, 50, stringFormat);
            xPosition += font.GetTextWidth("Superscript");

            // Draw the baseline
            Pen pen = new SolidPen(new ColorRGB(0, 0, 255));

            pen.Opacity = 50;
            page.Canvas.DrawLine(pen, 20, 50 + font.Size, xPosition, 50 + font.Size);


            // Save document to file
            pdfDocument.Save("result.pdf");

            // Cleanup
            pdfDocument.Dispose();

            // Open document in default PDF viewer app
            Process.Start("result.pdf");
        }
示例#15
0
        public void TestTransformAndPie()
        {
            Document document = new Document();

            document.Pages.Add(new Page(PaperFormat.A4));
            Canvas      canvas = document.Pages[0].Canvas;
            DeviceColor red    = new ColorRGB(255, 0, 0);
            DeviceColor green  = new ColorRGB(0, 255, 0);
            DeviceColor blue   = new ColorRGB(0, 0, 255);

            SolidBrush brush = new SolidBrush(red);
            SolidPen   pen   = new SolidPen();

            pen.Width = 3;

            canvas.TranslateTransform(100, 200);
            canvas.DrawPie(brush, 0, 0, 50, 50, -90, 120);
            brush.Color = green;
            canvas.DrawPie(brush, 0, 0, 50, 50, 30, 120);
            brush.Color = blue;
            canvas.DrawPie(pen, brush, 0, 0, 50, 50, -90, -120);

            canvas.TranslateTransform(150, 0);
            canvas.ScaleTransform(1.5f, 1.5f);
            canvas.RotateTransform(90);

            brush.Color = red;
            canvas.DrawPie(brush, 0, 0, 50, 50, -90, 120);
            brush.Color = green;
            canvas.DrawPie(brush, 0, 0, 50, 50, 30, 120);
            brush.Color = blue;
            canvas.DrawPie(pen, brush, 0, 0, 50, 50, -90, -120);

            canvas.TranslateTransform(0, -150);
            canvas.ScaleTransform(1.5f, 1.5f);
            canvas.RotateTransform(45);

            brush.Color = red;
            canvas.DrawPie(brush, 0, 0, 50, 50, -90, 120);
            brush.Color = green;
            canvas.DrawPie(brush, 0, 0, 50, 50, 30, 120);
            brush.Color = blue;
            canvas.DrawPie(pen, brush, 0, 0, 50, 50, -90, -120);

            document.Save(OutputFolder + @"\TestTransformAndPie.pdf");
            document.Dispose();
        }
示例#16
0
        public void TestCirlesEllipses()
        {
            Document document = new Document();

            document.Pages.Add(new Page(PaperFormat.A4));

            Canvas canvas = document.Pages[0].Canvas;
            Path   path   = new Path();

            path.AddEllipse(50, 50, document.Pages[0].Width - 100, document.Pages[0].Height - 100);
            canvas.SetClip(path);
            canvas.DrawPath(new SolidPen(), path);
            path.Reset();

            Random rand = new Random();

            for (int i = 0; i < 200; ++i)
            {
                float x = (float)rand.NextDouble() * (document.Pages[0].Width - 100 + 1);
                float y = (float)rand.NextDouble() * (document.Pages[0].Height - 100 + 1);
                float s = (float)rand.NextDouble() * (150 + 1);

                if (i % 2 == 0)
                {
                    path.AddCircle(x, y, s);
                }
                else
                {
                    float k = (float)rand.NextDouble() * (150 + 1);
                    path.AddEllipse(x, y, s, k);
                }
                Color color = new ColorRGB((Byte)rand.Next(256), (Byte)rand.Next(256), (Byte)rand.Next(256));
                canvas.DrawPath(new SolidPen(color), new SolidBrush(color), path);
                path.Reset();
            }

            path.AddEllipse(50, 50, document.Pages[0].Width - 100, document.Pages[0].Height - 100);
            canvas.SetClip(path);
            SolidPen pen = new SolidPen();

            pen.Width = 2.5f;
            canvas.DrawPath(pen, path);

            document.Save(OutputFolder + @"\TestCirclesEllipses.pdf");

            //Process.Start("TestCirclesEllipses.pdf");
        }
示例#17
0
        static void Main()
        {
            // Create new document
            Document pdfDocument = new Document();

            pdfDocument.RegistrationName = "demo";
            pdfDocument.RegistrationKey  = "demo";
            // Add page
            Page page = new Page(PaperFormat.A4);

            pdfDocument.Pages.Add(page);

            Canvas canvas = page.Canvas;

            // Prepare pens
            Pen blackPen = new SolidPen(new ColorRGB(0, 0, 0), 2f);

            blackPen.Opacity = 50;
            Pen bluePen = new SolidPen(new ColorRGB(0, 0, 255), 2f);

            bluePen.Opacity = 50;
            Pen greenPen = new SolidPen(new ColorRGB(0, 255, 0), 2f);

            greenPen.Opacity = 50;

            // Move coordinate space zero point to (200, 200) and draw a rectangle of 50x50 dize
            canvas.TranslateTransform(200, 200);
            canvas.DrawRectangle(blackPen, 0, 0, 50, 50);

            // Now zoom the coordinate space in twice and draw the same rectangle in green
            canvas.ScaleTransform(2, 2);
            canvas.DrawRectangle(greenPen, 0, 0, 50, 50);

            // Now rotate the coordinate space by 30 degrees and draw the same rectangle in blue
            canvas.RotateTransform(30);
            canvas.DrawRectangle(bluePen, 0, 0, 50, 50);

            // Save document to file
            pdfDocument.Save("result.pdf");

            // Cleanup
            pdfDocument.Dispose();

            // Open document in default PDF viewer app
            Process.Start("result.pdf");
        }
示例#18
0
        internal void DrawBorder(GraphicsTemplate xObj)
        {
            if (BorderColor != null)
            {
                Pen pen = new SolidPen(BorderColor);
                pen.Width = Border.Width;
                if (Border.Style == BorderStyle.Underline)
                {
                    xObj.DrawLine(pen, 0, Height - pen.Width / 2, Width, Height - pen.Width / 2);
                }
                else
                {
                    RectangleF rect = new RectangleF(pen.Width / 2, pen.Width / 2, Width - pen.Width, Height - pen.Width);
                    if (Border.Style == BorderStyle.Dashed)
                    {
                        pen.DashPattern = Border.DashPattern;
                    }
                    xObj.DrawRectangle(pen, rect);

                    if (Border.Style == BorderStyle.Inset)
                    {
                        Pen insPen = new SolidPen(new ColorRGB(128, 128, 128));
                        insPen.Width = Border.Width;
                        xObj.DrawLine(insPen, insPen.Width, 1.5f * insPen.Width, Width - insPen.Width, 1.5f * insPen.Width);
                        xObj.DrawLine(insPen, 1.5f * insPen.Width, 1.5f * insPen.Width, 1.5f * insPen.Width, Height - insPen.Width);
                    }

                    if (Border.Style == BorderStyle.Inset || Border.Style == BorderStyle.Beveled)
                    {
                        float width = Border.Width;
                        Path  path  = new Path();
                        path.MoveTo(width, Height - width);
                        path.AddLineTo(2 * width, Height - 2 * width);
                        path.AddLineTo(Width - 2 * width, Height - 2 * width);
                        path.AddLineTo(Width - 2 * width, 2 * width);
                        path.AddLineTo(Width - width, width);
                        path.AddLineTo(Width - width, Height - width);
                        path.ClosePath();

                        Brush br = new SolidBrush(new ColorRGB(192, 192, 192));
                        xObj.DrawPath(br, path);
                    }
                }
            }
        }
示例#19
0
        static void Main()
        {
            // Create new document
            Document pdfDocument = new Document();

            pdfDocument.RegistrationName = "demo";
            pdfDocument.RegistrationKey  = "demo";
            // Add page
            Page page = new Page(PaperFormat.A4);

            pdfDocument.Pages.Add(page);

            Canvas canvas = page.Canvas;

            // Prepare pens and brushes
            Pen borderPen = new SolidPen(new ColorRGB(0, 0, 0), 2f);

            SolidBrush brush1 = new SolidBrush(new ColorRGB(255, 0, 0));
            SolidBrush brush2 = new SolidBrush(new ColorRGB(0, 0, 255));

            borderPen.Opacity = 50;
            brush1.Opacity    = 30;
            brush2.Opacity    = 60;

            // Draw normal rectangles
            canvas.DrawRectangle(brush1, 100, 100, 100, 100);
            canvas.DrawRectangle(borderPen, brush2, 150, 150, 100, 100);

            borderPen.Opacity = 80;
            brush1.Opacity    = 60;
            brush2.Opacity    = 30;

            // Draw rounded rectangles
            canvas.DrawRoundedRectangle(brush1, 220, 100, 100, 100, 10);
            canvas.DrawRoundedRectangle(borderPen, brush2, 270, 150, 100, 100, 10);

            // Save document to file
            pdfDocument.Save("result.pdf");

            // Cleanup
            pdfDocument.Dispose();

            // Open document in default PDF viewer app
            Process.Start("result.pdf");
        }
示例#20
0
        private void PrintStickersOnPage(Page page)
        {
            var nextpoint = StartPoint;

            Pen        borderpen = new SolidPen(new ColorRGB(0, 0, 0), (float)0.5);
            SolidBrush fontbrush = new SolidBrush();

            var stickercol = 1;

            foreach (Sticker sticker in Stickers)
            {
                // Draw border
                page.Canvas.DrawRectangle(borderpen, nextpoint.X, nextpoint.Y, sticker.Width, sticker.Height);

                // Draw barcode
                page.Canvas.DrawImage(sticker.BarcodeImage, nextpoint.X + sticker.MarginLeft, nextpoint.Y + sticker.MarginTop, sticker.BarcodeWidth, sticker.BarcodeHeight);

                // Draw Text
                // Line 1
                page.Canvas.DrawString(sticker.Text1, sticker.Font, fontbrush, nextpoint.X + (sticker.Width / 2), nextpoint.Y + sticker.MarginTop);
                // Line 2
                page.Canvas.DrawString(sticker.Text2, sticker.Font, fontbrush, nextpoint.X + (sticker.Width / 2), nextpoint.Y + sticker.MarginTop + sticker.HTextSpacing);
                // Line 3
                page.Canvas.DrawString(sticker.Text3, sticker.Font, fontbrush, nextpoint.X + (sticker.Width / 2), nextpoint.Y + sticker.MarginTop + 3 * sticker.HTextSpacing);

                // Is Sticker last Sticker in the Row?
                if (stickercol == Columns)
                {
                    // Next Sticker will be the first again in the new row
                    stickercol = 1;
                    // Reset X coordinate for next point
                    nextpoint.X = StartPoint.X;

                    // New Y Coordinate for next point
                    nextpoint.Y = nextpoint.Y + VStickerSpacing + sticker.Height;
                }
                else
                {
                    // Next Column
                    stickercol++;
                    // Move X Coordinate to next Point
                    nextpoint.X = nextpoint.X + HStickerSpacing + sticker.Width;
                }
            }
        }
示例#21
0
        static void Main()
        {
            // Create new document
            Document pdfDocument = new Document();

            pdfDocument.RegistrationName = "demo";
            pdfDocument.RegistrationKey  = "demo";
            // Add page
            Page page = new Page(PaperFormat.A4);

            pdfDocument.Pages.Add(page);

            // Draw simple text
            Font  font       = new Font("Arial", 24);
            Brush blackBrush = new SolidBrush();

            page.Canvas.DrawString("Simple text.", font, blackBrush, 20, 20);

            // Draw text with alignment in specified rectangle
            StringFormat stringFormat = new StringFormat();

            stringFormat.HorizontalAlign = HorizontalAlign.Right;
            stringFormat.VerticalAlign   = VerticalAlign.Bottom;
            page.Canvas.DrawString("Aligned text", font, blackBrush, new RectangleF(20, 100, 200, 60), stringFormat);
            page.Canvas.DrawRectangle(new SolidPen(), 20, 100, 200, 60);

            // Draw colored text
            Font  boldFont = new Font("Arial", 32, true, false, false, false);
            Brush redBrush = new SolidBrush(new ColorRGB(255, 0, 0));
            Pen   bluePen  = new SolidPen(new ColorRGB(0, 0, 255));

            page.Canvas.DrawString("Colored text", boldFont, redBrush, 20, 200);
            page.Canvas.DrawString("Outlined colored text", boldFont, redBrush, bluePen, 20, 240);
            page.Canvas.DrawString("Outlined transparent text", boldFont, bluePen, 20, 280);

            // Save document to file
            pdfDocument.Save("result.pdf");

            // Cleanup
            pdfDocument.Dispose();

            // Open document in default PDF viewer app
            Process.Start("result.pdf");
        }
        static void Main()
        {
            // Create new document
            Document pdfDocument = new Document();

            pdfDocument.RegistrationName = "demo";
            pdfDocument.RegistrationKey  = "demo";

            // If you wish to load an existing document uncomment the line below and comment the Add page section instead
            // pdfDocument.Load(@".\existing_document.pdf");

            // Add page
            Page page = new Page(PaperFormat.A4);

            pdfDocument.Pages.Add(page);

            Canvas canvas = page.Canvas;

            // Prepare pens and brushes
            Pen   borderPen = new SolidPen(new ColorGray(128), 2f);
            Brush brush1    = new SolidBrush(new ColorRGB(255, 0, 0));
            Brush brush2    = new SolidBrush(new ColorRGB(0, 255, 255));

            // Draw transparent rectangle with border only
            canvas.DrawRectangle(borderPen, 100, 100, 100, 50);

            // Draw rounded rectangle with broder and filling
            canvas.DrawRoundedRectangle(borderPen, brush1, 250, 100, 100, 50, 10);

            // Draw rectangle as polygon
            canvas.DrawPolygon(borderPen, brush2, new PointF[] { new PointF(400, 100), new PointF(500, 100), new PointF(500, 150), new PointF(400, 150) });

            // Save document to file
            pdfDocument.Save("result.pdf");

            // Cleanup
            pdfDocument.Dispose();

            // Open result document in default associated application (for demo purpose)
            ProcessStartInfo processStartInfo = new ProcessStartInfo("result.pdf");

            processStartInfo.UseShellExecute = true;
            Process.Start(processStartInfo);
        }
示例#23
0
        private void drawSpacesCells(GraphicsTemplate xObj)
        {
            if (BorderColor != null)
            {
                float w   = getRotateWidth() / MaxLength;
                Pen   pen = new SolidPen(BorderColor);
                if (BorderStyle == BorderStyle.Dashed)
                {
                    pen.DashPattern = new DashPattern(new float[] { 3 });
                }

                float curPos = 0;
                for (int i = 1; i < MaxLength; ++i)
                {
                    curPos += w;
                    xObj.DrawLine(pen, curPos, 0, curPos, Height);
                }
            }
        }
示例#24
0
        static void Main()
        {
            // Create new document
            Document pdfDocument = new Document();

            pdfDocument.RegistrationName = "demo";
            pdfDocument.RegistrationKey  = "demo";

            // If you wish to load an existing document uncomment the line below and comment the Add page section instead
            // pdfDocument.Load(@".\existing_document.pdf");

            // Add page
            Page page = new Page(PaperFormat.A4);

            pdfDocument.Pages.Add(page);

            Canvas canvas = page.Canvas;

            SolidPen solidPen  = new SolidPen();
            SolidPen dashedPen = new SolidPen();

            dashedPen.DashPattern = new DashPattern(new float[] { 2, 2 });

            // Draw dashed lines
            canvas.DrawLine(dashedPen, 100, 100, 200, 100);
            canvas.DrawLine(dashedPen, 200, 100, 200, 200);
            canvas.DrawLine(dashedPen, 200, 200, 100, 200);
            // Draw besier curve by the same points
            canvas.DrawCurve(solidPen, 100, 100, 200, 100, 200, 200, 100, 200);

            // Save document to file
            pdfDocument.Save("result.pdf");

            // Cleanup
            pdfDocument.Dispose();

            // Open result document in default associated application (for demo purpose)
            ProcessStartInfo processStartInfo = new ProcessStartInfo("result.pdf");

            processStartInfo.UseShellExecute = true;
            Process.Start(processStartInfo);
        }
示例#25
0
        public void TestICCBased()
        {
            Document document = new Document();

            document.Pages.Add(new Page(PaperFormat.A4));
            Canvas canvas = document.Pages[0].Canvas;

            SolidBrush         brush = new SolidBrush();
            SolidPen           pen   = new SolidPen();
            ICCBasedColorspace icc   = new ICCBasedColorspace(TestColorProfile);

            brush.Color = new ColorICC(icc, new ColorRGB(0, 255, 0));
            pen.Color   = new ColorICC(icc, new ColorRGB(255, 0, 0));
            pen.Width   = 5;
            canvas.DrawRectangle(pen, brush, 0, 0, 100, 100);

            document.Save(OutputFolder + @"\TestICCBased.pdf");
            document.Dispose();

            //Process.Start("TestICCBased.pdf");
        }
示例#26
0
        static void Main()
        {
            // Create new document
            Document pdfDocument = new Document();

            pdfDocument.RegistrationName = "demo";
            pdfDocument.RegistrationKey  = "demo";
            // Add page
            Page page = new Page(PaperFormat.A4);

            pdfDocument.Pages.Add(page);

            Canvas canvas = page.Canvas;

            // Prepare pens and brushes
            Pen   borderPen = new SolidPen(new ColorGray(128), 2f);
            Brush brush1    = new SolidBrush(new ColorRGB(255, 0, 0));
            Brush brush2    = new SolidBrush(new ColorRGB(0, 255, 255));

            // Draw transparent rectangle with border only
            canvas.DrawRectangle(borderPen, 100, 100, 100, 50);

            // Draw rounded rectangle with broder and filling
            canvas.DrawRoundedRectangle(borderPen, brush1, 250, 100, 100, 50, 10);

            // Draw rectangle as polygon
            canvas.DrawPolygon(borderPen, brush2, new PointF[] { new PointF(400, 100), new PointF(500, 100), new PointF(500, 150), new PointF(400, 150) });

            // Save document to file
            pdfDocument.Save("result.pdf");

            // Cleanup
            pdfDocument.Dispose();

            // Open document in default PDF viewer app
            Process.Start("result.pdf");
        }
        public void TestStatusText()
        {
            Document document = new Document();

            document.Pages.Add(new Page(PaperFormat.A4));
            Canvas     canvas         = document.Pages[0].Canvas;
            SolidBrush brush          = new SolidBrush(new ColorRGB(150, 150, 0));
            SolidPen   pen            = new SolidPen(new ColorRGB(200, 0, 0));
            Font       fontStandart11 = new Font(StandardFonts.Helvetica, 8, true, true);
            Font       fontStandart01 = new Font(StandardFonts.Helvetica, 8, false, true);
            Font       fontStandart10 = new Font(StandardFonts.Helvetica, 8, true, false);
            Font       fontStandart00 = new Font(StandardFonts.Helvetica, 8, false, false);

            List <Font> list_fontsWF = new List <Font>();

            for (int i = 0; i < 16; ++i)
            {
                list_fontsWF.Add(new Font("Helvetica", i + 12, (((i >> 3) & 1) % 2 == 0 ? false : true), (((i >> 2) & 1) % 2 == 0 ? false : true), (((i >> 1) & 1) % 2 == 0 ? false : true), ((i & 1) % 2 == 0 ? false : true)));
            }
            fontStandart00.Size = 32;
            fontStandart01.Size = 24;
            fontStandart10.Size = 24;
            fontStandart11.Size = 24;
            canvas.DrawString("Normalize text", fontStandart00, brush, pen, 50, 0);
            canvas.DrawString("Underline text", fontStandart10, brush, 50, fontStandart00.Size * 1.5f);
            canvas.DrawString("Strokeout text", fontStandart01, pen, 50, fontStandart00.Size * 3.0f);
            canvas.DrawString("Strokeout and underline text", fontStandart11, brush, 50, fontStandart00.Size * 4.5f);

            Font[] fonts = list_fontsWF.ToArray();
            for (int i = 0; i < 16; ++i)
            {
                canvas.DrawString("Test string text", fonts[i], brush, 50, fontStandart00.Size * 6.0f + (fonts[i].Size + 10) * i);
            }

            document.Save(OutputFolder + @"\TestStatusString.pdf");
            document.Dispose();
        }
        public void TestAlignInRectangle()
        {
            Document document = new Document();

            document.Pages.Add(new Page(PaperFormat.A4));
            Canvas canvas = document.Pages[0].Canvas;

            Font         font  = new Font(StandardFonts.Courier, 8, false, false);
            StringFormat sf    = new StringFormat();
            Brush        brush = new SolidBrush();
            SolidPen     pen   = new SolidPen(new ColorRGB(0, 255, 0));

            pen.Opacity = 20;
            string str = "The test string";

            canvas.DrawString("Font = PDFBuiltInFont.Courier", font, brush, 50, 10);
            canvas.DrawString("Font = ByFontName(\"Arial\")", font, brush, 300, 10);
            for (int i = 0; i < 2; ++i)
            {
                if (i == 1)
                {
                    font = new Font("Arial", 8);
                    str  = "Test test string. ";
                    str += str;
                    str += str;
                }
                canvas.DrawString("HAlign", font, brush, 10 + i * 250, 40);
                canvas.DrawRectangle(pen, 10 + i * 250, 40, 40, 10);
                canvas.DrawString("VAlign", font, brush, 10 + i * 250, 50);
                canvas.DrawRectangle(pen, 10 + i * 250, 50, 40, 10);
                canvas.DrawString("Left", font, brush, 50 + i * 250, 40);
                canvas.DrawRectangle(pen, 50 + i * 250, 40, 50, 10);
                canvas.DrawString("Center", font, brush, 100 + i * 250, 40);
                canvas.DrawRectangle(pen, 100 + i * 250, 40, 50, 10);
                canvas.DrawString("Width", font, brush, 150 + i * 250, 40);
                canvas.DrawRectangle(pen, 150 + i * 250, 40, 50, 10);
                canvas.DrawString("Right", font, brush, 200 + i * 250, 40);
                canvas.DrawRectangle(pen, 200 + i * 250, 40, 50, 10);
                canvas.DrawString("Top", font, brush, 10 + i * 250, 75);
                canvas.DrawRectangle(pen, 10 + i * 250, 60, 40, 40);
                canvas.DrawString("Center", font, brush, 10 + i * 250, 125);
                canvas.DrawRectangle(pen, 10 + i * 250, 100, 40, 50);
                canvas.DrawString("Bottom", font, brush, 10 + i * 250, 175);
                canvas.DrawRectangle(pen, 10 + i * 250, 150, 40, 50);
                sf.VerticalAlign   = VerticalAlign.Top;
                sf.HorizontalAlign = HorizontalAlign.Left;
                canvas.DrawString(str, font, brush, new RectangleF(50 + i * 250, 50, 50, 50), sf);
                canvas.DrawRectangle(pen, 50 + i * 250, 50, 50, 50);
                sf.HorizontalAlign = HorizontalAlign.Center;
                canvas.DrawString(str, font, brush, new RectangleF(100 + i * 250, 50, 50, 50), sf);
                canvas.DrawRectangle(pen, 100 + i * 250, 50, 50, 50);
                sf.HorizontalAlign = HorizontalAlign.Justify;
                canvas.DrawString(str, font, brush, new RectangleF(150 + i * 250, 50, 50, 50), sf);
                canvas.DrawRectangle(pen, 150 + i * 250, 50, 50, 50);
                sf.HorizontalAlign = HorizontalAlign.Right;
                canvas.DrawString(str, font, brush, new RectangleF(200 + i * 250, 50, 50, 50), sf);
                canvas.DrawRectangle(pen, 200 + i * 250, 50, 50, 50);
                sf.VerticalAlign   = VerticalAlign.Center;
                sf.HorizontalAlign = HorizontalAlign.Left;
                canvas.DrawString(str, font, brush, new RectangleF(50 + i * 250, 100, 50, 50), sf);
                canvas.DrawRectangle(pen, 50 + i * 250, 100, 50, 50);
                sf.HorizontalAlign = HorizontalAlign.Center;
                canvas.DrawString(str, font, brush, new RectangleF(100 + i * 250, 100, 50, 50), sf);
                canvas.DrawRectangle(pen, 100 + i * 250, 100, 50, 50);
                sf.HorizontalAlign = HorizontalAlign.Justify;
                canvas.DrawString(str, font, brush, new RectangleF(150 + i * 250, 100, 50, 50), sf);
                canvas.DrawRectangle(pen, 150 + i * 250, 100, 50, 50);
                sf.HorizontalAlign = HorizontalAlign.Right;
                canvas.DrawString(str, font, brush, new RectangleF(200 + i * 250, 100, 50, 50), sf);
                canvas.DrawRectangle(pen, 200 + i * 250, 100, 50, 50);
                sf.VerticalAlign   = VerticalAlign.Bottom;
                sf.HorizontalAlign = HorizontalAlign.Left;
                canvas.DrawString(str, font, brush, new RectangleF(50 + i * 250, 150, 50, 50), sf);
                canvas.DrawRectangle(pen, 50 + i * 250, 150, 50, 50);
                sf.HorizontalAlign = HorizontalAlign.Center;
                canvas.DrawString(str, font, brush, new RectangleF(100 + i * 250, 150, 50, 50), sf);
                canvas.DrawRectangle(pen, 100 + i * 250, 150, 50, 50);
                sf.HorizontalAlign = HorizontalAlign.Justify;
                canvas.DrawString(str, font, brush, new RectangleF(150 + i * 250, 150, 50, 50), sf);
                canvas.DrawRectangle(pen, 150 + i * 250, 150, 50, 50);
                sf.HorizontalAlign = HorizontalAlign.Right;
                canvas.DrawString(str, font, brush, new RectangleF(200 + i * 250, 150, 50, 50), sf);
                canvas.DrawRectangle(pen, 200 + i * 250, 150, 50, 50);
            }

            document.Save(OutputFolder + @"\TestStringInRectangle.pdf");
            document.Dispose();
        }
示例#29
0
        public void TestEditFields()
        {
            Document document = new Document();

            document.Pages.Add(new Page(PaperFormat.A4));

            EditBox edit1 = new EditBox(10, 10, 100, 20, "Edit1");

            edit1.Text      = "Simple edit box";
            edit1.Font.Size = 8;

            EditBox edit2 = new EditBox(10, 40, 100, 20, "Edit2");

            edit2.Text      = "Centered text";
            edit2.TextAlign = TextAlign.Center;
            edit2.Font.Size = 8;

            EditBox edit3 = new EditBox(10, 70, 100, 20, "Edit3");

            edit3.Text      = "Right align";
            edit3.TextAlign = TextAlign.Right;
            edit3.Font.Size = 8;

            EditBox edit4 = new EditBox(10, 100, 100, 20, "Edit4");

            edit4.Text      = "Simple edit box Simple edit box";
            edit4.Font.Size = 8;

            EditBox edit5 = new EditBox(10, 130, 100, 20, "Edit5");

            edit5.Text      = "Centered text Centered text Centered text";
            edit5.TextAlign = TextAlign.Center;
            edit5.Font.Size = 8;

            EditBox edit6 = new EditBox(10, 160, 100, 20, "Edit6");

            edit6.Text      = "Right align Right align Right align";
            edit6.TextAlign = TextAlign.Right;
            edit6.Font.Size = 8;

            //password
            EditBox edit7 = new EditBox(120, 10, 100, 20, "Edit7");

            edit7.Text      = "Simple edit box";
            edit7.Font.Size = 8;
            edit7.Password  = true;

            EditBox edit8 = new EditBox(120, 40, 100, 20, "Edit8");

            edit8.Text      = "Centered text";
            edit8.TextAlign = TextAlign.Center;
            edit8.Font.Size = 8;
            edit8.Password  = true;

            EditBox edit9 = new EditBox(120, 70, 100, 20, "Edit9");

            edit9.Text      = "Right align";
            edit9.TextAlign = TextAlign.Right;
            edit9.Font.Size = 8;
            edit9.Password  = true;

            EditBox edit10 = new EditBox(120, 100, 100, 20, "Edit10");

            edit10.Text      = "Simple edit box Simple edit box";
            edit10.Font.Size = 8;
            edit10.Password  = true;

            EditBox edit11 = new EditBox(120, 130, 100, 20, "Edit11");

            edit11.Text      = "Centered text Centered text Centered text";
            edit11.TextAlign = TextAlign.Center;
            edit11.Font.Size = 8;
            edit11.Password  = true;

            EditBox edit12 = new EditBox(120, 160, 100, 20, "Edit12");

            edit12.Text      = "Right align Right align Right align";
            edit12.TextAlign = TextAlign.Right;
            edit12.Font.Size = 8;
            edit12.Password  = true;

            //maxlength
            EditBox edit13 = new EditBox(230, 10, 100, 20, "Edit13");

            edit13.Text      = "Simple edit box";
            edit13.Font.Size = 8;
            edit13.MaxLength = 8;

            EditBox edit14 = new EditBox(230, 40, 100, 20, "Edit14");

            edit14.Text      = "Centered text";
            edit14.TextAlign = TextAlign.Center;
            edit14.Font.Size = 8;
            edit14.MaxLength = 8;

            EditBox edit15 = new EditBox(230, 70, 100, 20, "Edit15");

            edit15.Text      = "Right align";
            edit15.TextAlign = TextAlign.Right;
            edit15.Font.Size = 8;
            edit15.MaxLength = 8;

            EditBox edit16 = new EditBox(230, 100, 100, 20, "Edit16");

            edit16.Text      = "Simple edit box Simple edit box";
            edit16.Font.Size = 8;
            edit16.MaxLength = 8;

            EditBox edit17 = new EditBox(230, 130, 100, 20, "Edit17");

            edit17.Text      = "Centered text Centered text Centered text";
            edit17.TextAlign = TextAlign.Center;
            edit17.Font.Size = 8;
            edit17.MaxLength = 8;

            EditBox edit18 = new EditBox(230, 160, 100, 20, "Edit18");

            edit18.Text      = "Right align Right align Right align";
            edit18.TextAlign = TextAlign.Right;
            edit18.Font.Size = 8;
            edit18.MaxLength = 8;

            //comb
            EditBox edit19 = new EditBox(340, 10, 100, 20, "Edit19");

            edit19.Text         = "Left";
            edit19.Font.Size    = 8;
            edit19.MaxLength    = 8;
            edit19.InsertSpaces = true;

            EditBox edit20 = new EditBox(340, 40, 100, 20, "Edit20");

            edit20.Text         = "Center";
            edit20.TextAlign    = TextAlign.Center;
            edit20.Font.Size    = 8;
            edit20.MaxLength    = 8;
            edit20.InsertSpaces = true;

            EditBox edit21 = new EditBox(340, 70, 100, 20, "Edit21");

            edit21.Text         = "Right";
            edit21.TextAlign    = TextAlign.Right;
            edit21.Font.Size    = 8;
            edit21.MaxLength    = 8;
            edit21.InsertSpaces = true;

            EditBox edit22 = new EditBox(340, 100, 100, 20, "Edit22");

            edit22.Text         = "Simple edit box Simple edit box";
            edit22.Font.Size    = 8;
            edit22.MaxLength    = 8;
            edit22.InsertSpaces = true;

            EditBox edit23 = new EditBox(340, 130, 100, 20, "Edit23");

            edit23.Text         = "Centered text Centered text Centered text";
            edit23.TextAlign    = TextAlign.Center;
            edit23.Font.Size    = 8;
            edit23.MaxLength    = 8;
            edit23.InsertSpaces = true;

            EditBox edit24 = new EditBox(340, 160, 100, 20, "Edit24");

            edit24.Text         = "Right align Right align Right align";
            edit24.TextAlign    = TextAlign.Right;
            edit24.Font.Size    = 8;
            edit24.MaxLength    = 8;
            edit24.InsertSpaces = true;

            SolidPen pen = new SolidPen();

            pen.DashPattern = new DashPattern(new float[] { 3 });
            document.Pages[0].Canvas.DrawLine(pen, 10, 200, document.Pages[0].Width - 10, 200);
            Font       fnt = new Font(StandardFonts.Helvetica, 16);
            SolidBrush br  = new SolidBrush();

            document.Pages[0].Canvas.DrawString("Multiline Edit Box", fnt, br, 250, 210);


            //multiline
            EditBox edit25 = new EditBox(10, 230, 100, 30, "Edit25");

            edit25.Text      = "Simple edit box Simple edit box";
            edit25.Font.Size = 8;
            edit25.Multiline = true;

            EditBox edit26 = new EditBox(10, 270, 100, 30, "Edit26");

            edit26.Text      = "Centered text Centered text";
            edit26.TextAlign = TextAlign.Center;
            edit26.Font.Size = 8;
            edit26.Multiline = true;

            EditBox edit27 = new EditBox(10, 310, 100, 30, "Edit27");

            edit27.Text      = "Right align Right align blah blah";
            edit27.TextAlign = TextAlign.Right;
            edit27.Font.Size = 8;
            edit27.Multiline = true;

            EditBox edit28 = new EditBox(10, 350, 100, 30, "Edit28");

            edit28.Text      = "Simple edit box Simple edit box Simple edit box Simple edit box";
            edit28.Font.Size = 8;
            edit28.Multiline = true;

            EditBox edit29 = new EditBox(10, 390, 100, 30, "Edit29");

            edit29.Text      = "Centered text Centered text Centered text Centered text Centered text Centered text";
            edit29.TextAlign = TextAlign.Center;
            edit29.Font.Size = 8;
            edit29.Multiline = true;

            EditBox edit30 = new EditBox(10, 430, 100, 30, "Edit30");

            edit30.Text      = "Right align Right align Right align Right align Right align Right align";
            edit30.TextAlign = TextAlign.Right;
            edit30.Font.Size = 8;
            edit30.Multiline = true;

            //multiline password
            EditBox edit31 = new EditBox(120, 230, 100, 30, "Edit31");

            edit31.Text      = "Simple edit box Simple edit box";
            edit31.Font.Size = 8;
            edit31.Multiline = true;
            edit31.Password  = true;

            EditBox edit32 = new EditBox(120, 270, 100, 30, "Edit32");

            edit32.Text      = "Centered text Centered text";
            edit32.TextAlign = TextAlign.Center;
            edit32.Font.Size = 8;
            edit32.Multiline = true;
            edit32.Password  = true;

            EditBox edit33 = new EditBox(120, 310, 100, 30, "Edit33");

            edit33.Text      = "Right align Right align blah blah";
            edit33.TextAlign = TextAlign.Right;
            edit33.Font.Size = 8;
            edit33.Multiline = true;
            edit33.Password  = true;

            EditBox edit34 = new EditBox(120, 350, 100, 30, "Edit34");

            edit34.Text      = "Simple edit box Simple edit box Simple edit box Simple edit box";
            edit34.Font.Size = 8;
            edit34.Multiline = true;
            edit34.Password  = true;

            EditBox edit35 = new EditBox(120, 390, 100, 30, "Edit35");

            edit35.Text      = "Centered text Centered text Centered text Centered text Centered text Centered text";
            edit35.TextAlign = TextAlign.Center;
            edit35.Font.Size = 8;
            edit35.Multiline = true;
            edit35.Password  = true;

            EditBox edit36 = new EditBox(120, 430, 100, 30, "Edit36");

            edit36.Text      = "Right align Right align Right align Right align Right align Right align";
            edit36.TextAlign = TextAlign.Right;
            edit36.Font.Size = 8;
            edit36.Password  = true;
            edit36.Multiline = true;

            //maxlength
            EditBox edit37 = new EditBox(230, 230, 100, 30, "Edit37");

            edit37.Text      = "Simple edit box Simple edit box";
            edit37.Font.Size = 8;
            edit37.Multiline = true;
            edit37.MaxLength = 8;

            EditBox edit38 = new EditBox(230, 270, 100, 30, "Edit38");

            edit38.Text      = "Centered text Centered text";
            edit38.TextAlign = TextAlign.Center;
            edit38.Font.Size = 8;
            edit38.Multiline = true;
            edit38.MaxLength = 8;

            EditBox edit39 = new EditBox(230, 310, 100, 30, "Edit39");

            edit39.Text      = "Right align Right align blah blah";
            edit39.TextAlign = TextAlign.Right;
            edit39.Font.Size = 8;
            edit39.Multiline = true;
            edit39.MaxLength = 8;

            EditBox edit40 = new EditBox(230, 350, 100, 30, "Edit40");

            edit40.Text      = "Simple edit box Simple edit box Simple edit box Simple edit box";
            edit40.Font.Size = 8;
            edit40.Multiline = true;
            edit40.MaxLength = 8;

            EditBox edit41 = new EditBox(230, 390, 100, 30, "Edit41");

            edit41.Text      = "Centered text Centered text Centered text Centered text Centered text Centered text";
            edit41.TextAlign = TextAlign.Center;
            edit41.Font.Size = 8;
            edit41.Multiline = true;
            edit41.MaxLength = 8;

            EditBox edit42 = new EditBox(230, 430, 100, 30, "Edit42");

            edit42.Text      = "Right align Right align Right align Right align Right align Right align";
            edit42.TextAlign = TextAlign.Right;
            edit42.Font.Size = 8;
            edit42.Multiline = true;
            edit42.MaxLength = 8;

            document.Pages[0].Annotations.Add(edit1);
            document.Pages[0].Annotations.Add(edit2);
            document.Pages[0].Annotations.Add(edit3);
            document.Pages[0].Annotations.Add(edit4);
            document.Pages[0].Annotations.Add(edit5);
            document.Pages[0].Annotations.Add(edit6);
            document.Pages[0].Annotations.Add(edit7);
            document.Pages[0].Annotations.Add(edit8);
            document.Pages[0].Annotations.Add(edit9);
            document.Pages[0].Annotations.Add(edit10);
            document.Pages[0].Annotations.Add(edit11);
            document.Pages[0].Annotations.Add(edit12);
            document.Pages[0].Annotations.Add(edit13);
            document.Pages[0].Annotations.Add(edit14);
            document.Pages[0].Annotations.Add(edit15);
            document.Pages[0].Annotations.Add(edit16);
            document.Pages[0].Annotations.Add(edit17);
            document.Pages[0].Annotations.Add(edit18);
            document.Pages[0].Annotations.Add(edit19);
            document.Pages[0].Annotations.Add(edit20);
            document.Pages[0].Annotations.Add(edit21);
            document.Pages[0].Annotations.Add(edit22);
            document.Pages[0].Annotations.Add(edit23);
            document.Pages[0].Annotations.Add(edit24);
            document.Pages[0].Annotations.Add(edit25);
            document.Pages[0].Annotations.Add(edit26);
            document.Pages[0].Annotations.Add(edit27);
            document.Pages[0].Annotations.Add(edit28);
            document.Pages[0].Annotations.Add(edit29);
            document.Pages[0].Annotations.Add(edit30);
            document.Pages[0].Annotations.Add(edit31);
            document.Pages[0].Annotations.Add(edit32);
            document.Pages[0].Annotations.Add(edit33);
            document.Pages[0].Annotations.Add(edit34);
            document.Pages[0].Annotations.Add(edit35);
            document.Pages[0].Annotations.Add(edit36);
            document.Pages[0].Annotations.Add(edit37);
            document.Pages[0].Annotations.Add(edit38);
            document.Pages[0].Annotations.Add(edit39);
            document.Pages[0].Annotations.Add(edit40);
            document.Pages[0].Annotations.Add(edit41);
            document.Pages[0].Annotations.Add(edit42);

            document.Save(OutputFolder + @"\TestEditFields.pdf");
            document.Dispose();
        }
示例#30
0
        static void Main()
        {
            #region Declarations and Implementations

            SolidPen solidPen = new SolidPen();

            Brush blackBrush = new SolidBrush(new ColorRGB(0, 0, 0));

            Font headerFont  = new Font(StandardFonts.TimesBold, 24);
            Font headerFont2 = new Font(StandardFonts.TimesBold, 16);

            Font contentFont_12 = new Font(StandardFonts.TimesBold, 12);
            Font contentFont_10 = new Font(StandardFonts.Times, 10);


            // Create new document
            pdfDocument = new Document();
            pdfDocument.RegistrationName = "demo";
            pdfDocument.RegistrationKey  = "demo";

            #endregion

            // Add new page
            AddNewPage();

            /* 1. Add Content */
            page.Canvas.DrawString("COMPANY NAME", contentFont_12, blackBrush, 50, (HeightUtilized += 20));

            page.Canvas.DrawString("Address", contentFont_10, blackBrush, 50, (HeightUtilized += 20));
            page.Canvas.DrawString("DATE", contentFont_10, blackBrush, 400, HeightUtilized);

            page.Canvas.DrawString("Phone, fax", contentFont_10, blackBrush, 50, (HeightUtilized += 20));
            page.Canvas.DrawString("INVOICE #", contentFont_10, blackBrush, 400, HeightUtilized);

            page.Canvas.DrawString("E-mail", contentFont_10, blackBrush, 50, (HeightUtilized += 20));
            page.Canvas.DrawString("FOR", contentFont_10, blackBrush, 400, HeightUtilized);

            // Add some vertical space
            HeightUtilized += 50;

            /* 2. Add Table which can span multipage */
            Console.WriteLine("Enter the number of rows to add to the table:");
            int numberOfRows = Convert.ToInt32(Console.ReadLine());
            DrawTable(NumberOfRows: numberOfRows);

            /* 3. Add Signature */
            // Check new page needed for adding signature
            if (CheckNewPageNeeded(70))
            {
                AddNewPage();
            }

            page.Canvas.DrawString("Signature", contentFont_12, blackBrush, 400, (HeightUtilized + 57));
            page.Canvas.DrawLine(solidPen, 450, (HeightUtilized + 70), 570, (HeightUtilized + 70));

            /* 4. Add Header And Footer*/

            for (int pageIndex = 0; pageIndex < pdfDocument.Pages.Count; pageIndex++)
            {
                var curPage = pdfDocument.Pages[pageIndex];

                // Add Logo
                Image imageLogo = new Image("logo.png");
                curPage.Canvas.DrawImage(imageLogo, 20, 45, imageLogo.Width / 2, imageLogo.Height / 2);

                // Add requisites
                curPage.Canvas.DrawString("INVOICE", headerFont, blackBrush, 450, 55);

                // Add Page Number
                curPage.Canvas.DrawLine(solidPen, 20, 750, 590, 750);
                curPage.Canvas.DrawString($"Page: {pageIndex + 1} of {pdfDocument.Pages.Count}", contentFont_10, blackBrush, 30, 760);
            }

            // Save document to file
            pdfDocument.Save("result.pdf");

            // Cleanup
            pdfDocument.Dispose();

            // Open result document in default associated application (for demo purpose)
            ProcessStartInfo processStartInfo = new ProcessStartInfo("result.pdf");
            processStartInfo.UseShellExecute = true;
            Process.Start(processStartInfo);
        }