Пример #1
0
        private void Build(
            Document document
            )
        {
            // 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.

              SizeF pageSize = page.Size;

              // Create a content composer for the content stream!
              /*
            NOTE: There are several ways to add contents to a content stream:
            - adding content objects directly to the Contents collection;
            - adding content objects through a ContentScanner instance;
            - invoking basic drawing functions through a PrimitiveComposer instance;
            - invoking advanced static-positioning functions through a BlockComposer instance;
            - invoking advanced dynamic-positioning functions through a FlowComposer instance (currently not implemented yet).
              */
              PrimitiveComposer composer = new PrimitiveComposer(page);
              // Wrap the content composer within a block filter!
              /*
            NOTE: The block filter is a basic typesetter. It exposes higher-level graphical
            functionalities (horizontal/vertical alignment, indentation, paragraph composition etc.)
            leveraging the content composer primitives.
            It's important to note that this is just an intermediate abstraction layer of the typesetting
            stack: further abstract levels could sit upon it, allowing the convenient treatment of
            typographic entities like titles, paragraphs, columns, tables, headers, footers etc.
            When such further abstract levels are available, the final user (developer of consuming
            applications) won't care any more of the details you can see here in the following code lines
            (such as bothering to select the first-letter font...).
              */
              BlockComposer blockComposer = new BlockComposer(composer);

              composer.BeginLocalState();
              // Define the block frame that will constrain our contents on the page canvas!
              RectangleF frame = new RectangleF(
            Margin_X,
            Margin_Y,
            (float)pageSize.Width - Margin_X * 2,
            (float)pageSize.Height - Margin_Y * 2
            );
              // Begin the title block!
              blockComposer.Begin(frame,XAlignmentEnum.Left,YAlignmentEnum.Top);
              fonts::Font decorativeFont = fonts::Font.Get(
            document,
            GetResourcePath("fonts" + Path.DirectorySeparatorChar + "Ruritania-Outline.ttf")
            );
              composer.SetFont(decorativeFont,56);
              blockComposer.ShowText("Chapter 1");
              blockComposer.ShowBreak();
              composer.SetFont(decorativeFont,32);
              blockComposer.ShowText("Down the Rabbit-Hole");
              // End the title block!
              blockComposer.End();
              // Update the block frame in order to begin after the title!
              frame = new RectangleF(
            (float)blockComposer.BoundBox.X,
            (float)blockComposer.BoundBox.Y + blockComposer.BoundBox.Height,
            (float)blockComposer.BoundBox.Width,
            (float)pageSize.Height - Margin_Y - (blockComposer.BoundBox.Y + blockComposer.BoundBox.Height)
            );
              // Begin the body block!
              blockComposer.Begin(frame,XAlignmentEnum.Justify,YAlignmentEnum.Bottom);
              fonts::Font bodyFont = fonts::Font.Get(
            document,
            GetResourcePath("fonts" + Path.DirectorySeparatorChar + "TravelingTypewriter.otf")
            );
              composer.SetFont(bodyFont,14);
              composer.BeginLocalState();
              composer.SetFont(decorativeFont,28);
              blockComposer.ShowText("A");
              composer.End();
              blockComposer.ShowText("lice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, 'and what is the use of a book,' thought Alice 'without pictures or conversation?'");
              // Define new-paragraph first-line offset!
              SizeF breakSize = new SizeF(24,8); // Indentation (24pt) and top margin (8pt).
              // Begin a new paragraph!
              blockComposer.ShowBreak(breakSize);
              blockComposer.ShowText("So she was considering in her own mind (as well as she could, for the hot day made her feel very sleepy and stupid), whether the pleasure of making a daisy-chain would be worth the trouble of getting up and picking the daisies, when suddenly a White Rabbit with pink eyes ran close by her.");
              // Begin a new paragraph!
              blockComposer.ShowBreak(breakSize);
              blockComposer.ShowText("There was nothing so VERY remarkable in that; nor did Alice think it so VERY much out of the way to hear the Rabbit say to itself, 'Oh dear! Oh dear! I shall be late!' (when she thought it over afterwards, it occurred to her that she ought to have wondered at this, but at the time it all seemed quite natural); but when the Rabbit actually TOOK A WATCH OUT OF ITS WAISTCOAT- POCKET, and looked at it, and then hurried on, Alice started to her feet, for it flashed across her mind that she had never before seen a rabbit with either a waistcoat-pocket, or a watch to take out of it, and burning with curiosity, she ran across the field after it, and fortunately was just in time to see it pop down a large rabbit-hole under the hedge.");
              // End the body block!
              blockComposer.End();
              composer.End();

              composer.BeginLocalState();
              composer.Rotate(
            90,
            new PointF(
              pageSize.Width - 50,
              pageSize.Height - 25
              )
            );
              blockComposer = new BlockComposer(composer);
              blockComposer.Begin(
            new RectangleF(0,0,300,50),
            XAlignmentEnum.Left,
            YAlignmentEnum.Middle
            );
              composer.SetFont(bodyFont,8);
              blockComposer.ShowText("Generated by PDF Clown on " + System.DateTime.Now);
              blockComposer.ShowBreak();
              blockComposer.ShowText("For more info, visit http://www.pdfclown.org");
              blockComposer.End();
              composer.End();

              // Flush the contents into the page!
              composer.Flush();
        }
