예제 #1
0
        /**
         * <summary>Populates a PDF file with contents.</summary>
         */
        private void Populate(
            Document document
            )
        {
            // 1. Add the page to the document!
            Page page = new Page(document); // Instantiates the page inside the document context.

            document.Pages.Add(page);       // Puts the page in the pages collection.

            // 2. Create a content composer for the page!
            PrimitiveComposer composer = new PrimitiveComposer(page);

            colors::Color textColor = new colors::DeviceRGBColor(115 / 255d, 164 / 255d, 232 / 255d);

            composer.SetFillColor(textColor);
            composer.SetLineDash(new LineDash(new double[] { 10 }));
            composer.SetLineWidth(.25);

            BlockComposer blockComposer = new BlockComposer(composer);

            blockComposer.Begin(new RectangleF(300, 400, 200, 100), XAlignmentEnum.Left, YAlignmentEnum.Middle);
            composer.SetFont(new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Times, false, true), 12);
            blockComposer.ShowText("PrimitiveComposer.ShowText(...) methods return the actual bounding box of the text shown, allowing to precisely determine its location on the page.");
            blockComposer.End();

            // 3. Inserting contents...
            // Set the font to use!
            composer.SetFont(new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Courier, true, false), 72);
            composer.DrawPolygon(
                composer.ShowText(
                    "Text frame",
                    new PointF(150, 360),
                    XAlignmentEnum.Left,
                    YAlignmentEnum.Middle,
                    45
                    ).Points
                );
            composer.Stroke();

            composer.SetFont(fonts::Font.Get(document, GetResourcePath("fonts" + System.IO.Path.DirectorySeparatorChar + "Ruritania-Outline.ttf")), 102);
            composer.DrawPolygon(
                composer.ShowText(
                    "Text frame",
                    new PointF(250, 600),
                    XAlignmentEnum.Center,
                    YAlignmentEnum.Middle,
                    -25
                    ).Points
                );
            composer.Stroke();

            // 4. Flush the contents into the page!
            composer.Flush();
        }
예제 #2
0
 private void DrawFrame(PrimitiveComposer composer, SKPoint[] frameVertices)
 {
     composer.BeginLocalState();
     composer.SetLineWidth(0.2f);
     composer.SetLineDash(new LineDash(new float[] { 5 }, 5));
     composer.DrawPolygon(frameVertices);
     composer.Stroke();
     composer.End();
 }
        /**
         * <summary>Populates a PDF file with contents.</summary>
         */
        private void Populate(
            Document document
            )
        {
            // 1. Add the page to the document!
            Page page = new Page(document); // Instantiates the page inside the document context.

            document.Pages.Add(page);       // Puts the page in the pages collection.
            SizeF pageSize = page.Size;

            // 2. Create a content composer for the page!
            PrimitiveComposer composer = new PrimitiveComposer(page);

            // 3. Inserting contents...
            // Set the font to use!
            composer.SetFont(new StandardType1Font(document, StandardType1Font.FamilyEnum.Courier, true, false), 30);
            // Show the text onto the page (along with its box)!

            /*
             * NOTE: PrimitiveComposer's ShowText() method is the most basic way to add text to a page
             * -- see BlockComposer for more advanced uses (horizontal and vertical alignment, hyphenation,
             * etc.).
             */
            composer.ShowText(
                "Hello World!",
                new PointF(32, 48)
                );

            composer.SetLineWidth(.25);
            composer.SetLineCap(LineCapEnum.Round);
            composer.SetLineDash(new LineDash(new double[] { 5, 10 }));
            composer.SetTextLead(1.2);
            composer.DrawPolygon(
                composer.ShowText(
                    "This is a primitive example"
                    + "\nof centered, rotated multi-"
                    + "\nline text."
                    + "\n\nWe recommend you to use"
                    + "\nBlockComposer instead, as it"
                    + "\nautomatically manages text"
                    + "\nwrapping and alignment with-"
                    + "\nin a specified area!",
                    new PointF(pageSize.Width / 2, pageSize.Height / 2),
                    XAlignmentEnum.Center,
                    YAlignmentEnum.Middle,
                    15
                    ).Points
                );
            composer.Stroke();

            // 4. Flush the contents into the page!
            composer.Flush();
        }
