コード例 #1
0
        private void BuildContent(Document document)
        {
            // Set default page size (A4)!
            document.PageSize = PageFormat.GetSize();
            // Add a font to the fonts collection!
            document.Resources.Fonts[ResourceName_DefaultFont] = PdfType1Font.Load(document, PdfType1Font.FamilyEnum.Courier, true, false);

            // Add a 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.

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

            string[]             steps  = new string[5];
            colorSpaces::Color[] colors = new colorSpaces::Color[5];
            SKSize pageSize             = page.Size;

            BuildSteps(composer, steps, colors, pageSize);

            BuildLegend(composer, steps, colors, pageSize);

            composer.Flush();
        }
コード例 #2
0
        private void Populate(Document document)
        {
            PdfType1Font bodyFont = PdfType1Font.Load(document, PdfType1Font.FamilyEnum.Courier, true, false);

            Pages pages = document.Pages;

            PageFormat.SizeEnum[]        pageFormats      = (PageFormat.SizeEnum[])Enum.GetValues(typeof(PageFormat.SizeEnum));
            PageFormat.OrientationEnum[] pageOrientations = (PageFormat.OrientationEnum[])Enum.GetValues(typeof(PageFormat.OrientationEnum));
            foreach (PageFormat.SizeEnum pageFormat in pageFormats)
            {
                foreach (PageFormat.OrientationEnum pageOrientation in pageOrientations)
                {
                    // Add a page to the document!
                    Page page = new Page(document, PageFormat.GetSize(pageFormat, pageOrientation));
                    // Instantiates the page inside the document context.
                    pages.Add(page); // Puts the page in the pages collection.

                    // Drawing the text label on the page...
                    SKSize            pageSize = page.Size;
                    PrimitiveComposer composer = new PrimitiveComposer(page);
                    composer.SetFont(bodyFont, 32);
                    composer.ShowText(
                        pageFormat + " (" + pageOrientation + ")", // Text.
                        new SKPoint(
                            pageSize.Width / 2,
                            pageSize.Height / 2
                            ),                 // Location: page center.
                        XAlignmentEnum.Center, // Places the text on horizontal center of the location.
                        YAlignmentEnum.Middle, // Places the text on vertical middle of the location.
                        45                     // Rotates the text 45 degrees counterclockwise.
                        );
                    composer.Flush();
                }
            }
        }
コード例 #3
0
        public override void Run(
            )
        {
            // 1. Instantiate a new PDF file!
            File     file     = new File();
            Document document = file.Document;

            // 2.1. Page-level private application data.
            {
                Page page = new Page(document);
                document.Pages.Add(page);

                AppData myAppData = page.GetAppData(MyAppName);

                /*
                 * NOTE: Applications are free to define whatever structure their private data should have. In
                 * this example, we chose a PdfDictionary populating it with arbitrary entries, including a
                 * byte stream.
                 */
                PdfStream myStream = new PdfStream(new Buffer("This is just some random characters to feed the stream..."));
                myAppData.Data = new PdfDictionary(
                    new PdfName("MyPrivateEntry"), PdfBoolean.True,
                    new PdfName("MyStreamEntry"), file.Register(myStream)
                    );

                // Add some (arbitrary) graphics content on the page!
                BlockComposer composer = new BlockComposer(new PrimitiveComposer(page));
                composer.BaseComposer.SetFont(PdfType1Font.Load(document, PdfType1Font.FamilyEnum.Times, true, false), 14);
                SKSize pageSize = page.Size;
                composer.Begin(SKRect.Create(50, 50, pageSize.Width - 100, pageSize.Height - 100), XAlignmentEnum.Left, YAlignmentEnum.Top);
                composer.ShowText("This page holds private application data (see PieceInfo entry in its dictionary).");
                composer.End();
                composer.BaseComposer.Flush();
            }

            // 2.2. Document-level private application data.
            {
                AppData myAppData = document.GetAppData(MyAppName);

                /*
                 * NOTE: Applications are free to define whatever structure their private data should have. In
                 * this example, we chose a PdfDictionary populating it with arbitrary entries.
                 */
                myAppData.Data = new PdfDictionary(
                    new PdfName("MyPrivateDocEntry"), new PdfTextString("This is an arbitrary value"),
                    new PdfName("AnotherPrivateEntry"), new PdfDictionary(
                        new PdfName("SubEntry"), new PdfInteger(1287),
                        new PdfName("SomeData"), new PdfArray(
                            new PdfReal(282.773),
                            new PdfReal(14.28378)
                            )
                        )
                    );
            }

            // 3. Serialize the PDF file!
            Serialize(file, "Private application data", "editing private application data", "Page-Piece Dictionaries, private application data, metadata");
        }
コード例 #4
0
        public void Regular()
        {
            string testString = "Ali";

            builder.Regular().AddText(testString);

            Paragraph paragraph   = builder.GetParagraph();
            Text      textContent = (Text)paragraph.GetChildren()[0];

            PdfType1Font font = textContent.GetProperty <PdfType1Font>(20);

            Assert.Equal("Helvetica", font.GetFontProgram().GetFontNames().ToString());
        }
コード例 #5
0
        private void Stamp(
            Document document
            )
        {
            // 1. Instantiate the stamper!
            /* NOTE: The PageStamper is optimized for dealing with pages. */
            PageStamper stamper = new PageStamper();

            // 2. Numbering each page...
            PdfType1Font   font     = PdfType1Font.Load(document, PdfType1Font.FamilyEnum.Courier, true, false);
            DeviceRGBColor redColor = DeviceRGBColor.Get(SKColors.Red);
            int            margin   = 32;

            foreach (Page page in document.Pages)
            {
                // 2.1. Associate the page to the stamper!
                stamper.Page = page;

                // 2.2. Stamping the page number on the foreground...
                {
                    PrimitiveComposer foreground = stamper.Foreground;

                    foreground.SetFont(font, 16);
                    foreground.SetFillColor(redColor);

                    SKSize pageSize   = page.Size;
                    int    pageNumber = page.Number;
                    bool   pageIsEven = (pageNumber % 2 == 0);
                    foreground.ShowText(
                        pageNumber.ToString(),
                        new SKPoint(
                            (pageIsEven
                          ? margin
                          : pageSize.Width - margin),
                            pageSize.Height - margin
                            ),
                        (pageIsEven
                        ? XAlignmentEnum.Left
                        : XAlignmentEnum.Right),
                        YAlignmentEnum.Bottom,
                        0
                        );
                }

                // 2.3. End the stamping!
                stamper.Flush();
            }
        }