Пример #2
0
        private FormXObject BuildTemplate(Document document, DateTime creationDate)
        {
            // Create a template (form)!
            FormXObject template     = new FormXObject(document, document.PageSize.Value);
            SKSize      templateSize = template.Size;

            // Get form content stream!
            PrimitiveComposer composer = new PrimitiveComposer(template);

            // Showing the header image inside the common content stream...
            // Instantiate a jpeg image object!
            entities::Image image = entities::Image.Get(GetResourcePath("images" + Path.DirectorySeparatorChar + "mountains.jpg")); // Abstract image (entity).

            // Show the image inside the common content stream!
            composer.ShowXObject(
                image.ToXObject(document),
                new SKPoint(0, 0),
                new SKSize(templateSize.Width - 50, 125)
                );

            // Showing the 'PdfClown' label inside the common content stream...
            composer.BeginLocalState();
            composer.SetFillColor(new colorSpaces::DeviceRGBColor(115f / 255, 164f / 255, 232f / 255));
            // Set the font to use!
            composer.SetFont(fonts::PdfType1Font.Load(document, fonts::PdfType1Font.FamilyEnum.Times, true, false), 120);
            // Show the text!
            composer.ShowText(
                "PdfClown",
                new SKPoint(
                    0,
                    templateSize.Height - (float)composer.State.Font.GetAscent(composer.State.FontSize)
                    )
                );

            // Drawing the side rectangle...
            composer.DrawRectangle(
                SKRect.Create(
                    (float)templateSize.Width - 50,
                    0,
                    50,
                    (float)templateSize.Height
                    )
                );
            composer.Fill();
            composer.End();

            // Showing the side text inside the common content stream...
            composer.BeginLocalState();
            {
                composer.SetFont(fonts::PdfType1Font.Load(document, fonts::PdfType1Font.FamilyEnum.Helvetica, false, false), 8);
                composer.SetFillColor(colorSpaces::DeviceRGBColor.White);
                composer.BeginLocalState();
                {
                    composer.Rotate(
                        90,
                        new SKPoint(
                            templateSize.Width - 50,
                            templateSize.Height - 25
                            )
                        );
                    BlockComposer blockComposer = new BlockComposer(composer);
                    blockComposer.Begin(
                        SKRect.Create(0, 0, 300, 50),
                        XAlignmentEnum.Left,
                        YAlignmentEnum.Middle
                        );
                    {
                        blockComposer.ShowText("Generated by PDF Clown on " + creationDate);
                        blockComposer.ShowBreak();
                        blockComposer.ShowText("For more info, visit http://www.pdfclown.org");
                    }
                    blockComposer.End();
                }
                composer.End();
            }
            composer.End();

            composer.Flush();

            return(template);
        }