예제 #4
0
        private void BuildMiscellaneousPage(
            Document document
            )
        {
            // 1. Add the page to the document!
            Page page = new Page(document); // Instantiates the page inside the document context.

            document.Pages.Add(page);       // Puts the page in the pages collection.

            SizeF pageSize = page.Size;

            // 2. Create a content composer for the page!
            PrimitiveComposer composer = new PrimitiveComposer(page);

            // 3. Drawing the page contents...
            composer.SetFont(
                new fonts::StandardType1Font(
                    document,
                    fonts::StandardType1Font.FamilyEnum.Courier,
                    true,
                    false
                    ),
                32
                );

            {
                BlockComposer blockComposer = new BlockComposer(composer);
                blockComposer.Begin(new RectangleF(30, 0, pageSize.Width - 60, 50), XAlignmentEnum.Center, YAlignmentEnum.Middle);
                blockComposer.ShowText("Miscellaneous");
                blockComposer.End();
            }

            composer.BeginLocalState();
            composer.SetLineJoin(LineJoinEnum.Round);
            composer.SetLineCap(LineCapEnum.Round);

            // 3.1. Polygon.
            composer.DrawPolygon(
                new PointF[]
            {
                new PointF(100, 200),
                new PointF(150, 150),
                new PointF(200, 150),
                new PointF(250, 200)
            }
                );

            // 3.2. Polyline.
            composer.DrawPolyline(
                new PointF[]
            {
                new PointF(300, 200),
                new PointF(350, 150),
                new PointF(400, 150),
                new PointF(450, 200)
            }
                );

            composer.Stroke();

            // 3.3. Rectangle (both squared and rounded).
            int x      = 50;
            int radius = 0;

            while (x < 500)
            {
                if (x > 300)
                {
                    composer.SetLineDash(new LineDash(new double[] { 5, 5 }, 3));
                }

                composer.SetFillColor(new DeviceRGBColor(1, x / 500d, x / 500d));
                composer.DrawRectangle(
                    new RectangleF(x, 250, 150, 100),
                    radius // NOTE: radius parameter determines the rounded angle size.
                    );
                composer.FillStroke();

                x      += 175;
                radius += 10;
            }
            composer.End(); // End local state.

            composer.BeginLocalState();
            composer.SetFont(
                composer.State.Font,
                12
                );

            // 3.4. Line cap parameter.
            int y = 400;

            foreach (LineCapEnum lineCap
                     in (LineCapEnum[])Enum.GetValues(typeof(LineCapEnum)))
            {
                composer.ShowText(
                    lineCap + ":",
                    new PointF(50, y),
                    XAlignmentEnum.Left,
                    YAlignmentEnum.Middle,
                    0
                    );
                composer.SetLineWidth(12);
                composer.SetLineCap(lineCap);
                composer.DrawLine(
                    new PointF(120, y),
                    new PointF(220, y)
                    );
                composer.Stroke();

                composer.BeginLocalState();
                composer.SetLineWidth(1);
                composer.SetStrokeColor(DeviceRGBColor.White);
                composer.SetLineCap(LineCapEnum.Butt);
                composer.DrawLine(
                    new PointF(120, y),
                    new PointF(220, y)
                    );
                composer.Stroke();
                composer.End(); // End local state.

                y += 30;
            }

            // 3.5. Line join parameter.
            y += 50;
            foreach (LineJoinEnum lineJoin
                     in (LineJoinEnum[])Enum.GetValues(typeof(LineJoinEnum)))
            {
                composer.ShowText(
                    lineJoin + ":",
                    new PointF(50, y),
                    XAlignmentEnum.Left,
                    YAlignmentEnum.Middle,
                    0
                    );
                composer.SetLineWidth(12);
                composer.SetLineJoin(lineJoin);
                PointF[] points = new PointF[]
                {
                    new PointF(120, y + 25),
                    new PointF(150, y - 25),
                    new PointF(180, y + 25)
                };
                composer.DrawPolyline(points);
                composer.Stroke();

                composer.BeginLocalState();
                composer.SetLineWidth(1);
                composer.SetStrokeColor(DeviceRGBColor.White);
                composer.SetLineCap(LineCapEnum.Butt);
                composer.DrawPolyline(points);
                composer.Stroke();
                composer.End(); // End local state.

                y += 50;
            }
            composer.End(); // End local state.

            // 3.6. Clipping.

            /*
             * NOTE: Clipping should be conveniently enclosed within a local state
             * in order to easily resume the unaltered drawing area after the operation completes.
             */
            composer.BeginLocalState();
            composer.DrawPolygon(
                new PointF[]
            {
                new PointF(220, 410),
                new PointF(300, 490),
                new PointF(450, 360),
                new PointF(430, 520),
                new PointF(590, 565),
                new PointF(420, 595),
                new PointF(460, 730),
                new PointF(380, 650),
                new PointF(330, 765),
                new PointF(310, 640),
                new PointF(220, 710),
                new PointF(275, 570),
                new PointF(170, 500),
                new PointF(275, 510)
            }
                );
            composer.Clip();
            // Showing a clown image...
            // Instantiate a jpeg image object!
            entities::Image   image        = entities::Image.Get(GetResourcePath("images" + System.IO.Path.DirectorySeparatorChar + "Clown.jpg")); // Abstract image (entity).
            xObjects::XObject imageXObject = image.ToXObject(document);

            // Show the image!
            composer.ShowXObject(
                imageXObject,
                new PointF(170, 320),
                GeomUtils.Scale(imageXObject.Size, new SizeF(450, 0))
                );
            composer.End(); // End local state.

            // 4. Flush the contents into the page!
            composer.Flush();
        }