コード例 #6
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.
            SKSize 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(PdfType1Font.Load(document, PdfType1Font.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 SKPoint(32, 48));

            composer.SetLineWidth(.25);
            composer.SetLineCap(LineCapEnum.Round);
            composer.SetLineDash(new LineDash(new float[] { 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 SKPoint(pageSize.Width / 2, pageSize.Height / 2),
                    XAlignmentEnum.Center,
                    YAlignmentEnum.Middle,
                    15
                    ).GetPoints()
                );
            composer.Stroke();

            // 4. Flush the contents into the page!
            composer.Flush();
        }
コード例 #7
0
        private void Apply(
            ComboBox field
            )
        {
            Document document = field.Document;
            Widget   widget   = field.Widgets[0];

            Appearance appearance = widget.Appearance;

            widget.BaseDataObject[PdfName.DA] = new PdfString("/Helv " + FontSize + " Tf 0 0 0 rg");

            FormXObject normalAppearanceState;

            {
                SKSize size = widget.Box.Size;
                normalAppearanceState = new FormXObject(document, size);
                PrimitiveComposer composer = new PrimitiveComposer(normalAppearanceState);

                float  lineWidth = 1;
                SKRect frame     = SKRect.Create(lineWidth / 2, lineWidth / 2, size.Width - lineWidth, size.Height - lineWidth);
                if (GraphicsVisibile)
                {
                    composer.BeginLocalState();
                    composer.SetLineWidth(lineWidth);
                    composer.SetFillColor(BackColor);
                    composer.SetStrokeColor(ForeColor);
                    composer.DrawRectangle(frame, 5);
                    composer.FillStroke();
                    composer.End();
                }

                composer.BeginMarkedContent(PdfName.Tx);
                composer.SetFont(PdfType1Font.Load(document, PdfType1Font.FamilyEnum.Helvetica, false, false), FontSize);
                composer.ShowText(
                    (string)field.Value,
                    new SKPoint(0, size.Height / 2),
                    XAlignmentEnum.Left,
                    YAlignmentEnum.Middle,
                    0
                    );
                composer.End();

                composer.Flush();
            }
            appearance.Normal[null] = normalAppearanceState;
        }
コード例 #8
0
        private void Populate(
            Document document
            )
        {
            Page page = new Page(document);

            document.Pages.Add(page);
            SKSize pageSize = page.Size;

            PrimitiveComposer composer = new PrimitiveComposer(page);

            {
                BlockComposer blockComposer = new BlockComposer(composer);
                blockComposer.Hyphenation = true;
                blockComposer.Begin(
                    SKRect.Create(
                        Margin,
                        Margin,
                        (float)pageSize.Width - Margin * 2,
                        (float)pageSize.Height - Margin * 2
                        ),
                    XAlignmentEnum.Justify,
                    YAlignmentEnum.Top
                    );
                PdfType1Font bodyFont = PdfType1Font.Load(document, PdfType1Font.FamilyEnum.Courier, true, false);
                composer.SetFont(bodyFont, 32);
                blockComposer.ShowText("Inline image sample"); blockComposer.ShowBreak();
                composer.SetFont(bodyFont, 16);
                blockComposer.ShowText("Showing the GNU logo as an inline image within the page content stream.");
                blockComposer.End();
            }
            // Showing the 'GNU' image...
            {
                // Instantiate a jpeg image object!
                entities::Image image = entities::Image.Get(GetResourcePath("images" + Path.DirectorySeparatorChar + "gnu.jpg")); // Abstract image (entity).
                                                                                                                                  // Set the position of the image in the page!
                composer.ApplyMatrix(200, 0, 0, 200, (pageSize.Width - 200) / 2, (pageSize.Height - 200) / 2);
                // Show the image!
                image.ToInlineObject(composer); // Transforms the image entity into an inline image within the page.
            }
            composer.Flush();
        }
コード例 #9
0
        private void Apply(PushButton field)
        {
            Document document = field.Document;
            Widget   widget   = field.Widgets[0];

            Appearance  appearance = widget.Appearance;
            FormXObject normalAppearanceState;

            {
                SKSize size = widget.Box.Size;
                normalAppearanceState = new FormXObject(document, size);
                PrimitiveComposer composer = new PrimitiveComposer(normalAppearanceState);

                float  lineWidth = 1;
                SKRect frame     = SKRect.Create(lineWidth / 2, lineWidth / 2, size.Width - lineWidth, size.Height - lineWidth);
                if (GraphicsVisibile)
                {
                    composer.BeginLocalState();
                    composer.SetLineWidth(lineWidth);
                    composer.SetFillColor(BackColor);
                    composer.SetStrokeColor(ForeColor);
                    composer.DrawRectangle(frame, 5);
                    composer.FillStroke();
                    composer.End();
                }

                string title = (string)field.Value;
                if (title != null)
                {
                    BlockComposer blockComposer = new BlockComposer(composer);
                    blockComposer.Begin(frame, XAlignmentEnum.Center, YAlignmentEnum.Middle);
                    composer.SetFillColor(ForeColor);
                    composer.SetFont(PdfType1Font.Load(document, PdfType1Font.FamilyEnum.Helvetica, true, false), size.Height * 0.5);
                    blockComposer.ShowText(title);
                    blockComposer.End();
                }

                composer.Flush();
            }
            appearance.Normal[null] = normalAppearanceState;
        }
コード例 #10
0
        private void Apply(
            ListBox field
            )
        {
            Document document = field.Document;
            Widget   widget   = field.Widgets[0];

            Appearance appearance = widget.Appearance;
            {
                PdfDictionary widgetDataObject = widget.BaseDataObject;
                widgetDataObject[PdfName.DA] = new PdfString("/Helv " + FontSize + " Tf 0 0 0 rg");
                widgetDataObject[PdfName.MK] = new PdfDictionary(
                    new PdfName[]
                {
                    PdfName.BG,
                    PdfName.BC
                },
                    new PdfDirectObject[]
                {
                    new PdfArray(new PdfDirectObject[] { PdfReal.Get(.9), PdfReal.Get(.9), PdfReal.Get(.9) }),
                    new PdfArray(new PdfDirectObject[] { PdfInteger.Default, PdfInteger.Default, PdfInteger.Default })
                }
                    );
            }

            FormXObject normalAppearanceState;

            {
                SKSize size = widget.Box.Size;
                normalAppearanceState = new FormXObject(document, size);
                PrimitiveComposer composer = new PrimitiveComposer(normalAppearanceState);

                float  lineWidth = 1;
                SKRect frame     = SKRect.Create(lineWidth / 2, lineWidth / 2, size.Width - lineWidth, size.Height - lineWidth);
                if (GraphicsVisibile)
                {
                    composer.BeginLocalState();
                    composer.SetLineWidth(lineWidth);
                    composer.SetFillColor(BackColor);
                    composer.SetStrokeColor(ForeColor);
                    composer.DrawRectangle(frame, 5);
                    composer.FillStroke();
                    composer.End();
                }

                composer.BeginLocalState();
                if (GraphicsVisibile)
                {
                    composer.DrawRectangle(frame, 5);
                    composer.Clip(); // Ensures that the visible content is clipped within the rounded frame.
                }
                composer.BeginMarkedContent(PdfName.Tx);
                composer.SetFont(
                    PdfType1Font.Load(document, PdfType1Font.FamilyEnum.Helvetica, false, false),
                    FontSize
                    );
                double y = 3;
                foreach (ChoiceItem item in field.Items)
                {
                    composer.ShowText(
                        item.Text,
                        new SKPoint(0, (float)y)
                        );
                    y += FontSize * 1.175;
                    if (y > size.Height)
                    {
                        break;
                    }
                }
                composer.End();
                composer.End();

                composer.Flush();
            }
            appearance.Normal[null] = normalAppearanceState;
        }
コード例 #11
0
        private void Populate(Document document)
        {
            Page page = new Page(document);

            document.Pages.Add(page);
            SKSize pageSize = page.Size;

            /*
             * NOTE: Default fallback behavior on text encoding mismatch is substitution with default
             * character; in this case, we want to force an exception to be thrown so we can explicitly
             * handle the issue.
             */
            document.Configuration.EncodingFallback = EncodingFallbackEnum.Exception;

            PrimitiveComposer composer = new PrimitiveComposer(page);

            int          x = Margin, y = Margin;
            PdfType1Font titleFont = PdfType1Font.Load(document, PdfType1Font.FamilyEnum.Times, true, true);
            PdfType1Font font      = null;

            // Iterating through the standard Type 1 fonts...
            foreach (PdfType1Font.FamilyEnum fontFamily
                     in (PdfType1Font.FamilyEnum[])Enum.GetValues(typeof(PdfType1Font.FamilyEnum)))
            {
                // Iterating through the font styles...
                for (int styleIndex = 0; styleIndex < 4; styleIndex++)
                {
                    /*
                     * NOTE: Symbol and Zapf Dingbats are available just as regular fonts (no italic or bold variant).
                     */
                    if (styleIndex > 0 &&
                        (fontFamily == PdfType1Font.FamilyEnum.Symbol ||
                         fontFamily == PdfType1Font.FamilyEnum.ZapfDingbats))
                    {
                        break;
                    }

                    bool bold   = (styleIndex & 1) > 0;
                    bool italic = (styleIndex & 2) > 0;

                    // Define the font used to show its character set!
                    font = PdfType1Font.Load(document, fontFamily, bold, italic);

                    if (y > pageSize.Height - Margin)
                    {
                        composer.Flush();

                        page = new Page(document);
                        document.Pages.Add(page);
                        pageSize = page.Size;
                        composer = new PrimitiveComposer(page);
                        x        = Margin;
                        y        = Margin;
                    }

                    if (styleIndex == 0)
                    {
                        composer.DrawLine(
                            new SKPoint(x, y),
                            new SKPoint(pageSize.Width - Margin, y)
                            );
                        composer.Stroke();
                        y += 5;
                    }

                    composer.SetFont(
                        titleFont,
                        FontBaseSize * (styleIndex == 0 ? 1.5f : 1)
                        );
                    composer.ShowText(
                        fontFamily.ToString() + (bold ? " bold" : "") + (italic ? " italic" : ""),
                        new SKPoint(x, y)
                        );

                    y += 40;
                    // Set the font used to show its character set!
                    composer.SetFont(font, FontBaseSize);
                    // Iterating through the font characters...
                    foreach (int charCode in font.Encoding.CodeToNameMap.Keys.OrderBy(codePoint => codePoint))
                    {
                        if (y > pageSize.Height - Margin)
                        {
                            composer.Flush();

                            page = new Page(document);
                            document.Pages.Add(page);
                            pageSize = page.Size;
                            composer = new PrimitiveComposer(page);
                            x        = Margin;
                            y        = Margin;

                            composer.SetFont(titleFont, FontBaseSize);
                            composer.ShowText(
                                fontFamily.ToString() + " (continued)",
                                new SKPoint(pageSize.Width - Margin, y),
                                XAlignmentEnum.Right,
                                YAlignmentEnum.Top,
                                0
                                );
                            composer.SetFont(font, FontBaseSize);
                            y += FontBaseSize * 2;
                        }

                        try
                        {
                            var uniCode = font.ToUnicode(charCode);
                            // Show the character!
                            composer.ShowText(
                                new String((char)uniCode, 1),
                                new SKPoint(x, y)
                                );
                            x += FontBaseSize;
                            if (x > pageSize.Width - Margin)
                            {
                                x = Margin; y += 30;
                            }
                        }
                        catch (EncodeException)
                        {
                            /*
                             * NOOP -- NOTE: document.Configuration.EncodingFallback allows to customize the
                             * behavior in case of missing character: we can alternatively catch an exception, have
                             * the character substituted by a default one (typically '?' symbol) or have the
                             * character silently excluded.
                             */
                        }
                    }

                    x  = Margin;
                    y += Margin;
                }
            }
            composer.Flush();
        }
コード例 #12
0
        /**
         * <summary>Populates a PDF file with contents.</summary>
         */
        private void Populate(Document document)
        {
            // Initialize a new page!
            Page page = new Page(document);

            document.Pages.Add(page);

            // Initialize the primitive composer (within the new page context)!
            PrimitiveComposer composer = new PrimitiveComposer(page);

            composer.SetFont(PdfType1Font.Load(document, PdfType1Font.FamilyEnum.Helvetica, true, false), 12);

            // Initialize the block composer (wrapping the primitive one)!
            BlockComposer blockComposer = new BlockComposer(composer);

            // Initialize the document layer configuration!
            LayerDefinition layerDefinition = document.Layer;

            document.ViewerPreferences.PageMode = ViewerPreferences.PageModeEnum.Layers; // Shows the layers tab on document opening.

            // Get the root collection of the layers displayed to the user!
            UILayers uiLayers = layerDefinition.UILayers;

            // Nested layers.
            Layer parentLayer;
            {
                parentLayer = new Layer(document, "Parent layer");
                uiLayers.Add(parentLayer);
                var childLayers = parentLayer.Children;

                var childLayer1 = new Layer(document, "Child layer 1");
                childLayers.Add(childLayer1);

                var childLayer2 = new Layer(document, "Child layer 2");
                childLayers.Add(childLayer2);
                childLayer2.Locked = true;

                /*
                 * NOTE: Graphical content can be controlled through layers in two ways:
                 * 1) marking content within content streams (that is content within the page body);
                 * 2) associating annotations and external objects (XObject) to the layers.
                 */

                XObject imageXObject = entities::Image.Get(GetResourcePath("images" + Path.DirectorySeparatorChar + "gnu.jpg")).ToXObject(document);
                imageXObject.Layer = childLayer1; // Associates the image to the layer.

                composer.ShowXObject(imageXObject, new SKPoint(200, 75));

                composer.BeginLayer(parentLayer); // Opens a marked block associating its contents with the specified layer.
                composer.ShowText(parentLayer.Title, new SKPoint(50, 50));
                composer.End();                   // Closes the marked block.

                composer.BeginLayer(childLayer1);
                composer.ShowText(childLayer1.Title, new SKPoint(50, 75));
                composer.End();

                composer.BeginLayer(childLayer2);
                composer.ShowText(childLayer2.Title, new SKPoint(50, 100));
                composer.End();
            }

            // Simple layer collection (labeled collection of inclusive-state layers).
            Layer simpleLayer1;
            {
                var simpleLayerCollection = new LayerCollection(document, "Simple layer collection");
                uiLayers.Add(simpleLayerCollection);

                simpleLayer1 = new Layer(document, "Simple layer 1");
                simpleLayerCollection.Add(simpleLayer1);

                var simpleLayer2 = new Layer(document, "Simple layer 2 (Design)");

                /*
                 * NOTE: Intent limits layer use in determining visibility to specific use contexts. In this
                 * case, we want to mark content as intended to represent a document designer's structural
                 * organization of artwork, hence it's outside the interactive use by document consumers.
                 */
                simpleLayer2.Intents = new HashSet <PdfName> {
                    IntentEnum.Design.Name()
                };
                simpleLayerCollection.Add(simpleLayer2);

                var simpleLayer3 = new Layer(document, "Simple layer 3");
                simpleLayerCollection.Add(simpleLayer3);

                blockComposer.Begin(SKRect.Create(50, 125, 200, 75), XAlignmentEnum.Left, YAlignmentEnum.Middle);

                composer.BeginLayer(simpleLayer1);
                blockComposer.ShowText(simpleLayer1.Title);
                composer.End();

                blockComposer.ShowBreak(new SKSize(0, 10));

                composer.BeginLayer(simpleLayer2);
                blockComposer.ShowText(simpleLayer2.Title);
                composer.End();

                blockComposer.ShowBreak(new SKSize(0, 10));

                composer.BeginLayer(simpleLayer3);
                blockComposer.ShowText(simpleLayer3.Title);
                composer.End();

                blockComposer.End();
            }

            // Radio layer collection (labeled collection of exclusive-state layers).
            Layer radioLayer2;

            {
                var radioLayerCollection = new LayerCollection(document, "Radio layer collection");
                uiLayers.Add(radioLayerCollection);

                var radioLayer1 = new Layer(document, "Radio layer 1")
                {
                    Visible = true
                };
                radioLayerCollection.Add(radioLayer1);

                radioLayer2 = new Layer(document, "Radio layer 2")
                {
                    Visible = false
                };
                radioLayerCollection.Add(radioLayer2);

                var radioLayer3 = new Layer(document, "Radio layer 3")
                {
                    Visible = false
                };
                radioLayerCollection.Add(radioLayer3);

                // Register this option group in the layer configuration!
                var optionGroup = new OptionGroup(document)
                {
                    radioLayer1, radioLayer2, radioLayer3
                };
                layerDefinition.OptionGroups.Add(optionGroup);

                blockComposer.Begin(SKRect.Create(50, 200, 200, 75), XAlignmentEnum.Left, YAlignmentEnum.Middle);

                composer.BeginLayer(radioLayer1);
                blockComposer.ShowText(radioLayer1.Title);
                composer.End();

                blockComposer.ShowBreak(new SKSize(0, 10));

                composer.BeginLayer(radioLayer2);
                blockComposer.ShowText(radioLayer2.Title);
                composer.End();

                blockComposer.ShowBreak(new SKSize(0, 10));

                composer.BeginLayer(radioLayer3);
                blockComposer.ShowText(radioLayer3.Title);
                composer.End();

                blockComposer.End();
            }

            // Layer state action.
            {
                var actionLayer = new Layer(document, "Action layer")
                {
                    Printable = false
                };

                composer.BeginLayer(actionLayer);
                composer.BeginLocalState();
                composer.SetFillColor(colors::DeviceRGBColor.Get(SKColors.Blue));
                composer.ShowText(
                    "Layer state action:\n * deselect \"" + simpleLayer1.Title + "\"\n   and \"" + radioLayer2.Title + "\"\n * toggle \"" + parentLayer.Title + "\"",
                    new SKPoint(400, 200),
                    XAlignmentEnum.Left,
                    YAlignmentEnum.Middle,
                    0,
                    new SetLayerState(
                        document,
                        new SetLayerState.LayerState(SetLayerState.StateModeEnum.Off, simpleLayer1, radioLayer2),
                        new SetLayerState.LayerState(SetLayerState.StateModeEnum.Toggle, parentLayer)
                        )
                    );
                composer.End();
                composer.End();
            }

            // Zoom-restricted layer.
            {
                var zoomRestrictedLayer = new Layer(document, "Zoom-restricted layer")
                {
                    ZoomRange = new Interval <double>(.75, 1.251)
                };                                                // NOTE: Change this interval to test other magnification ranges.

                composer.BeginLayer(zoomRestrictedLayer);
                new TextMarkup(
                    page,
                    composer.ShowText(zoomRestrictedLayer.Title + ": this text is only visible if zoom between 75% and 125%", new SKPoint(50, 290)),
                    "This is a highlight annotation visible only if zoom is between 75% and 125%",
                    TextMarkupType.Highlight
                    )
                {
                    Layer = zoomRestrictedLayer /* Associates the annotation to the layer. */
                };
                composer.End();
            }

            // Print-only layer.
            {
                var printOnlyLayer = new Layer(document, "Print-only layer")
                {
                    Visible   = false,
                    Printable = true
                };

                composer.BeginLayer(printOnlyLayer);
                composer.BeginLocalState();
                composer.SetFillColor(colors::DeviceRGBColor.Get(SKColors.Red));
                composer.ShowText(printOnlyLayer.Title, new SKPoint(25, 300), XAlignmentEnum.Left, YAlignmentEnum.Top, 90);
                composer.End();
                composer.End();
            }

            // Language-specific layer.
            {
                var languageLayer = new Layer(document, "Language-specific layer")
                {
                    Language          = new LanguageIdentifier("en-GB"), // NOTE: Change this to test other languages and locales.
                    LanguagePreferred = true,                            // Matches any system locale (e.g. en-US, en-AU...) if layer language (en-GB) doesn't match exactly the system language.
                    Printable         = false
                };

                blockComposer.Begin(SKRect.Create(50, 320, 500, 75), XAlignmentEnum.Left, YAlignmentEnum.Top);

                composer.BeginLayer(languageLayer);
                blockComposer.ShowText(languageLayer.Title + ": this text is visible only if current system language is english (\"en\", any locale (\"en-US\", \"en-GB\", \"en-NZ\", etc.)) and is hidden on print.");
                composer.End();

                blockComposer.End();
            }

            // User-specific layer.
            {
                var userLayer = new Layer(document, "User-specific layer")
                {
                    Users = new List <string> {
                        "Lizbeth", "Alice", "Stefano", "Johann"
                    },                                                                    // NOTE: Change these entries to test other user names.
                    UserType = Layer.UserTypeEnum.Individual
                };

                blockComposer.Begin(SKRect.Create(blockComposer.BoundBox.Left, blockComposer.BoundBox.Bottom + 15, blockComposer.BoundBox.Width, 75), XAlignmentEnum.Left, YAlignmentEnum.Top);

                composer.BeginLayer(userLayer);
                blockComposer.ShowText(userLayer.Title + ": this text is visible only to " + String.Join(", ", userLayer.Users) + " (exact match).");
                composer.End();

                blockComposer.End();
            }

            // Layer membership (composite layer visibility).
            {
                var layerMembership = new LayerMembership(document)
                {
                    /*
                     * NOTE: VisibilityExpression is a more flexible alternative to the combination of
                     * VisibilityPolicy and VisibilityMembers. However, for compatibility purposes is preferable
                     * to provide both of them (the latter combination will work as a fallback in case of older
                     * viewer application).
                     */
                    VisibilityExpression = new VisibilityExpression(
                        document,
                        VisibilityExpression.OperatorEnum.And,
                        new VisibilityExpression(
                            document,
                            VisibilityExpression.OperatorEnum.Not,
                            new VisibilityExpression(
                                document,
                                VisibilityExpression.OperatorEnum.Or,
                                simpleLayer1,
                                radioLayer2
                                )
                            ),
                        parentLayer
                        ),
                    VisibilityPolicy  = LayerMembership.VisibilityPolicyEnum.AnyOff,
                    VisibilityMembers = new List <Layer> {
                        simpleLayer1, radioLayer2, parentLayer
                    }
                };

                blockComposer.Begin(SKRect.Create(blockComposer.BoundBox.Left, blockComposer.BoundBox.Bottom + 15, blockComposer.BoundBox.Width, 75), XAlignmentEnum.Left, YAlignmentEnum.Top);

                composer.BeginLayer(layerMembership);
                blockComposer.ShowText(String.Format("Layer membership: the visibility of this text is computed combining multiple layer states into an expression (\"{0}\" and \"{1}\" must be OFF while \"{2}\" must be ON).", simpleLayer1.Title, radioLayer2.Title, parentLayer.Title));
                composer.End();

                blockComposer.End();
            }

            composer.Flush();
        }
コード例 #13
0
        private void BuildLinks(Document document)
        {
            Pages pages = document.Pages;
            Page  page  = new Page(document);

            pages.Add(page);

            PrimitiveComposer composer      = new PrimitiveComposer(page);
            BlockComposer     blockComposer = new BlockComposer(composer);

            PdfType1Font font = PdfType1Font.Load(document, PdfType1Font.FamilyEnum.Courier, true, false);

            /*
             * 2.1. Goto-URI link.
             */
            {
                blockComposer.Begin(SKRect.Create(30, 100, 200, 50), XAlignmentEnum.Left, YAlignmentEnum.Middle);
                composer.SetFont(font, 12);
                blockComposer.ShowText("Go-to-URI link");
                composer.SetFont(font, 8);
                blockComposer.ShowText("\nIt allows you to navigate to a network resource.");
                composer.SetFont(font, 5);
                blockComposer.ShowText("\n\nClick on the box to go to the project's SourceForge.net repository.");
                blockComposer.End();

                /*
                 * NOTE: This statement instructs the PDF viewer to navigate to the given URI when the link is clicked.
                 */
                new Link(page, SKRect.Create(240, 100, 100, 50), "Link annotation",
                         new GoToURI(document, new Uri("http://www.sourceforge.net/projects/clown")))
                {
                    Border = new Border(3, BorderStyleType.Beveled)
                };
            }

            /*
             * 2.2. Embedded-goto link.
             */
            {
                string filePath = PromptFileChoice("Please select a PDF file to attach");

                /*
                 * NOTE: These statements instruct PDF Clown to attach a PDF file to the current document.
                 * This is necessary in order to test the embedded-goto functionality,
                 * as you can see in the following link creation (see below).
                 */
                int    fileAttachmentPageIndex = page.Index;
                string fileAttachmentName      = "attachedSamplePDF";
                string fileName = System.IO.Path.GetFileName(filePath);
                new FileAttachment(
                    page,
                    SKRect.Create(0, -20, 10, 10),
                    "File attachment annotation",
                    FileSpecification.Get(EmbeddedFile.Get(document, filePath),
                                          fileName
                                          )
                    )
                {
                    Name           = fileAttachmentName,
                    AttachmentName = FileAttachmentImageType.PaperClip
                };

                blockComposer.Begin(SKRect.Create(30, 170, 200, 50), XAlignmentEnum.Left, YAlignmentEnum.Middle);
                composer.SetFont(font, 12);
                blockComposer.ShowText("Go-to-embedded link");
                composer.SetFont(font, 8);
                blockComposer.ShowText("\nIt allows you to navigate to a destination within an embedded PDF file.");
                composer.SetFont(font, 5);
                blockComposer.ShowText("\n\nClick on the button to go to the 2nd page of the attached PDF file (" + fileName + ").");
                blockComposer.End();

                /*
                 * NOTE: This statement instructs the PDF viewer to navigate to the page 2 of a PDF file
                 * attached inside the current document as described by the FileAttachment annotation on page 1 of the current document.
                 */
                new Link(
                    page,
                    SKRect.Create(240, 170, 100, 50),
                    "Link annotation",
                    new GoToEmbedded(
                        document,
                        new GoToEmbedded.PathElement(
                            document,
                            fileAttachmentPageIndex, // Page of the current document containing the file attachment annotation of the target document.
                            fileAttachmentName,      // Name of the file attachment annotation corresponding to the target document.
                            null                     // No sub-target.
                            ),                       // Target represents the document to go to.
                        new RemoteDestination(
                            document,
                            1,                        // Show the page 2 of the target document.
                            Destination.ModeEnum.Fit, // Show the target document page entirely on the screen.
                            null,
                            null
                            ) // The destination must be within the target document.
                        )
                    )
                {
                    Border = new Border(1, new LineDash(new float[] { 8, 5, 2, 5 }))
                };
            }

            /*
             * 2.3. Textual link.
             */
            {
                blockComposer.Begin(SKRect.Create(30, 240, 200, 50), XAlignmentEnum.Left, YAlignmentEnum.Middle);
                composer.SetFont(font, 12);
                blockComposer.ShowText("Textual link");
                composer.SetFont(font, 8);
                blockComposer.ShowText("\nIt allows you to expose any kind of link (including the above-mentioned types) as text.");
                composer.SetFont(font, 5);
                blockComposer.ShowText("\n\nClick on the text links to go either to the project's SourceForge.net repository or to the project's home page.");
                blockComposer.End();

                composer.BeginLocalState();
                composer.SetFont(font, 10);
                composer.SetFillColor(DeviceRGBColor.Get(SKColors.Blue));
                composer.ShowText(
                    "PDF Clown Project's repository at SourceForge.net",
                    new SKPoint(240, 265),
                    XAlignmentEnum.Left,
                    YAlignmentEnum.Middle,
                    0,
                    new GoToURI(
                        document,
                        new Uri("http://www.sourceforge.net/projects/clown")
                        )
                    );
                composer.ShowText(
                    "PDF Clown Project's home page",
                    new SKPoint(240, 285),
                    XAlignmentEnum.Left,
                    YAlignmentEnum.Bottom,
                    -90,
                    new GoToURI(
                        document,
                        new Uri("http://www.pdfclown.org")
                        )
                    );
                composer.End();
            }

            composer.Flush();
        }
コード例 #14
0
        private void Populate(Document document)
        {
            /*
             * NOTE: In order to insert a field into a document, you have to follow these steps:
             * 1. Define the form fields collection that will gather your fields (NOTE: the form field collection is global to the document);
             * 2. Define the pages where to place the fields;
             * 3. Define the appearance style to render your fields;
             * 4. Create each field of yours:
             *  4.1. instantiate your field into the page;
             *  4.2. apply the appearance style to your field;
             *  4.3. insert your field into the fields collection.
             */

            // 1. Define the form fields collection!
            Form   form   = document.Form;
            Fields fields = form.Fields;

            // 2. Define the page where to place the fields!
            Page page = new Page(document);

            document.Pages.Add(page);

            // 3. Define the appearance style to apply to the fields!
            DefaultStyle fieldStyle = new DefaultStyle();

            fieldStyle.FontSize         = 12;
            fieldStyle.GraphicsVisibile = true;

            PrimitiveComposer composer = new PrimitiveComposer(page);

            composer.SetFont(PdfType1Font.Load(document, PdfType1Font.FamilyEnum.Courier, true, false), 14);

            // 4. Field creation.
            // 4.a. Push button.
            {
                composer.ShowText(
                    "PushButton:",
                    new SKPoint(140, 68),
                    XAlignmentEnum.Right,
                    YAlignmentEnum.Middle,
                    0);

                Widget fieldWidget = new Widget(
                    page,
                    SKRect.Create(150, 50, 136, 36));
                fieldWidget.Actions.OnActivate = new JavaScript(
                    document,
                    "app.alert(\"Radio button currently selected: '\" + this.getField(\"myRadio\").value + \"'.\",3,0,\"Activation event\");");
                PushButton field = new PushButton(
                    "okButton",
                    fieldWidget,
                    "Push"               // Current value.
                    );                   // 4.1. Field instantiation.
                fields.Add(field);       // 4.2. Field insertion into the fields collection.
                fieldStyle.Apply(field); // 4.3. Appearance style applied.

                {
                    BlockComposer blockComposer = new BlockComposer(composer);
                    blockComposer.Begin(SKRect.Create(296, 50, page.Size.Width - 336, 36), XAlignmentEnum.Left, YAlignmentEnum.Middle);
                    composer.SetFont(composer.State.Font, 7);
                    blockComposer.ShowText("If you click this push button, a javascript action should prompt you an alert box responding to the activation event triggered by your PDF viewer.");
                    blockComposer.End();
                }
            }

            // 4.b. Check box.
            {
                composer.ShowText("CheckBox:", new SKPoint(140, 118), XAlignmentEnum.Right, YAlignmentEnum.Middle, 0);
                CheckBox field = new CheckBox("myCheck", new Widget(page, SKRect.Create(150, 100, 36, 36)), true); // 4.1. Field instantiation.
                fieldStyle.Apply(field);
                fields.Add(field);
                field = new CheckBox("myCheck2", new Widget(page, SKRect.Create(200, 100, 36, 36)), true); // 4.1. Field instantiation.
                fieldStyle.Apply(field);
                fields.Add(field);
                field = new CheckBox("myCheck3", new Widget(page, SKRect.Create(250, 100, 36, 36)), false); // 4.1. Field instantiation.
                fields.Add(field);                                                                          // 4.2. Field insertion into the fields collection.
                fieldStyle.Apply(field);                                                                    // 4.3. Appearance style applied.
            }

            // 4.c. Radio button.
            {
                composer.ShowText("RadioButton:", new SKPoint(140, 168), XAlignmentEnum.Right, YAlignmentEnum.Middle, 0);
                RadioButton field = new RadioButton(
                    "myRadio",

                    /*
                     * NOTE: A radio button field typically combines multiple alternative widgets.
                     */
                    new Widget[]
                {
                    new Widget(page, SKRect.Create(150, 150, 36, 36), "first"),
                    new Widget(page, SKRect.Create(200, 150, 36, 36), "second"),
                    new Widget(page, SKRect.Create(250, 150, 36, 36), "third")
                },
                    "second"             // Selected item (it MUST correspond to one of the available widgets' names).
                    );                   // 4.1. Field instantiation.
                fields.Add(field);       // 4.2. Field insertion into the fields collection.
                fieldStyle.Apply(field); // 4.3. Appearance style applied.
            }

            // 4.d. Text field.
            {
                composer.ShowText("TextField:", new SKPoint(140, 218), XAlignmentEnum.Right, YAlignmentEnum.Middle, 0);
                TextField field = new TextField("myText", new Widget(page, SKRect.Create(150, 200, 200, 36)), "Carmen Consoli"); // 4.1. Field instantiation. // Current value.

                field.SpellChecked = false;                                                                                      // Avoids text spell check.
                FieldActions fieldActions = new FieldActions(document);
                field.Actions           = fieldActions;
                fieldActions.OnValidate = new JavaScript(
                    document,
                    "app.alert(\"Text '\" + this.getField(\"myText\").value + \"' has changed!\",3,0,\"Validation event\");"
                    );
                fields.Add(field);       // 4.2. Field insertion into the fields collection.
                fieldStyle.Apply(field); // 4.3. Appearance style applied.

                {
                    BlockComposer blockComposer = new BlockComposer(composer);
                    blockComposer.Begin(SKRect.Create(360, 200, page.Size.Width - 400, 36), XAlignmentEnum.Left, YAlignmentEnum.Middle);
                    composer.SetFont(composer.State.Font, 7);
                    blockComposer.ShowText("If you leave this text field after changing its content, a javascript action should prompt you an alert box responding to the validation event triggered by your PDF viewer.");
                    blockComposer.End();
                }
            }

            // 4.e. Choice fields.
            {
                // Preparing the item list that we'll use for choice fields (a list box and a combo box (see below))...
                ChoiceItems items = new ChoiceItems(document);
                items.Add("Tori Amos");
                items.Add("Anouk");
                items.Add("Joan Baez");
                items.Add("Rachele Bastreghi");
                items.Add("Anna Calvi");
                items.Add("Tracy Chapman");
                items.Add("Carmen Consoli");
                items.Add("Ani DiFranco");
                items.Add("Cristina Dona'");
                items.Add("Nathalie Giannitrapani");
                items.Add("PJ Harvey");
                items.Add("Billie Holiday");
                items.Add("Joan As Police Woman");
                items.Add("Joan Jett");
                items.Add("Janis Joplin");
                items.Add("Angelique Kidjo");
                items.Add("Patrizia Laquidara");
                items.Add("Annie Lennox");
                items.Add("Loreena McKennitt");
                items.Add("Joni Mitchell");
                items.Add("Alanis Morissette");
                items.Add("Yael Naim");
                items.Add("Noa");
                items.Add("Sinead O'Connor");
                items.Add("Dolores O'Riordan");
                items.Add("Nina Persson");
                items.Add("Brisa Roche'");
                items.Add("Roberta Sammarelli");
                items.Add("Cristina Scabbia");
                items.Add("Nina Simone");
                items.Add("Skin");
                items.Add("Patti Smith");
                items.Add("Fatima Spar");
                items.Add("Thony (F.V.Caiozzo)");
                items.Add("Paola Turci");
                items.Add("Sarah Vaughan");
                items.Add("Nina Zilli");

                // 4.e1. List box.
                {
                    composer.ShowText("ListBox:", new SKPoint(140, 268), XAlignmentEnum.Right, YAlignmentEnum.Middle, 0);
                    ListBox field = new ListBox("myList", new Widget(page, SKRect.Create(150, 250, 200, 70))); // 4.1. Field instantiation.
                    field.Items       = items;                                                                 // List items assignment.
                    field.MultiSelect = false;                                                                 // Multiple items may not be selected simultaneously.
                    field.Value       = "Carmen Consoli";                                                      // Selected item.
                    fields.Add(field);                                                                         // 4.2. Field insertion into the fields collection.
                    fieldStyle.Apply(field);                                                                   // 4.3. Appearance style applied.
                }

                // 4.e2. Combo box.
                {
                    composer.ShowText("ComboBox:", new SKPoint(140, 350), XAlignmentEnum.Right, YAlignmentEnum.Middle, 0);
                    ComboBox field = new ComboBox("myCombo", new Widget(page, SKRect.Create(150, 334, 200, 36))); // 4.1. Field instantiation.
                    field.Items        = items;                                                                   // Combo items assignment.
                    field.Editable     = true;                                                                    // Text may be edited.
                    field.SpellChecked = false;                                                                   // Avoids text spell check.
                    field.Value        = "Carmen Consoli";                                                        // Selected item.
                    fields.Add(field);                                                                            // 4.2. Field insertion into the fields collection.
                    fieldStyle.Apply(field);                                                                      // 4.3. Appearance style applied.
                }
            }

            composer.Flush();
        }
コード例 #15
0
        /**
         * <summary>Populates a PDF file with contents.</summary>
         */
        private void Populate(
            Document document
            )
        {
            // Get the abstract barcode entity!
            EAN13Barcode barcode = new EAN13Barcode("8012345678901");
            // Create the reusable barcode within the document!
            XObject barcodeXObject = barcode.ToXObject(document);

            Pages pages = document.Pages;
            // Page 1.
            {
                Page page = new Page(document);
                pages.Add(page);
                SKSize pageSize = page.Size;

                PrimitiveComposer composer = new PrimitiveComposer(page);
                {
                    BlockComposer blockComposer = new BlockComposer(composer);
                    blockComposer.Hyphenation = true;
                    blockComposer.Begin(
                        SKRect.Create(
                            Margin,
                            Margin,
                            pageSize.Width - Margin * 2,
                            pageSize.Height - Margin * 2
                            ),
                        XAlignmentEnum.Left,
                        YAlignmentEnum.Top
                        );
                    PdfType1Font bodyFont = PdfType1Font.Load(document, PdfType1Font.FamilyEnum.Courier, true, false);
                    composer.SetFont(bodyFont, 32);
                    blockComposer.ShowText("Barcode sample"); blockComposer.ShowBreak();
                    composer.SetFont(bodyFont, 16);
                    blockComposer.ShowText("Showing the EAN-13 Bar Code on different compositions:"); blockComposer.ShowBreak();
                    blockComposer.ShowText("- page 1: on the lower right corner of the page, 100pt wide;"); blockComposer.ShowBreak();
                    blockComposer.ShowText("- page 2: on the middle of the page, 1/3-page wide, 25 degree counterclockwise rotated;"); blockComposer.ShowBreak();
                    blockComposer.ShowText("- page 3: filled page, 90 degree clockwise rotated."); blockComposer.ShowBreak();
                    blockComposer.End();
                }

                // Show the barcode!
                composer.ShowXObject(
                    barcodeXObject,
                    new SKPoint(pageSize.Width - Margin, pageSize.Height - Margin),
                    GeomUtils.Scale(barcodeXObject.Size, new SKSize(100, 0)),
                    XAlignmentEnum.Right,
                    YAlignmentEnum.Bottom,
                    0);
                composer.Flush();
            }

            // Page 2.
            {
                Page page = new Page(document);
                pages.Add(page);
                SKSize pageSize = page.Size;

                PrimitiveComposer composer = new PrimitiveComposer(page);
                // Show the barcode!
                composer.ShowXObject(
                    barcodeXObject,
                    new SKPoint(pageSize.Width / 2, pageSize.Height / 2),
                    GeomUtils.Scale(barcodeXObject.Size, new SKSize(pageSize.Width / 3, 0)),
                    XAlignmentEnum.Center,
                    YAlignmentEnum.Middle,
                    25
                    );
                composer.Flush();
            }

            // Page 3.
            {
                Page page = new Page(document);
                pages.Add(page);
                SKSize pageSize = page.Size;

                PrimitiveComposer composer = new PrimitiveComposer(page);
                // Show the barcode!
                composer.ShowXObject(
                    barcodeXObject,
                    new SKPoint(pageSize.Width / 2, pageSize.Height / 2),
                    new SKSize(pageSize.Height, pageSize.Width),
                    XAlignmentEnum.Center,
                    YAlignmentEnum.Middle,
                    -90
                    );
                composer.Flush();
            }
        }
コード例 #16
0
        private void Apply(CheckBox field)
        {
            Document document = field.Document;

            foreach (Widget widget in field.Widgets)
            {
                {
                    PdfDictionary widgetDataObject = widget.BaseDataObject;
                    widgetDataObject[PdfName.DA] = new PdfString("/ZaDb 0 Tf 0 0 0 rg");
                    widgetDataObject[PdfName.MK] = new PdfDictionary(
                        new PdfName[] { PdfName.BG, PdfName.BC, PdfName.CA },
                        new PdfDirectObject[]
                    {
                        new PdfArray(new PdfDirectObject[] { PdfReal.Get(0.9412), PdfReal.Get(0.9412), PdfReal.Get(0.9412) }),
                        new PdfArray(new PdfDirectObject[] { PdfInteger.Default, PdfInteger.Default, PdfInteger.Default }),
                        new PdfString("4")
                    }
                        );
                    widgetDataObject[PdfName.BS] = new PdfDictionary(
                        new PdfName[] { PdfName.W, PdfName.S },
                        new PdfDirectObject[] { PdfReal.Get(0.8), PdfName.S }
                        );
                    widgetDataObject[PdfName.H] = PdfName.P;
                }

                Appearance       appearance       = widget.Appearance;
                AppearanceStates normalAppearance = appearance.Normal;
                SKSize           size             = widget.Box.Size;
                FormXObject      onState          = new FormXObject(document, size);
                normalAppearance[PdfName.Yes] = onState;

                //TODO:verify!!!
                //   appearance.getRollover()[PdfName.Yes,onState);
                //   appearance.getDown()[PdfName.Yes,onState);
                //   appearance.getRollover()[PdfName.Off,offState);
                //   appearance.getDown()[PdfName.Off,offState);

                float  lineWidth = 1;
                SKRect frame     = SKRect.Create(lineWidth / 2, lineWidth / 2, size.Width - lineWidth, size.Height - lineWidth);
                {
                    PrimitiveComposer composer = new PrimitiveComposer(onState);

                    if (GraphicsVisibile)
                    {
                        composer.BeginLocalState();
                        composer.SetLineWidth(lineWidth);
                        composer.SetFillColor(BackColor);
                        composer.SetStrokeColor(ForeColor);
                        composer.DrawRectangle(frame, 5);
                        composer.FillStroke();
                        composer.End();
                    }

                    BlockComposer blockComposer = new BlockComposer(composer);
                    blockComposer.Begin(frame, XAlignmentEnum.Center, YAlignmentEnum.Middle);
                    composer.SetFillColor(ForeColor);
                    composer.SetFont(
                        PdfType1Font.Load(document, PdfType1Font.FamilyEnum.ZapfDingbats, true, false),
                        size.Height * 0.8
                        );
                    blockComposer.ShowText(new String(new char[] { CheckSymbol }));
                    blockComposer.End();

                    composer.Flush();
                }

                FormXObject offState = new FormXObject(document, size);
                normalAppearance[PdfName.Off] = offState;
                {
                    if (GraphicsVisibile)
                    {
                        PrimitiveComposer composer = new PrimitiveComposer(offState);

                        composer.BeginLocalState();
                        composer.SetLineWidth(lineWidth);
                        composer.SetFillColor(BackColor);
                        composer.SetStrokeColor(ForeColor);
                        composer.DrawRectangle(frame, 5);
                        composer.FillStroke();
                        composer.End();

                        composer.Flush();
                    }
                }
            }
        }
コード例 #17
0
        /**
         * <summary>Populates a PDF file with contents.</summary>
         */
        private void Populate(Document document, XObject form)
        {
            // 1. Add a 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 content stream!
            PrimitiveComposer composer = new PrimitiveComposer(page);

            // 3. Inserting contents...
            SKSize pageSize = page.Size;

            // 3.1. Showing the form on the page...
            {
                SKSize formSize = form.Size;
                // Form 1.
                composer.ShowXObject(
                    form,
                    new SKPoint(pageSize.Width / 2, pageSize.Height / 2),
                    GeomUtils.Scale(formSize, new SKSize(300, 0)),
                    XAlignmentEnum.Center,
                    YAlignmentEnum.Middle,
                    45
                    );
                // Form 2.
                composer.ShowXObject(
                    form,
                    new SKPoint(0, pageSize.Height),
                    GeomUtils.Scale(formSize, new SKSize(0, 300)),
                    XAlignmentEnum.Left,
                    YAlignmentEnum.Bottom,
                    0
                    );
                // Form 3.
                composer.ShowXObject(
                    form,
                    new SKPoint(pageSize.Width, pageSize.Height),
                    new SKSize(80, 200),
                    XAlignmentEnum.Right,
                    YAlignmentEnum.Bottom,
                    0
                    );
            }
            // 3.2. Showing the comments on the page...
            {
                BlockComposer blockComposer = new BlockComposer(composer);
                SKRect        frame         = SKRect.Create(
                    18,
                    18,
                    pageSize.Width * .5f,
                    pageSize.Height * .5f
                    );
                blockComposer.Begin(frame, XAlignmentEnum.Justify, YAlignmentEnum.Top);
                PdfType1Font bodyFont = PdfType1Font.Load(document, PdfType1Font.FamilyEnum.Courier, true, false);
                composer.SetFont(bodyFont, 24);
                blockComposer.ShowText("Page-to-form sample");
                SKSize breakSize = new SKSize(0, 8);
                blockComposer.ShowBreak(breakSize);
                composer.SetFont(bodyFont, 8);
                blockComposer.ShowText("This sample shows how to convert a page to a reusable form that can be placed multiple times on other pages scaling, rotating, anchoring and aligning it.");
                blockComposer.ShowBreak(breakSize);
                blockComposer.ShowText("On this page you can see some of the above-mentioned transformations:");
                breakSize.Width = 8;
                blockComposer.ShowBreak(breakSize);
                blockComposer.ShowText("1. anchored to the center of the page, rotated by 45 degrees counterclockwise, 300 point wide (preserved proportions);"); blockComposer.ShowBreak(breakSize);
                blockComposer.ShowText("2. anchored to the bottom-left corner of the page, 300 point high (preserved proportions);"); blockComposer.ShowBreak(breakSize);
                blockComposer.ShowText("3. anchored to the bottom-right of the page, 80 point wide and 200 point high (altered proportions).");
                blockComposer.End();
            }

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