Пример #3
0
        private void Build(Document document)
        {
            // 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.

            SKSize pageSize = page.Size;

            // Create a content composer for the content stream!

            /*
             * NOTE: There are several ways to add contents to a content stream:
             * - adding content objects directly to the Contents collection;
             * - adding content objects through a ContentScanner instance;
             * - invoking basic drawing functions through a PrimitiveComposer instance;
             * - invoking advanced static-positioning functions through a BlockComposer instance;
             * - invoking advanced dynamic-positioning functions through a FlowComposer instance (currently not implemented yet).
             */
            PrimitiveComposer composer = new PrimitiveComposer(page);
            // Wrap the content composer within a block filter!

            /*
             * NOTE: The block filter is a basic typesetter. It exposes higher-level graphical
             * functionalities (horizontal/vertical alignment, indentation, paragraph composition etc.)
             * leveraging the content composer primitives.
             * It's important to note that this is just an intermediate abstraction layer of the typesetting
             * stack: further abstract levels could sit upon it, allowing the convenient treatment of
             * typographic entities like titles, paragraphs, columns, tables, headers, footers etc.
             * When such further abstract levels are available, the final user (developer of consuming
             * applications) won't care any more of the details you can see here in the following code lines
             * (such as bothering to select the first-letter font...).
             */
            BlockComposer blockComposer = new BlockComposer(composer);

            composer.BeginLocalState();
            // Define the block frame that will constrain our contents on the page canvas!
            SKRect frame = SKRect.Create(
                Margin_X,
                Margin_Y,
                (float)pageSize.Width - Margin_X * 2,
                (float)pageSize.Height - Margin_Y * 2
                );

            // Begin the title block!
            blockComposer.Begin(frame, XAlignmentEnum.Left, YAlignmentEnum.Top);
            fonts::Font decorativeFont = fonts::Font.Get(
                document,
                GetResourcePath("fonts" + Path.DirectorySeparatorChar + "Ruritania-Outline.ttf")
                );

            composer.SetFont(decorativeFont, 56);
            blockComposer.ShowText("Chapter 1");
            blockComposer.ShowBreak();
            composer.SetFont(decorativeFont, 32);
            blockComposer.ShowText("Down the Rabbit-Hole");
            // End the title block!
            blockComposer.End();
            // Update the block frame in order to begin after the title!
            frame = SKRect.Create(
                (float)blockComposer.BoundBox.Left,
                (float)blockComposer.BoundBox.Top + blockComposer.BoundBox.Height,
                (float)blockComposer.BoundBox.Width,
                (float)pageSize.Height - Margin_Y - (blockComposer.BoundBox.Top + blockComposer.BoundBox.Height)
                );
            // Begin the body block!
            blockComposer.Begin(frame, XAlignmentEnum.Justify, YAlignmentEnum.Bottom);
            fonts::Font bodyFont = fonts::Font.Get(
                document,
                GetResourcePath("fonts" + Path.DirectorySeparatorChar + "TravelingTypewriter.otf")
                );

            composer.SetFont(bodyFont, 14);
            composer.BeginLocalState();
            composer.SetFont(decorativeFont, 28);
            blockComposer.ShowText("A");
            composer.End();
            blockComposer.ShowText("lice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, 'and what is the use of a book,' thought Alice 'without pictures or conversation?'");
            // Define new-paragraph first-line offset!
            SKSize breakSize = new SKSize(24, 8); // Indentation (24pt) and top margin (8pt).

            // Begin a new paragraph!
            blockComposer.ShowBreak(breakSize);
            blockComposer.ShowText("So she was considering in her own mind (as well as she could, for the hot day made her feel very sleepy and stupid), whether the pleasure of making a daisy-chain would be worth the trouble of getting up and picking the daisies, when suddenly a White Rabbit with pink eyes ran close by her.");
            // Begin a new paragraph!
            blockComposer.ShowBreak(breakSize);
            blockComposer.ShowText("There was nothing so VERY remarkable in that; nor did Alice think it so VERY much out of the way to hear the Rabbit say to itself, 'Oh dear! Oh dear! I shall be late!' (when she thought it over afterwards, it occurred to her that she ought to have wondered at this, but at the time it all seemed quite natural); but when the Rabbit actually TOOK A WATCH OUT OF ITS WAISTCOAT- POCKET, and looked at it, and then hurried on, Alice started to her feet, for it flashed across her mind that she had never before seen a rabbit with either a waistcoat-pocket, or a watch to take out of it, and burning with curiosity, she ran across the field after it, and fortunately was just in time to see it pop down a large rabbit-hole under the hedge.");
            // End the body block!
            blockComposer.End();
            composer.End();

            composer.BeginLocalState();
            composer.Rotate(
                90,
                new SKPoint(
                    pageSize.Width - 50,
                    pageSize.Height - 25
                    )
                );
            blockComposer = new BlockComposer(composer);
            blockComposer.Begin(
                SKRect.Create(0, 0, 300, 50),
                XAlignmentEnum.Left,
                YAlignmentEnum.Middle
                );
            composer.SetFont(bodyFont, 8);
            blockComposer.ShowText("Generated by PDF Clown on " + System.DateTime.Now);
            blockComposer.ShowBreak();
            blockComposer.ShowText("For more info, visit http://www.pdfclown.org");
            blockComposer.End();
            composer.End();

            // Flush the contents into the page!
            composer.Flush();
        }