예제 #5
0
        /**
         * <summary>Scans a content level looking for text.</summary>
         */
        /*
         * NOTE: Page contents are represented by a sequence of content objects,
         * possibly nested into multiple levels.
         */
        private void Extract(ContentScanner level, PrimitiveComposer composer)
        {
            if (level == null)
            {
                return;
            }

            while (level.MoveNext())
            {
                ContentObject content = level.Current;
                if (content is Text)
                {
                    TextWrapper text       = (TextWrapper)level.CurrentWrapper;
                    int         colorIndex = 0;
                    foreach (TextStringWrapper textString in text.TextStrings)
                    {
                        SKRect textStringBox = textString.Box.Value;
                        Console.WriteLine(
                            "Text ["
                            + "x:" + Math.Round(textStringBox.Left) + ","
                            + "y:" + Math.Round(textStringBox.Top) + ","
                            + "w:" + Math.Round(textStringBox.Width) + ","
                            + "h:" + Math.Round(textStringBox.Height)
                            + "] [font size:" + Math.Round(textString.Style.FontSize) + "]: " + textString.Text
                            );

                        // Drawing text character bounding boxes...
                        colorIndex = (colorIndex + 1) % textCharBoxColors.Length;
                        composer.SetStrokeColor(textCharBoxColors[colorIndex]);
                        foreach (TextChar textChar in textString.TextChars)
                        {
                            /*
                             * NOTE: You can get further text information
                             * (font, font size, text color, text rendering mode)
                             * through textChar.style.
                             */
                            composer.DrawPolygon(textChar.Quad.GetPoints());
                            composer.Stroke();
                        }

                        // Drawing text string bounding box...
                        composer.BeginLocalState();
                        composer.SetLineDash(new LineDash(new float[] { 5 }));
                        composer.SetStrokeColor(textStringBoxColor);
                        composer.DrawRectangle(textString.Box.Value);
                        composer.Stroke();
                        composer.End();
                    }
                }
                else if (content is XObject)
                {
                    // Scan the external level!
                    Extract(((XObject)content).GetScanner(level), composer);
                }
                else if (content is ContainerObject)
                {
                    // Scan the inner level!
                    Extract(level.ChildLevel, composer);
                }
            }
        }
