Example #1
0
        private void BuildWelcomePage(Document document, FormXObject template)
        {
            // Add welcome 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;

            PrimitiveComposer composer = new PrimitiveComposer(page);

            // Add the background template!
            composer.ShowXObject(template);
            // Wrap the content composer inside a block composer in order to achieve higher-level typographic control!

            /*
             * NOTE: BlockComposer provides block-level typographic features as text and paragraph alignment.
             * Flow-level typographic features are currently not supported: block-level typographic features
             * are the foundations upon which flow-level typographic features will sit.
             */
            BlockComposer blockComposer = new BlockComposer(composer);

            SKSize breakSize = new SKSize(0, 20); // Size of a paragraph break.
                                                  // Instantiate the page body's font!
            fonts::Font font = fonts::PdfType0Font.Load(document, GetResourcePath("fonts" + Path.DirectorySeparatorChar + "lazyDog.ttf"));

            // Showing the page title...
            // Define the box frame to force the page title within!
            SKRect frame = SKRect.Create(
                20,
                150,
                (float)pageSize.Width - 90,
                (float)pageSize.Height - 250
                );

            // Begin the block!
            blockComposer.Begin(frame, XAlignmentEnum.Center, YAlignmentEnum.Top);
            // Set the font to use!
            composer.SetFont(font, 56);
            // Set the text rendering mode (outline only)!
            composer.SetTextRenderMode(TextRenderModeEnum.Stroke);
            // Show the page title!
            blockComposer.ShowText("Welcome");
            // End the block!
            blockComposer.End();

            // Showing the clown photo...
            // Instantiate a jpeg image object!
            entities::Image image         = entities::Image.Get(GetResourcePath("images" + Path.DirectorySeparatorChar + "Clown.jpg")); // Abstract image (entity).
            SKPoint         imageLocation = new SKPoint(
                blockComposer.BoundBox.Left + blockComposer.BoundBox.Width - image.Width,
                blockComposer.BoundBox.Top + blockComposer.BoundBox.Height + 25
                );

            // Show the image!
            composer.ShowXObject(
                image.ToXObject(document),
                imageLocation
                );

            SKRect descriptionFrame = SKRect.Create(
                imageLocation.X,
                imageLocation.Y + image.Height + 5,
                image.Width,
                20
                );

            frame = SKRect.Create(
                blockComposer.BoundBox.Left,
                imageLocation.Y,
                blockComposer.BoundBox.Width - image.Width - 20,
                image.Height
                );
            blockComposer.Begin(frame, XAlignmentEnum.Left, YAlignmentEnum.Middle);
            {
                composer.SetFont(font, 30);
                blockComposer.ShowText("This is a sample document that merely demonstrates some basic graphics features supported by PDF Clown.");
                blockComposer.ShowBreak(XAlignmentEnum.Center);
                blockComposer.ShowText("Enjoy!");
            }
            blockComposer.End();

            frame = SKRect.Create(
                blockComposer.BoundBox.Left,
                blockComposer.BoundBox.Top + blockComposer.BoundBox.Height,
                pageSize.Width - 90,
                pageSize.Height - 100 - (blockComposer.BoundBox.Top + blockComposer.BoundBox.Height)
                );
            blockComposer.Begin(frame, XAlignmentEnum.Justify, YAlignmentEnum.Bottom);
            {
                composer.SetFont(font, 14);
                blockComposer.ShowText("PS: As promised, since version 0.0.3 PDF Clown has supported");
                // Begin local state!

                /*
                 * NOTE: Local state is a powerful feature of PDF format as it lets you nest
                 * multiple graphics contexts on the graphics state stack.
                 */
                composer.BeginLocalState();
                {
                    composer.SetFillColor(TextColor_Highlight);
                    blockComposer.ShowText(" embedded latin OpenFont/TrueType and non-embedded Type 1 fonts");
                }
                composer.End();
                blockComposer.ShowText(" along with");
                composer.BeginLocalState();
                {
                    composer.SetFillColor(TextColor_Highlight);
                    blockComposer.ShowText(" paragraph construction facilities");
                }
                composer.End();
                blockComposer.ShowText(" through the BlockComposer class.");
                blockComposer.ShowBreak(breakSize);

                blockComposer.ShowText("Since version 0.0.4 the content stream stack has been completed, providing ");
                composer.BeginLocalState();
                {
                    composer.SetFillColor(TextColor_Highlight);
                    blockComposer.ShowText("fully object-oriented access to the graphics objects that describe the contents on a page.");
                }
                composer.End();
                blockComposer.ShowText(" It's a great step towards a whole bunch of possibilities, such as text extraction/replacement, that next releases will progressively exploit.");
                blockComposer.ShowBreak(breakSize);

                blockComposer.ShowText("Since version 0.0.6 it has supported ");
                composer.BeginLocalState();
                {
                    composer.SetFillColor(TextColor_Highlight);
                    blockComposer.ShowText("Unicode");
                }
                composer.End();
                blockComposer.ShowText(" for OpenFont/TrueType fonts.");
                blockComposer.ShowBreak(breakSize);

                composer.SetFont(font, 8);
                blockComposer.ShowText("This page was crafted with the nice");
                composer.BeginLocalState();
                {
                    composer.SetFont(font, 10);
                    blockComposer.ShowText(" LazyDog font");
                }
                composer.End();
                blockComposer.ShowText(" (by Paul Neave, www.neave.com)");
            }
            blockComposer.End();

            blockComposer.Begin(descriptionFrame, XAlignmentEnum.Right, YAlignmentEnum.Top);
            {
                composer.SetFont(font, 8);
                blockComposer.ShowText("Source: http://www.wikipedia.org/");
            }
            blockComposer.End();

            composer.Flush();
        }