Пример #4
0
        private void BuildSteps(
            PrimitiveComposer composer,
            string[] steps,
            colorSpaces::Color[] colors,
            SizeF pageSize
            )
        {
            composer.SetFont(ResourceName_DefaultFont,32);
              RectangleF frame = new RectangleF(
            0,
            0,
            pageSize.Width,
            pageSize.Height
            );

              // Step 0.
              {
            colors[0] = new colorSpaces::DeviceRGBColor(30 / 255d, 10 / 255d, 0);
            composer.SetFillColor(colors[0]);
            composer.SetStrokeColor(colors[0]);

            // Draw the page frame!
            composer.DrawRectangle(frame);
            composer.Stroke();

            // Draw the lower-left corner mark!
            composer.ShowText(
              "Step 0",
              new PointF(0,pageSize.Height),
              XAlignmentEnum.Left,
              YAlignmentEnum.Bottom,
              0
              );

            steps[0] = GetStepNote(composer,"default");
              }

              // Step 1.
              {
            colors[1] = new colorSpaces::DeviceRGBColor(80 / 255d, 25 / 255d, 0);
            composer.SetFillColor(colors[1]);
            composer.SetStrokeColor(colors[1]);

            // Transform the coordinate space, applying translation!
            composer.Translate(72,72);

            // Draw the page frame!
            composer.DrawRectangle(frame);
            composer.Stroke();

            // Draw the lower-left corner mark!
            composer.ShowText(
              "Step 1",
              new PointF(0,pageSize.Height),
              XAlignmentEnum.Left,
              YAlignmentEnum.Bottom,
              0
              );

            steps[1] = GetStepNote(composer,"after translate(72,72)");
              }

              // Step 2.
              {
            colors[2] = new colorSpaces::DeviceRGBColor(130 / 255d, 45 / 255d, 0);
            composer.SetFillColor(colors[2]);
            composer.SetStrokeColor(colors[2]);

            // Transform the coordinate space, applying clockwise rotation!
            composer.Rotate(-20);

            // Draw the page frame!
            composer.DrawRectangle(frame);
            composer.Stroke();

            // Draw the coordinate space origin mark!
            composer.ShowText("Origin 2");

            // Draw the lower-left corner mark!
            composer.ShowText(
              "Step 2",
              new PointF(0,pageSize.Height),
              XAlignmentEnum.Left,
              YAlignmentEnum.Bottom,
              0
              );

            steps[2] = GetStepNote(composer,"after rotate(20)");
              }

              // Step 3.
              {
            colors[3] = new colorSpaces::DeviceRGBColor(180 / 255d, 60 / 255d, 0);
            composer.SetFillColor(colors[3]);
            composer.SetStrokeColor(colors[3]);

            // Transform the coordinate space, applying translation and scaling!
            composer.Translate(0,72);
            composer.Scale(.5f,.5f);

            // Draw the page frame!
            composer.DrawRectangle(frame);
            composer.Stroke();

            // Draw the lower-left corner mark!
            composer.ShowText(
              "Step 3",
              new PointF(0,pageSize.Height),
              XAlignmentEnum.Left,
              YAlignmentEnum.Bottom,
              0
              );

            steps[3] = GetStepNote(composer,"after translate(0,72) and scale(.5,.5)");
              }

              // Step 4.
              {
            colors[4] = new colorSpaces::DeviceRGBColor(230 / 255d, 75 / 255d, 0);
            composer.SetFillColor(colors[4]);
            composer.SetStrokeColor(colors[4]);

            // Transform the coordinate space, restoring its initial CTM!
            composer.Add(
              ModifyCTM.GetResetCTM(
            composer.Scanner.State
            )
              );

            // Draw the page frame!
            composer.DrawRectangle(frame);
            composer.Stroke();

            // Draw the lower-left corner mark!
            composer.ShowText(
              "Step 4",
              new PointF(0,pageSize.Height),
              XAlignmentEnum.Left,
              YAlignmentEnum.Bottom,
              0
              );

            steps[4] = GetStepNote(composer,"after resetting CTM");
              }
        }