예제 #6
0
        private void BuildMiscellaneousPage(
            Document document
            )
        {
            // 1. Add the page to the document!
              Page page = new Page(document); // Instantiates the page inside the document context.
              document.Pages.Add(page); // Puts the page in the pages collection.

              SizeF pageSize = page.Size;

              // 2. Create a content composer for the page!
              PrimitiveComposer composer = new PrimitiveComposer(page);

              // 3. Drawing the page contents...
              composer.SetFont(
            new fonts::StandardType1Font(
              document,
              fonts::StandardType1Font.FamilyEnum.Courier,
              true,
              false
              ),
            32
            );

              {
            BlockComposer blockComposer = new BlockComposer(composer);
            blockComposer.Begin(new RectangleF(30,0,pageSize.Width-60,50),XAlignmentEnum.Center,YAlignmentEnum.Middle);
            blockComposer.ShowText("Miscellaneous");
            blockComposer.End();
              }

              composer.BeginLocalState();
              composer.SetLineJoin(LineJoinEnum.Round);
              composer.SetLineCap(LineCapEnum.Round);

              // 3.1. Polygon.
              composer.DrawPolygon(
            new PointF[]
            {
              new PointF(100,200),
              new PointF(150,150),
              new PointF(200,150),
              new PointF(250,200)
            }
            );

              // 3.2. Polyline.
              composer.DrawPolyline(
            new PointF[]
            {
              new PointF(300,200),
              new PointF(350,150),
              new PointF(400,150),
              new PointF(450,200)
            }
            );

              composer.Stroke();

              // 3.3. Rectangle (both squared and rounded).
              int x = 50;
              int radius = 0;
              while(x < 500)
              {
            if(x > 300)
            {
              composer.SetLineDash(new LineDash(new double[]{5,5}, 3));
            }

            composer.SetFillColor(new DeviceRGBColor(1, x / 500d, x / 500d));
            composer.DrawRectangle(
              new RectangleF(x, 250, 150, 100),
              radius // NOTE: radius parameter determines the rounded angle size.
              );
            composer.FillStroke();

            x += 175;
            radius += 10;
              }
              composer.End(); // End local state.

              composer.BeginLocalState();
              composer.SetFont(
            composer.State.Font,
            12
            );

              // 3.4. Line cap parameter.
              int y = 400;
              foreach(LineCapEnum lineCap
            in (LineCapEnum[])Enum.GetValues(typeof(LineCapEnum)))
              {
            composer.ShowText(
              lineCap + ":",
              new PointF(50,y),
              XAlignmentEnum.Left,
              YAlignmentEnum.Middle,
              0
              );
            composer.SetLineWidth(12);
            composer.SetLineCap(lineCap);
            composer.DrawLine(
              new PointF(120,y),
              new PointF(220,y)
              );
            composer.Stroke();

            composer.BeginLocalState();
            composer.SetLineWidth(1);
            composer.SetStrokeColor(DeviceRGBColor.White);
            composer.SetLineCap(LineCapEnum.Butt);
            composer.DrawLine(
              new PointF(120,y),
              new PointF(220,y)
              );
            composer.Stroke();
            composer.End(); // End local state.

            y += 30;
              }

              // 3.5. Line join parameter.
              y += 50;
              foreach(LineJoinEnum lineJoin
            in (LineJoinEnum[])Enum.GetValues(typeof(LineJoinEnum)))
              {
            composer.ShowText(
              lineJoin + ":",
              new PointF(50,y),
              XAlignmentEnum.Left,
              YAlignmentEnum.Middle,
              0
              );
            composer.SetLineWidth(12);
            composer.SetLineJoin(lineJoin);
            PointF[] points = new PointF[]
              {
            new PointF(120,y+25),
            new PointF(150,y-25),
            new PointF(180,y+25)
              };
            composer.DrawPolyline(points);
            composer.Stroke();

            composer.BeginLocalState();
            composer.SetLineWidth(1);
            composer.SetStrokeColor(DeviceRGBColor.White);
            composer.SetLineCap(LineCapEnum.Butt);
            composer.DrawPolyline(points);
            composer.Stroke();
            composer.End(); // End local state.

            y += 50;
              }
              composer.End(); // End local state.

              // 3.6. Clipping.
              /*
            NOTE: Clipping should be conveniently enclosed within a local state
            in order to easily resume the unaltered drawing area after the operation completes.
              */
              composer.BeginLocalState();
              composer.DrawPolygon(
            new PointF[]
            {
              new PointF(220,410),
              new PointF(300,490),
              new PointF(450,360),
              new PointF(430,520),
              new PointF(590,565),
              new PointF(420,595),
              new PointF(460,730),
              new PointF(380,650),
              new PointF(330,765),
              new PointF(310,640),
              new PointF(220,710),
              new PointF(275,570),
              new PointF(170,500),
              new PointF(275,510)
            }
            );
              composer.Clip();
              // Showing a clown image...
              // Instantiate a jpeg image object!
              entities::Image image = entities::Image.Get(GetResourcePath("images" + System.IO.Path.DirectorySeparatorChar + "Clown.jpg")); // Abstract image (entity).
              xObjects::XObject imageXObject = image.ToXObject(document);
              // Show the image!
              composer.ShowXObject(
            imageXObject,
            new PointF(170, 320),
            GeomUtils.Scale(imageXObject.Size, new SizeF(450,0))
            );
              composer.End(); // End local state.

              // 4. Flush the contents into the page!
              composer.Flush();
        }
