Ejemplo n.º 1
0
        public static void AddShape2()
        {
            //This example is using document level builder
            PdfDocument document = new PdfDocument();

            using (PdfDocumentBuilder builder = new PdfDocumentBuilder(document))
            {
                //Add line shape
                Block lineBlock = new Block();
                lineBlock.GraphicState.StrokeColor = new RgbColor(255, 0, 0);
                lineBlock.InsertLine(new Point(10, 10), new Point(200, 20));
                builder.InsertBlock(lineBlock);

                //Add rectangle shape
                Block rectBlock = new Block();
                rectBlock.GraphicState.StrokeColor = new RgbColor(255, 0, 0);
                rectBlock.GraphicState.FillColor   = new RgbColor(0, 255, 0);
                rectBlock.GraphicState.IsFilled    = true;
                rectBlock.InsertRectangle(new Rect(0, 0, 50, 50));
                builder.InsertBlock(rectBlock);
            }

            using (FileStream fs = File.Create("AddShape2.pdf"))
            {
                PdfFile pdfFile = new PdfFile();
                pdfFile.Export(document, fs);
            }
        }