Пример #5
0
        private void BuildSteps(
            PrimitiveComposer composer,
            string[] steps,
            colorSpaces::Color[] colors,
            SKSize pageSize
            )
        {
            composer.SetFont(ResourceName_DefaultFont, 32);
            SKRect frame = SKRect.Create(
                0,
                0,
                pageSize.Width,
                pageSize.Height
                );

            // Step 0.
            {
                colors[0] = new colorSpaces::DeviceRGBColor(30 / 255d, 10 / 255d, 0);
                composer.SetFillColor(colors[0]);
                composer.SetStrokeColor(colors[0]);

                // Draw the page frame!
                composer.DrawRectangle(frame);
                composer.Stroke();

                // Draw the lower-left corner mark!
                composer.ShowText(
                    "Step 0",
                    new SKPoint(0, pageSize.Height),
                    XAlignmentEnum.Left,
                    YAlignmentEnum.Bottom,
                    0
                    );

                steps[0] = GetStepNote(composer, "default");
            }

            // Step 1.
            {
                colors[1] = new colorSpaces::DeviceRGBColor(80 / 255d, 25 / 255d, 0);
                composer.SetFillColor(colors[1]);
                composer.SetStrokeColor(colors[1]);

                // Transform the coordinate space, applying translation!
                composer.Translate(72, 72);

                // Draw the page frame!
                composer.DrawRectangle(frame);
                composer.Stroke();

                // Draw the lower-left corner mark!
                composer.ShowText(
                    "Step 1",
                    new SKPoint(0, pageSize.Height),
                    XAlignmentEnum.Left,
                    YAlignmentEnum.Bottom,
                    0
                    );

                steps[1] = GetStepNote(composer, "after translate(72,72)");
            }

            // Step 2.
            {
                colors[2] = new colorSpaces::DeviceRGBColor(130 / 255d, 45 / 255d, 0);
                composer.SetFillColor(colors[2]);
                composer.SetStrokeColor(colors[2]);

                // Transform the coordinate space, applying clockwise rotation!
                composer.Rotate(-20);

                // Draw the page frame!
                composer.DrawRectangle(frame);
                composer.Stroke();

                // Draw the coordinate space origin mark!
                composer.ShowText("Origin 2");

                // Draw the lower-left corner mark!
                composer.ShowText(
                    "Step 2",
                    new SKPoint(0, pageSize.Height),
                    XAlignmentEnum.Left,
                    YAlignmentEnum.Bottom,
                    0
                    );

                steps[2] = GetStepNote(composer, "after rotate(20)");
            }

            // Step 3.
            {
                colors[3] = new colorSpaces::DeviceRGBColor(180 / 255d, 60 / 255d, 0);
                composer.SetFillColor(colors[3]);
                composer.SetStrokeColor(colors[3]);

                // Transform the coordinate space, applying translation and scaling!
                composer.Translate(0, 72);
                composer.Scale(.5f, .5f);

                // Draw the page frame!
                composer.DrawRectangle(frame);
                composer.Stroke();

                // Draw the lower-left corner mark!
                composer.ShowText(
                    "Step 3",
                    new SKPoint(0, pageSize.Height),
                    XAlignmentEnum.Left,
                    YAlignmentEnum.Bottom,
                    0
                    );

                steps[3] = GetStepNote(composer, "after translate(0,72) and scale(.5,.5)");
            }

            // Step 4.
            {
                colors[4] = new colorSpaces::DeviceRGBColor(230 / 255d, 75 / 255d, 0);
                composer.SetFillColor(colors[4]);
                composer.SetStrokeColor(colors[4]);

                // Transform the coordinate space, restoring its initial CTM!
                composer.Add(
                    ModifyCTM.GetResetCTM(
                        composer.Scanner.State
                        )
                    );

                // Draw the page frame!
                composer.DrawRectangle(frame);
                composer.Stroke();

                // Draw the lower-left corner mark!
                composer.ShowText(
                    "Step 4",
                    new SKPoint(0, pageSize.Height),
                    XAlignmentEnum.Left,
                    YAlignmentEnum.Bottom,
                    0
                    );

                steps[4] = GetStepNote(composer, "after resetting CTM");
            }
        }