Example #2
0
        private void BuildWelcomePage(
            Document document,
            FormXObject template
            )
        {
            // Add welcome 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;

              PrimitiveComposer composer = new PrimitiveComposer(page);
              // Add the background template!
              composer.ShowXObject(template);
              // Wrap the content composer inside a block composer in order to achieve higher-level typographic control!
              /*
            NOTE: BlockComposer provides block-level typographic features as text and paragraph alignment.
            Flow-level typographic features are currently not supported: block-level typographic features
            are the foundations upon which flow-level typographic features will sit.
              */
              BlockComposer blockComposer = new BlockComposer(composer);

              SizeF breakSize = new SizeF(0,20); // Size of a paragraph break.
              // Instantiate the page body's font!
              fonts::Font font = fonts::Font.Get(
            document,
            GetResourcePath("fonts" + Path.DirectorySeparatorChar + "lazyDog.ttf")
            );

              // Showing the page title...
              // Define the box frame to force the page title within!
              RectangleF frame = new RectangleF(
            20,
            150,
            (float)pageSize.Width - 90,
            (float)pageSize.Height - 250
            );
              // Begin the block!
              blockComposer.Begin(frame,XAlignmentEnum.Center,YAlignmentEnum.Top);
              // Set the font to use!
              composer.SetFont(font,56);
              // Set the text rendering mode (outline only)!
              composer.SetTextRenderMode(TextRenderModeEnum.Stroke);
              // Show the page title!
              blockComposer.ShowText("Welcome");
              // End the block!
              blockComposer.End();

              // Showing the clown photo...
              // Instantiate a jpeg image object!
              entities::Image image = entities::Image.Get(GetResourcePath("images" + Path.DirectorySeparatorChar + "Clown.jpg")); // Abstract image (entity).
              PointF imageLocation = new PointF(
            blockComposer.BoundBox.X + blockComposer.BoundBox.Width - image.Width,
            blockComposer.BoundBox.Y + blockComposer.BoundBox.Height + 25
            );
              // Show the image!
              composer.ShowXObject(
            image.ToXObject(document),
            imageLocation
            );

              RectangleF descriptionFrame = new RectangleF(
            imageLocation.X,
            imageLocation.Y + image.Height + 5,
            image.Width,
            20
            );

              frame = new RectangleF(
            blockComposer.BoundBox.X,
            imageLocation.Y,
            blockComposer.BoundBox.Width - image.Width - 20,
            image.Height
            );
              blockComposer.Begin(frame,XAlignmentEnum.Left,YAlignmentEnum.Middle);
              {
            composer.SetFont(font,30);
            blockComposer.ShowText("This is a sample document that merely demonstrates some basic graphics features supported by PDF Clown.");
            blockComposer.ShowBreak(XAlignmentEnum.Center);
            blockComposer.ShowText("Enjoy!");
              }
              blockComposer.End();

              frame = new RectangleF(
            blockComposer.BoundBox.X,
            blockComposer.BoundBox.Y+blockComposer.BoundBox.Height,
            pageSize.Width - 90,
            pageSize.Height - 100 - (blockComposer.BoundBox.Y+blockComposer.BoundBox.Height)
            );
              blockComposer.Begin(frame,XAlignmentEnum.Justify,YAlignmentEnum.Bottom);
              {
            composer.SetFont(font,14);
            blockComposer.ShowText("PS: As promised, since version 0.0.3 PDF Clown has supported");
            // Begin local state!
            /*
              NOTE: Local state is a powerful feature of PDF format as it lets you nest
              multiple graphics contexts on the graphics state stack.
            */
            composer.BeginLocalState();
            {
              composer.SetFillColor(TextColor_Highlight);
              blockComposer.ShowText(" embedded latin OpenFont/TrueType and non-embedded Type 1 fonts");
            }
            composer.End();
            blockComposer.ShowText(" along with");
            composer.BeginLocalState();
            {
              composer.SetFillColor(TextColor_Highlight);
              blockComposer.ShowText(" paragraph construction facilities");
            }
            composer.End();
            blockComposer.ShowText(" through the BlockComposer class.");
            blockComposer.ShowBreak(breakSize);

            blockComposer.ShowText("Since version 0.0.4 the content stream stack has been completed, providing ");
            composer.BeginLocalState();
            {
              composer.SetFillColor(TextColor_Highlight);
              blockComposer.ShowText("fully object-oriented access to the graphics objects that describe the contents on a page.");
            }
            composer.End();
            blockComposer.ShowText(" It's a great step towards a whole bunch of possibilities, such as text extraction/replacement, that next releases will progressively exploit.");
            blockComposer.ShowBreak(breakSize);

            blockComposer.ShowText("Since version 0.0.6 it has supported ");
            composer.BeginLocalState();
            {
              composer.SetFillColor(TextColor_Highlight);
              blockComposer.ShowText("Unicode");
            }
            composer.End();
            blockComposer.ShowText(" for OpenFont/TrueType fonts.");
            blockComposer.ShowBreak(breakSize);

            composer.SetFont(font,8);
            blockComposer.ShowText("This page was crafted with the nice");
            composer.BeginLocalState();
            {
              composer.SetFont(font,10);
              blockComposer.ShowText(" LazyDog font");
            }
            composer.End();
            blockComposer.ShowText(" (by Paul Neave, www.neave.com)");
              }
              blockComposer.End();

              blockComposer.Begin(descriptionFrame,XAlignmentEnum.Right,YAlignmentEnum.Top);
              {
            composer.SetFont(font,8);
            blockComposer.ShowText("Source: http://www.wikipedia.org/");
              }
              blockComposer.End();

              composer.Flush();
        }