Beispiel #1
0
        private void AddLinearGradientAsElementBackground(Document doc)
        {
            doc.Add(new Paragraph("The \"addLinearGradientAsElementBackground\" starts here."));

            AbstractLinearGradientBuilder gradientBuilder = new StrategyBasedLinearGradientBuilder()
                                                            .AddColorStop(new GradientColorStop(ColorConstants.RED.GetColorValue()))
                                                            .AddColorStop(new GradientColorStop(ColorConstants.GREEN.GetColorValue()))
                                                            .AddColorStop(new GradientColorStop(ColorConstants.BLUE.GetColorValue()));
            BackgroundImage backgroundImage = new BackgroundImage.Builder().SetLinearGradientBuilder(gradientBuilder).Build();

            if (backgroundImage.IsBackgroundSpecified())
            {
                String text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, " +
                              "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. " +
                              "Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi " +
                              "ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit " +
                              "in voluptate velit esse cillum dolore eu fugiat nulla pariatur. " +
                              "Excepteur sint occaecat cupidatat non proident, sunt in culpa qui " +
                              "officia deserunt mollit anim id est laborum. ";

                Div div = new Div().Add(new Paragraph(text + text + text));
                div.SetProperty(Property.BACKGROUND_IMAGE, backgroundImage);
                doc.Add(div);
            }
            else
            {
                Console.Out.WriteLine("There are no linear gradient elements present within the passing image.");
            }
        }
Beispiel #2
0
        public virtual void BackgroundImageClipOriginNoRepeatTest()
        {
            PdfDocument pdfDocument = new PdfDocument(new PdfWriter(new ByteArrayOutputStream()));

            byte[]           bytes       = new byte[] { 54, 25, 47, 15, 2, 2, 2, 44, 55, 77, 86, 24 };
            PdfXObject       rawImage    = new _PdfImageXObject_544(ImageDataFactory.CreateRawImage(bytes));
            PdfCanvas        pdfCanvas   = new _PdfCanvas_555(rawImage, pdfDocument.AddNewPage());
            DrawContext      drawContext = new DrawContext(pdfDocument, pdfCanvas);
            AbstractRenderer renderer    = new DivRenderer(new Div().SetPadding(20).SetBorder(new DashedBorder(10)));

            renderer.occupiedArea = new LayoutArea(1, new Rectangle(100f, 200f, 300f, 400f));
            BackgroundImage backgroundImage = new BackgroundImage.Builder().SetImage(rawImage).SetBackgroundRepeat(new
                                                                                                                   BackgroundRepeat(BackgroundRepeat.BackgroundRepeatValue.NO_REPEAT)).SetBackgroundClip(BackgroundBox.CONTENT_BOX
                                                                                                                                                                                                         ).SetBackgroundOrigin(BackgroundBox.BORDER_BOX).Build();

            renderer.SetProperty(Property.BACKGROUND_IMAGE, backgroundImage);
            renderer.DrawBackground(drawContext);
        }
Beispiel #3
0
        public virtual void BackgroundLinearGradientClipOriginNoRepeatTest()
        {
            PdfDocument pdfDocument = new PdfDocument(new PdfWriter(new ByteArrayOutputStream()));

            byte[]           bytes       = new byte[] { 54, 25, 47, 15, 2, 2, 2, 44, 55, 77, 86, 24 };
            PdfCanvas        pdfCanvas   = new _PdfCanvas_589(pdfDocument.AddNewPage());
            DrawContext      drawContext = new DrawContext(pdfDocument, pdfCanvas);
            AbstractRenderer renderer    = new DivRenderer(new Div().SetPadding(20).SetBorder(new DashedBorder(10)));

            renderer.occupiedArea = new LayoutArea(1, new Rectangle(100f, 200f, 300f, 400f));
            Rectangle targetBoundingBox = new Rectangle(50f, 150f, 300f, 300f);
            AbstractLinearGradientBuilder gradientBuilder = new LinearGradientBuilder().SetGradientVector(targetBoundingBox
                                                                                                          .GetLeft() + 100f, targetBoundingBox.GetBottom() + 100f, targetBoundingBox.GetRight() - 100f, targetBoundingBox
                                                                                                          .GetTop() - 100f).SetSpreadMethod(GradientSpreadMethod.PAD).AddColorStop(new GradientColorStop(ColorConstants
                                                                                                                                                                                                         .RED.GetColorValue(), 0d, GradientColorStop.OffsetType.RELATIVE)).AddColorStop(new GradientColorStop(ColorConstants
                                                                                                                                                                                                                                                                                                              .BLUE.GetColorValue(), 1d, GradientColorStop.OffsetType.RELATIVE));
            BackgroundImage backgroundImage = new BackgroundImage.Builder().SetLinearGradientBuilder(gradientBuilder).
                                              SetBackgroundRepeat(new BackgroundRepeat(BackgroundRepeat.BackgroundRepeatValue.NO_REPEAT)).SetBackgroundClip
                                                  (BackgroundBox.CONTENT_BOX).SetBackgroundOrigin(BackgroundBox.BORDER_BOX).Build();

            renderer.SetProperty(Property.BACKGROUND_IMAGE, backgroundImage);
            renderer.DrawBackground(drawContext);
        }