예제 #7
0
 private void DrawFrame(
     PrimitiveComposer composer,
     PointF[] frameVertices
     )
 {
     composer.BeginLocalState();
       composer.SetLineWidth(0.2f);
       composer.SetLineDash(new LineDash(new double[]{5,5}, 5));
       composer.DrawPolygon(frameVertices);
       composer.Stroke();
       composer.End();
 }
예제 #8
0
        /**
          <summary>Populates a PDF file with contents.</summary>
        */
        private void Populate(
            Document document
            )
        {
            // 1. Add the page to the document!
              Page page = new Page(document); // Instantiates the page inside the document context.
              document.Pages.Add(page); // Puts the page in the pages collection.

              // 2. Create a content composer for the page!
              PrimitiveComposer composer = new PrimitiveComposer(page);

              colors::Color textColor = new colors::DeviceRGBColor(115 / 255d, 164 / 255d, 232 / 255d);
              composer.SetFillColor(textColor);

              BlockComposer blockComposer = new BlockComposer(composer);
              blockComposer.Begin(new RectangleF(300, 400, 200, 100), XAlignmentEnum.Left, YAlignmentEnum.Middle);
              composer.SetFont(
            new fonts::StandardType1Font(
              document,
              fonts::StandardType1Font.FamilyEnum.Times,
              false,
              true
              ),
            12
            );
              blockComposer.ShowText("PrimitiveComposer.ShowText(...) methods return the actual bounding box of the text shown, allowing to precisely determine its location on the page.");
              blockComposer.End();

              // 3. Inserting contents...
              // Set the font to use!
              composer.SetFont(
            new fonts::StandardType1Font(
              document,
              fonts::StandardType1Font.FamilyEnum.Courier,
              true,
              false
              ),
            72
            );
              composer.DrawPolygon(
            composer.ShowText(
              "Text frame",
              new PointF(150, 360),
              XAlignmentEnum.Left,
              YAlignmentEnum.Middle,
              45
              ).Points
            );
              composer.Stroke();

              composer.SetFont(
            fonts::Font.Get(
              document,
              GetResourcePath("fonts" + System.IO.Path.DirectorySeparatorChar + "Ruritania-Outline.ttf")
              ),
            102
            );
              composer.DrawPolygon(
            composer.ShowText(
              "Text frame",
              new PointF(300, 600),
              XAlignmentEnum.Center,
              YAlignmentEnum.Middle,
              -25
              ).Points
            );
              composer.Stroke();

              // 4. Flush the contents into the page!
              composer.Flush();
        }