Пример #6
0
        private FormXObject BuildTemplate(
            Document document,
            DateTime creationDate
            )
        {
            // Create a template (form)!
              FormXObject template = new FormXObject(document, document.PageSize.Value);
              SizeF templateSize = template.Size;

              // Get form content stream!
              PrimitiveComposer composer = new PrimitiveComposer(template);

              // Showing the header image inside the common content stream...
              // Instantiate a jpeg image object!
              entities::Image image = entities::Image.Get(GetResourcePath("images" + Path.DirectorySeparatorChar + "mountains.jpg")); // Abstract image (entity).
              // Show the image inside the common content stream!
              composer.ShowXObject(
            image.ToXObject(document),
            new PointF(0,0),
            new SizeF(templateSize.Width - 50, 125)
            );

              // Showing the 'PDFClown' label inside the common content stream...
              composer.BeginLocalState();
              composer.SetFillColor(new colorSpaces::DeviceRGBColor(115f / 255, 164f / 255, 232f / 255));
              // Set the font to use!
              composer.SetFont(
            new fonts::StandardType1Font(
              document,
              fonts::StandardType1Font.FamilyEnum.Times,
              true,
              false
              ),
            120
            );
              // Show the text!
              composer.ShowText(
            "PDFClown",
            new PointF(
              0,
              templateSize.Height - (float)composer.State.Font.GetAscent(composer.State.FontSize)
              )
            );

              // Drawing the side rectangle...
              composer.DrawRectangle(
            new RectangleF(
              (float)templateSize.Width - 50,
              0,
              50,
              (float)templateSize.Height
              )
            );
              composer.Fill();
              composer.End();

              // Showing the side text inside the common content stream...
              composer.BeginLocalState();
              {
            composer.SetFont(
              new fonts::StandardType1Font(
            document,
            fonts::StandardType1Font.FamilyEnum.Helvetica,
            false,
            false
            ),
              8
              );
            composer.SetFillColor(colorSpaces::DeviceRGBColor.White);
            composer.BeginLocalState();
            {
              composer.Rotate(
            90,
            new PointF(
              templateSize.Width - 50,
              templateSize.Height - 25
              )
            );
              BlockComposer blockComposer = new BlockComposer(composer);
              blockComposer.Begin(
            new RectangleF(0,0,300,50),
            XAlignmentEnum.Left,
            YAlignmentEnum.Middle
            );
              {
            blockComposer.ShowText("Generated by PDF Clown on " + creationDate);
            blockComposer.ShowBreak();
            blockComposer.ShowText("For more info, visit http://www.pdfclown.org");
              }
              blockComposer.End();
            }
            composer.End();
              }
              composer.End();

              composer.Flush();

              return template;
        }