示例#1
0
        private void DrawText(PrimitiveComposer composer, string value, SKPoint location, XAlignmentEnum xAlignment, YAlignmentEnum yAlignment, float rotation)
        {
            // Show the anchor point!
            DrawCross(composer, location);

            composer.BeginLocalState();
            composer.SetFillColor(SampleColor);
            // Show the text onto the page!
            Quad textFrame = composer.ShowText(
                value,
                location,
                xAlignment,
                yAlignment,
                rotation);

            composer.End();

            // Draw the frame binding the shown text!
            DrawFrame(composer, textFrame.GetPoints());

            composer.BeginLocalState();
            composer.SetFont(composer.State.Font, 8);
            // Draw the rotation degrees!
            composer.ShowText(
                "(" + ((int)rotation) + " degrees)",
                new SKPoint(location.X + 70, location.Y),
                XAlignmentEnum.Left,
                YAlignmentEnum.Middle,
                0
                );
            composer.End();
        }
示例#2
0
        public BlocoQrCodeNFC(DanfeViewModel viewModel, Estilo estilo, PrimitiveComposer primitiveComposer, float y, Document context) : base(estilo)
        {
            var result = new MemoryStream();

            primitiveComposer.BeginLocalState();
            primitiveComposer.SetFont(estilo.FonteCampoConteudo.FonteInterna, estilo.FonteCampoConteudo.Tamanho);
            primitiveComposer.ShowText("CONSULTA VIA LEITOR DE QR CODE", new PointF(140, y + 10), XAlignmentEnum.Center, YAlignmentEnum.Top, 0);

            var bitmap = GerarQrCode.GerarQRCode(viewModel.QrCode);

            bitmap.Save(result, ImageFormat.Jpeg);
            result.Position = 0;
            org.pdfclown.documents.contents.entities.Image   image        = org.pdfclown.documents.contents.entities.Image.Get(result);
            org.pdfclown.documents.contents.xObjects.XObject imageXObject = image.ToXObject(context);

            primitiveComposer.ShowXObject(imageXObject, new PointF(140, y + 20), new SizeF(150, 150), XAlignmentEnum.Center, YAlignmentEnum.Top, 0);

            if (viewModel.CalculoImposto.ValorAproximadoTributos > 0)
            // valor aproximado dos tributos
            {
                primitiveComposer.SetFont(estilo.FonteCampoConteudoNegrito.FonteInterna, 7);

                primitiveComposer.ShowText($"CONFORME LEI 12.741/2012 o valor aproximado dos tributos é {viewModel.CalculoImposto.ValorAproximadoTributos.Formatar()}", new PointF(140, y + 180), XAlignmentEnum.Center, YAlignmentEnum.Middle, 0);
                primitiveComposer.ShowText($"O valor aproximado dos tributos Federais é {viewModel.CalculoImposto.ValorAproximadoTributosFederais.Formatar()}", new PointF(140, y + 190), XAlignmentEnum.Center, YAlignmentEnum.Middle, 0);
                primitiveComposer.ShowText($"O valor aproximado dos tributos Estaduais é {viewModel.CalculoImposto.ValorAproximadoTributosEstaduais.Formatar()}", new PointF(140, y + 200), XAlignmentEnum.Center, YAlignmentEnum.Middle, 0);
            }
        }
示例#3
0
        public BlocoFormaPagamentoNFC(DanfeViewModel viewModel, Estilo estilo, PrimitiveComposer primitiveComposer, float y) : base(estilo)
        {
            primitiveComposer.BeginLocalState();
            primitiveComposer.SetFont(estilo.FonteCampoConteudo.FonteInterna, estilo.FonteCampoConteudo.Tamanho);
            primitiveComposer.ShowText("FORMAS DE PAGAMENTO", new PointF(25, y + 10), XAlignmentEnum.Left, YAlignmentEnum.Middle, 0);
            primitiveComposer.ShowText("VALOR PAGO", new PointF(250, y + 10), XAlignmentEnum.Right, YAlignmentEnum.Middle, 0);
            //primitiveComposer.ShowText("Troco", new PointF(160, y + 10), XAlignmentEnum.Left, YAlignmentEnum.Middle, 0);

            y = y + 10;

            foreach (var item in viewModel.Pagamento)
            {
                foreach (var detalhe in item.DetalhePagamento)
                {
                    y = y + 10;

                    primitiveComposer.ShowText(detalhe.FormaPagamento.FormaPagamentoToString(), new PointF(25, y), XAlignmentEnum.Left, YAlignmentEnum.Middle, 0);
                    primitiveComposer.ShowText(detalhe.Valor.Formatar(), new PointF(250, y), XAlignmentEnum.Right, YAlignmentEnum.Middle, 0);
                }
            }

            Y_NFC = y + 10;

            primitiveComposer.DrawLine(new PointF(15, Y_NFC), new PointF(265, Y_NFC));
            primitiveComposer.SetLineDash(new org.pdfclown.documents.contents.LineDash(new double[] { 3, 2 }));
            primitiveComposer.Stroke();
            primitiveComposer.End();
        }
示例#4
0
        /**
         * <summary>Populates a PDF file with contents.</summary>
         */
        private void Populate(
            Document document
            )
        {
            // 1. Add the page to the document!
            Page page = new Page(document); // Instantiates the page inside the document context.

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

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

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

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

            BlockComposer blockComposer = new BlockComposer(composer);

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

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

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

            // 4. Flush the contents into the page!
            composer.Flush();
        }
        /**
         * <summary>Populates a PDF file with contents.</summary>
         */
        private void Populate(
            Document document
            )
        {
            // 1. Add the page to the document!
            Page page = new Page(document); // Instantiates the page inside the document context.

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

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

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

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

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

            // 4. Flush the contents into the page!
            composer.Flush();
        }
        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();
                }
            }
        }
示例#7
0
        private FormXObject CreateWatermark(Document document)
        {
            SKSize size = document.GetSize();

            // 1. Create an external form object to represent the watermark!
            FormXObject watermark = new FormXObject(document, size);

            // 2. Inserting the contents of the watermark...
            // 2.1. Create a content composer!
            PrimitiveComposer composer = new PrimitiveComposer(watermark);

            // 2.2. Inserting the contents...
            // Set the font to use!
            composer.SetFont(new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Times, true, false), 120);
            // Set the color to fill the text characters!
            composer.SetFillColor(new DeviceRGBColor(115 / 255d, 164 / 255d, 232 / 255d));
            // Apply transparency!
            {
                ExtGState state = new ExtGState(document);
                state.FillAlpha = .3;
                composer.ApplyState(state);
            }
            // Show the text!
            composer.ShowText(
                "PdfClown",                                     // Text to show.
                new SKPoint(size.Width / 2f, size.Height / 2f), // Anchor location: page center.
                XAlignmentEnum.Center,                          // Horizontal placement (relative to the anchor): center.
                YAlignmentEnum.Middle,                          // Vertical placement (relative to the anchor): middle.
                50                                              // Rotation: 50-degree-counterclockwise.
                );
            // 2.3. Flush the contents into the watermark!
            composer.Flush();

            return(watermark);
        }
        private void Apply(
            ComboBox field
            )
        {
            Document document = field.Document;
            Widget   widget   = field.Widgets[0];

            Appearance appearance = widget.Appearance;

            if (appearance == null)
            {
                widget.Appearance = appearance = new Appearance(document);
            }

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

            FormXObject normalAppearanceState;

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

                float      lineWidth = 1;
                RectangleF frame     = new RectangleF(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(
                    new StandardType1Font(
                        document,
                        StandardType1Font.FamilyEnum.Helvetica,
                        false,
                        false
                        ),
                    FontSize
                    );
                composer.ShowText(
                    (string)field.Value,
                    new PointF(0, size.Height / 2),
                    XAlignmentEnum.Left,
                    YAlignmentEnum.Middle,
                    0
                    );
                composer.End();

                composer.Flush();
            }
            appearance.Normal[null] = normalAppearanceState;
        }
示例#9
0
        public BlocoConsultaChaveNFC(DanfeViewModel viewModel, Estilo estilo, PrimitiveComposer primitiveComposer, float y) : base(estilo)
        {
            primitiveComposer.BeginLocalState();
            primitiveComposer.SetFont(estilo.FonteCampoConteudo.FonteInterna, estilo.FonteCampoConteudo.Tamanho);
            primitiveComposer.ShowText("Consulta pela chave de acesso em", new PointF(140, y + 10), XAlignmentEnum.Center, YAlignmentEnum.Middle, 0);
            primitiveComposer.ShowText(viewModel.EndConsulta, new PointF(140, y + 20), XAlignmentEnum.Center, YAlignmentEnum.Middle, 0);
            primitiveComposer.ShowText("CHAVE DE ACESSO", new PointF(140, y + 30), XAlignmentEnum.Center, YAlignmentEnum.Middle, 0);
            primitiveComposer.ShowText(viewModel.ChaveAcesso, new PointF(140, y + 40), XAlignmentEnum.Center, YAlignmentEnum.Middle, 0);

            Y_NFC = y + 50;

            primitiveComposer.DrawLine(new PointF(15, Y_NFC), new PointF(265, Y_NFC));
            primitiveComposer.SetLineDash(new org.pdfclown.documents.contents.LineDash(new double[] { 3, 2 }));

            primitiveComposer.Stroke();
            primitiveComposer.End();
        }
        public BlocoDestinatarioRemetenteNFC(DanfeViewModel viewModel, Estilo estilo, PrimitiveComposer primitiveComposer, float y) : base(viewModel, estilo)
        {
            primitiveComposer.BeginLocalState();
            primitiveComposer.SetFont(estilo.FonteCampoConteudo.FonteInterna, estilo.FonteCampoConteudo.Tamanho);

            if (viewModel.Destinatario != null && !string.IsNullOrWhiteSpace(viewModel?.Destinatario?.CnpjCpf))
            {
                var dest = viewModel?.Destinatario;

                primitiveComposer.ShowText("CONSUMIDOR", new PointF(140, y + 10), XAlignmentEnum.Center, YAlignmentEnum.Middle, 0);

                if (!string.IsNullOrWhiteSpace(dest.RazaoSocial))
                {
                    if (dest.RazaoSocial.Length > 30)
                    {
                        primitiveComposer.ShowText(dest.RazaoSocial.Substring(0, 30), new PointF(140, y + 20), XAlignmentEnum.Center, YAlignmentEnum.Top, 0);
                        primitiveComposer.ShowText(dest.RazaoSocial.Substring(30), new PointF(140, y + 30), XAlignmentEnum.Center, YAlignmentEnum.Top, 0);

                        y = y + 10;
                    }
                    else
                    {
                        primitiveComposer.ShowText($"NOME: {dest.RazaoSocial}", new PointF(140, y + 20), XAlignmentEnum.Center, YAlignmentEnum.Middle, 0);
                    }
                }

                primitiveComposer.ShowText($"CNPJ/CPF: {dest.CnpjCpf}", new PointF(140, y + 30), XAlignmentEnum.Center, YAlignmentEnum.Middle, 0);


                if (!string.IsNullOrWhiteSpace(dest.EnderecoLogadrouro) &&
                    !string.IsNullOrWhiteSpace(dest.EnderecoNumero) &&
                    !string.IsNullOrWhiteSpace(dest.EnderecoBairro) &&
                    !string.IsNullOrWhiteSpace(dest.Municipio))
                {
                    primitiveComposer.ShowText($"{dest.EnderecoLogadrouro}, {dest.EnderecoNumero}, {dest.EnderecoBairro}, {dest.Municipio} - {dest.EnderecoUf}", new PointF(140, y + 40), XAlignmentEnum.Center, YAlignmentEnum.Middle, 0);
                }

                Y_NFC = y + 50;

                primitiveComposer.DrawLine(new PointF(15, Y_NFC), new PointF(265, Y_NFC));
                primitiveComposer.SetLineDash(new org.pdfclown.documents.contents.LineDash(new double[] { 3, 2 }));

                primitiveComposer.Stroke();
                primitiveComposer.End();
            }
            else
            {
                primitiveComposer.ShowText("CONSUMIDOR NÃO IDENTIFICADO", new PointF(140, y + 10), XAlignmentEnum.Center, YAlignmentEnum.Middle, 0);

                Y_NFC = y + 20;

                primitiveComposer.DrawLine(new PointF(15, Y_NFC), new PointF(265, Y_NFC));
                primitiveComposer.SetLineDash(new org.pdfclown.documents.contents.LineDash(new double[] { 3, 2 }));

                primitiveComposer.Stroke();
                primitiveComposer.End();
            }
        }
示例#11
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...
            StandardType1Font font = new StandardType1Font(
                document,
                StandardType1Font.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();
            }
        }
示例#12
0
        public BlocoIdentificacaoNFC(DanfeViewModel viewModel, Estilo estilo, PrimitiveComposer primitiveComposer, float y) : base(estilo)
        {
            primitiveComposer.BeginLocalState();

            primitiveComposer.SetFont(estilo.FonteCampoTituloNegrito.FonteInterna, estilo.FonteCampoTituloNegrito.Tamanho);
            primitiveComposer.ShowText($"Nº: {viewModel?.NfNumero}  Série: {viewModel?.NfSerie}", new PointF(140, y + 10), XAlignmentEnum.Center, YAlignmentEnum.Middle, 0);

            primitiveComposer.SetFont(estilo.FonteCampoConteudoNegrito.FonteInterna, estilo.FonteCampoConteudoNegrito.Tamanho);
            primitiveComposer.ShowText($"{viewModel?.DataHoraEmissao} - Via Consumidor", new PointF(140, y + 20), XAlignmentEnum.Center, YAlignmentEnum.Middle, 0);

            primitiveComposer.SetFont(estilo.FonteCampoConteudo.FonteInterna, estilo.FonteCampoConteudo.Tamanho);
            primitiveComposer.ShowText("PROTOCOLO DE AUTORIZAÇÃO", new PointF(140, y + 30), XAlignmentEnum.Center, YAlignmentEnum.Middle, 0);
            primitiveComposer.ShowText($"{viewModel.ProtocoloAutorizacao}", new PointF(140, y + 40), XAlignmentEnum.Center, YAlignmentEnum.Middle, 0);

            Y_NFC = y + 50;

            primitiveComposer.DrawLine(new PointF(15, Y_NFC), new PointF(265, Y_NFC));
            primitiveComposer.SetLineDash(new org.pdfclown.documents.contents.LineDash(new double[] { 3, 2 }));

            primitiveComposer.Stroke();
            primitiveComposer.End();
        }
        public BlocoIdentificacaoEmitenteNFC(DanfeViewModel viewModel, Estilo estilo, PrimitiveComposer primitiveComposer) : base(viewModel, estilo)
        {
            primitiveComposer.BeginLocalState();
            primitiveComposer.SetFont(estilo.FonteCampoTituloNegrito.FonteInterna, estilo.FonteCampoTituloNegrito.Tamanho);
            int y = 0;

            var emitente = viewModel.Emitente;

            if (emitente.RazaoSocial.Length > 39)
            {
                primitiveComposer.ShowText(emitente.RazaoSocial.Substring(0, 39), new PointF(140, 10), XAlignmentEnum.Center, YAlignmentEnum.Top, 0);
                primitiveComposer.ShowText(emitente.RazaoSocial.Substring(39), new PointF(140, 20), XAlignmentEnum.Center, YAlignmentEnum.Top, 0);

                primitiveComposer.ShowText($"CNPJ - {Formatador.FormatarCnpj(emitente.CnpjCpf)}", new PointF(140, 30), XAlignmentEnum.Center, YAlignmentEnum.Top, 0);

                y = 30;
            }
            else
            {
                primitiveComposer.ShowText(emitente.RazaoSocial, new PointF(140, 10), XAlignmentEnum.Center, YAlignmentEnum.Top, 0);
                primitiveComposer.ShowText($"CNPJ - {Formatador.FormatarCnpj(emitente.CnpjCpf)}", new PointF(140, 20), XAlignmentEnum.Center, YAlignmentEnum.Top, 0);

                y = 20;
            }

            primitiveComposer.SetFont(estilo.FonteCampoConteudoNegrito.FonteInterna, estilo.FonteCampoConteudoNegrito.Tamanho);

            if (!string.IsNullOrWhiteSpace(emitente.EnderecoLogadrouro) &&
                !string.IsNullOrWhiteSpace(emitente.EnderecoNumero) &&
                !string.IsNullOrWhiteSpace(emitente.EnderecoBairro) &&
                !string.IsNullOrWhiteSpace(emitente.Municipio))
            {
                if (emitente.EnderecoLogadrouro.Length >= 25)
                {
                    primitiveComposer.ShowText($"{emitente.EnderecoLogadrouro.Substring(0, 25)}, {emitente.EnderecoNumero} - {emitente.EnderecoBairro} - {emitente.Municipio} - {emitente.EnderecoUf}",
                                               new PointF(140, y + 10), XAlignmentEnum.Center, YAlignmentEnum.Top, 0);
                }
                else
                {
                    primitiveComposer.ShowText($"{emitente.EnderecoLogadrouro}, {emitente.EnderecoNumero} - {emitente.EnderecoBairro} - {emitente.Municipio} - {emitente.EnderecoUf}",
                                               new PointF(140, y + 10), XAlignmentEnum.Center, YAlignmentEnum.Top, 0);
                }
            }
            primitiveComposer.DrawLine(new PointF(15, y + 20), new PointF(265, y + 20));
            primitiveComposer.SetLineDash(new org.pdfclown.documents.contents.LineDash(new double[] { 3, 2 }));
            primitiveComposer.Stroke();
            primitiveComposer.End();

            Y_NFC = y + 20;
        }
示例#14
0
        private void Populate(
            Document document
            )
        {
            StandardType1Font bodyFont = new StandardType1Font(
            document,
            StandardType1Font.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...
              SizeF pageSize = page.Size;
              PrimitiveComposer composer = new PrimitiveComposer(page);
              composer.SetFont(bodyFont,32);
              composer.ShowText(
            pageFormat + " (" + pageOrientation + ")", // Text.
            new PointF(
              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();
            }
              }
        }
示例#15
0
        public BlocoInformacaoFiscal(DanfeViewModel viewModel, Estilo estilo, PrimitiveComposer primitiveComposer, float y) : base(estilo)
        {
            if (viewModel.TipoAmbiente == 2)
            {
                primitiveComposer.BeginLocalState();
                primitiveComposer.SetFont(estilo.FonteCampoConteudoNegrito.FonteInterna, estilo.FonteTamanhoMinimo + 1);
                primitiveComposer.ShowText("EMITIDA EM AMBIENTE DE HOMOLOGAÇÃO - SEM VALOR FISCAL", new PointF(132.5F, y + 10), XAlignmentEnum.Center, YAlignmentEnum.Middle, 0);

                Y_NFC = y + 20;
                primitiveComposer.DrawLine(new PointF(15, Y_NFC), new PointF(265, Y_NFC));
                primitiveComposer.SetLineDash(new org.pdfclown.documents.contents.LineDash(new double[] { 3, 2 }));
                primitiveComposer.Stroke();
                primitiveComposer.End();
            }
            else
            {
                Y_NFC = y;
            }
        }
        /**
         * <summary>Populates a PDF file with contents.</summary>
         */
        private void Populate(
            Document document
            )
        {
            // 1. Add the page to the document!
            Page page = new Page(document); // Instantiates the page inside the document context.

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

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

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

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

            // 4. Flush the contents into the page!
            composer.Flush();
        }
示例#17
0
        /**
          <summary>Populates a PDF file with contents.</summary>
        */
        private void Populate(
            Document document
            )
        {
            // 1. Add the page to the document!
              Page page = new Page(document); // Instantiates the page inside the document context.
              document.Pages.Add(page); // Puts the page in the pages collection.

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

              // 3. Inserting contents...
              // Set the font to use!
              composer.SetFont(
            new StandardType1Font(
              document,
              StandardType1Font.FamilyEnum.Courier,
              true,
              false
              ),
            32
            );
              // Show the text onto the page!
              /*
            NOTE: PrimitiveComposer's ShowText() method is the most basic way to add text to a page
            -- see BlockComposer for more advanced uses (horizontal and vertical alignment, hyphenation,
            etc.).
              */
              composer.ShowText(
            "Hello World!",
            new PointF(32,48)
            );

              // 4. Flush the contents into the page!
              composer.Flush();
        }
示例#18
0
        private void PrintMarcaDAgua(String text)
        {
            PointF p = PointF.Empty;

            var blocoProdutos = BlocosSuperiores.FirstOrDefault(x => x is BlocoProdutos);

            if (blocoProdutos == null)
            {
                p = new PointF(_Danfe.Size.Width / 2f, _Danfe.Size.Height / 2f);
            }
            else
            {
                p.X = blocoProdutos.Posicao.X + blocoProdutos.Size.Width / 2F;
                p.Y = blocoProdutos.Posicao.Y + blocoProdutos.Size.Height / 2F;
            }

            _Composer.BeginLocalState();
            _Composer.SetFont(_Danfe.FontBold, 50);
            org.pdfclown.documents.contents.ExtGState state = new org.pdfclown.documents.contents.ExtGState(_Danfe.Document);
            state.FillAlpha = 0.3F;
            _Composer.ApplyState(state);
            _Composer.ShowText(text, p, XAlignmentEnum.Center, YAlignmentEnum.Middle, 0);
            _Composer.End();
        }
示例#19
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();
        }
示例#20
0
        private FormXObject CreateWatermark(
            Document document
            )
        {
            SizeF size = document.GetSize();

              // 1. Create an external form object to represent the watermark!
              FormXObject watermark = new FormXObject(document, size);

              // 2. Inserting the contents of the watermark...
              // 2.1. Create a content composer!
              PrimitiveComposer composer = new PrimitiveComposer(watermark);
              // 2.2. Inserting the contents...
              // Set the font to use!
              composer.SetFont(new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Times, true, false), 120);
              // Set the color to fill the text characters!
              composer.SetFillColor(new DeviceRGBColor(115 / 255d, 164 / 255d, 232 / 255d));
              // Apply transparency!
              {
            ExtGState state = new ExtGState(document);
            state.FillAlpha = .3;
            composer.ApplyState(state);
              }
              // Show the text!
              composer.ShowText(
            "PDFClown", // Text to show.
            new PointF(size.Width / 2f, size.Height / 2f), // Anchor location: page center.
            XAlignmentEnum.Center, // Horizontal placement (relative to the anchor): center.
            YAlignmentEnum.Middle, // Vertical placement (relative to the anchor): middle.
            50 // Rotation: 50-degree-counterclockwise.
            );
              // 2.3. Flush the contents into the watermark!
              composer.Flush();

              return watermark;
        }
示例#21
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");
              }
        }
示例#22
0
        private void BuildSimpleTextPage(
            Document document
            )
        {
            // 1. Add the page to the document!
              Page page = new Page(document); // Instantiates the page inside the document context.
              document.Pages.Add(page); // Puts the page in the pages collection.

              SizeF pageSize = page.Size;

              // 2. Create a content composer for the page!
              PrimitiveComposer composer = new PrimitiveComposer(page);
              // 3. Inserting contents...
              // Set the font to use!
              composer.SetFont(
            new fonts::StandardType1Font(
              document,
              fonts::StandardType1Font.FamilyEnum.Courier,
              true,
              false
              ),
            32
            );

              XAlignmentEnum[] xAlignments = (XAlignmentEnum[])Enum.GetValues(typeof(XAlignmentEnum));
              YAlignmentEnum[] yAlignments = (YAlignmentEnum[])Enum.GetValues(typeof(YAlignmentEnum));
              int step = (int)(pageSize.Height) / ((xAlignments.Length-1) * yAlignments.Length+1);

              BlockComposer blockComposer = new BlockComposer(composer);
              RectangleF frame = new RectangleF(
            30,
            0,
            pageSize.Width-60,
            step/2
            );
              blockComposer.Begin(frame,XAlignmentEnum.Center,YAlignmentEnum.Middle);
              blockComposer.ShowText("Simple alignment");
              blockComposer.End();

              frame = new RectangleF(
            30,
            pageSize.Height-step/2,
            pageSize.Width-60,
            step/2 -10
            );
              blockComposer.Begin(frame,XAlignmentEnum.Left,YAlignmentEnum.Bottom);
              composer.SetFont(composer.State.Font,10);
              blockComposer.ShowText(
            "NOTE: showText(...) methods return the actual bounding box of the text shown.\n"
              + "NOTE: The rotation parameter can be freely defined as a floating point value."
            );
              blockComposer.End();

              composer.SetFont(composer.State.Font,12);
              int x = 30;
              int y = step;
              int alignmentIndex = 0;
              foreach(XAlignmentEnum xAlignment
            in (XAlignmentEnum[])Enum.GetValues(typeof(XAlignmentEnum)))
              {
            /*
              NOTE: As text shown through PrimitiveComposer has no bounding box constraining its extension,
              applying the justified alignment has no effect (it degrades to center alignment);
              in order to get such an effect, use BlockComposer instead.
            */
            if(xAlignment.Equals(XAlignmentEnum.Justify))
              continue;

            foreach(YAlignmentEnum yAlignment
              in (YAlignmentEnum[])Enum.GetValues(typeof(YAlignmentEnum)))
            {
              if(alignmentIndex % 2 == 0)
              {
            composer.BeginLocalState();
            composer.SetFillColor(BackColor);
            composer.DrawRectangle(
              new RectangleF(
                0,
                y-step/2,
                pageSize.Width,
                step
                )
              );
            composer.Fill();
            composer.End();
              }

              composer.ShowText(
            xAlignment + " " + yAlignment + ":",
            new PointF(x,y),
            XAlignmentEnum.Left,
            YAlignmentEnum.Middle,
            0
            );

              y+=step;
              alignmentIndex++;
            }
              }

              float rotationStep = 0;
              float rotation = 0;
              for(
            int columnIndex = 0;
            columnIndex < 2;
            columnIndex++
            )
              {
            switch(columnIndex)
            {
              case 0:
            x = 200;
            rotationStep = 0;
            break;
              case 1:
            x = (int)pageSize.Width / 2 + 100;
            rotationStep = 360 / ((xAlignments.Length-1) * yAlignments.Length-1);
            break;
            }
            y = step;
            rotation = 0;
            foreach(XAlignmentEnum xAlignment
              in (XAlignmentEnum[])Enum.GetValues(typeof(XAlignmentEnum)))
            {
              /*
            NOTE: As text shown through PrimitiveComposer has no bounding box constraining its extension,
            applying the justified alignment has no effect (it degrades to center alignment);
            in order to get such an effect, use BlockComposer instead.
              */
              if(xAlignment.Equals(XAlignmentEnum.Justify))
            continue;

              foreach(YAlignmentEnum yAlignment
            in (YAlignmentEnum[])Enum.GetValues(typeof(YAlignmentEnum)))
              {
            float startArcAngle = 0;
            switch(xAlignment)
            {
              case XAlignmentEnum.Left:
                // OK -- NOOP.
                break;
              case XAlignmentEnum.Right:
              case XAlignmentEnum.Center:
                startArcAngle = 180;
                break;
            }

            composer.DrawArc(
              new RectangleF(
                x-10,
                y-10,
                20,
                20
                ),
              startArcAngle,
              startArcAngle+rotation
              );

            DrawText(
              composer,
              "PDF Clown",
              new PointF(x,y),
              xAlignment,
              yAlignment,
              rotation
              );
            y+=step;
            rotation+=rotationStep;
              }
            }
              }

              // 4. Flush the contents into the page!
              composer.Flush();
        }
示例#23
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(
                new StandardType1Font(
                    document,
                    StandardType1Font.FamilyEnum.Courier,
                    true,
                    false
                    ),
                14
                );

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

                Widget fieldWidget = new Widget(
                    page,
                    new RectangleF(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(new RectangleF(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 PointF(140, 118),
                    XAlignmentEnum.Right,
                    YAlignmentEnum.Middle,
                    0
                    );
                CheckBox field = new CheckBox(
                    "myCheck",
                    new Widget(
                        page,
                        new RectangleF(150, 100, 36, 36)
                        ),
                    true // Current value.
                    );   // 4.1. Field instantiation.
                fieldStyle.Apply(field);
                fields.Add(field);
                field = new CheckBox(
                    "myCheck2",
                    new Widget(
                        page,
                        new RectangleF(200, 100, 36, 36)
                        ),
                    true // Current value.
                    );   // 4.1. Field instantiation.
                fieldStyle.Apply(field);
                fields.Add(field);
                field = new CheckBox(
                    "myCheck3",
                    new Widget(
                        page,
                        new RectangleF(250, 100, 36, 36)
                        ),
                    false                // 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.
            }

            // 4.c. Radio button.
            {
                composer.ShowText(
                    "RadioButton:",
                    new PointF(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,
                        new RectangleF(150, 150, 36, 36),
                        "first"
                        ),
                    new Widget(
                        page,
                        new RectangleF(200, 150, 36, 36),
                        "second"
                        ),
                    new Widget(
                        page,
                        new RectangleF(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 PointF(140, 218),
                    XAlignmentEnum.Right,
                    YAlignmentEnum.Middle,
                    0
                    );
                TextField field = new TextField(
                    "myText",
                    new Widget(
                        page,
                        new RectangleF(150, 200, 200, 36)
                        ),
                    "Carmen Consoli"        // Current value.
                    );                      // 4.1. Field instantiation.
                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(new RectangleF(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 PointF(140, 268),
                        XAlignmentEnum.Right,
                        YAlignmentEnum.Middle,
                        0
                        );
                    ListBox field = new ListBox(
                        "myList",
                        new Widget(
                            page,
                            new RectangleF(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 PointF(140, 350),
                        XAlignmentEnum.Right,
                        YAlignmentEnum.Middle,
                        0
                        );
                    ComboBox field = new ComboBox(
                        "myCombo",
                        new Widget(
                            page,
                            new RectangleF(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();
        }
示例#24
0
        /**
         * <summary>Shows text.</summary>
         * <returns>Last shown character index.</returns>
         */
        public int ShowText(
            string text
            )
        {
            if (currentRow == null ||
                text == null)
            {
                return(0);
            }

            ContentScanner.GraphicsState state = baseComposer.State;
            fonts::Font font       = state.Font;
            float       fontSize   = state.FontSize;
            float       lineHeight = font.GetLineHeight(fontSize);

            TextFitter textFitter = new TextFitter(
                text,
                0,
                font,
                fontSize,
                hyphenation
                );
            int textLength = text.Length;
            int index      = 0;

            while (true)
            {
                // Beginning of current row?
                if (currentRow.Width == 0)
                {
                    // Removing leading space...
                    while (true)
                    {
                        // Did we reach the text end?
                        if (index == textLength)
                        {
                            goto endTextShowing; // NOTE: I know GOTO is evil, yet in this case it's a much cleaner solution.
                        }
                        if (text[index] != ' ')
                        {
                            break;
                        }

                        index++;
                    }
                }

                // Text height: exceeds current row's height?
                if (lineHeight > currentRow.Height)
                {
                    // Text height: exceeds block's remaining vertical space?
                    if (lineHeight > frame.Height - currentRow.Y) // Text exceeds.
                    {
                        // Terminate the current row!
                        EndRow(false);
                        goto endTextShowing; // NOTE: I know GOTO is evil, yet in this case it's a much cleaner solution.
                    }
                    else // Text doesn't exceed.
                    {
                        // Adapt current row's height!
                        currentRow.Height = lineHeight;
                    }
                }

                // Does the text fit?
                if (textFitter.Fit(
                        index,
                        frame.Width - currentRow.Width // Residual row width.
                        ))
                {
                    // Get the fitting text!
                    string textChunk         = textFitter.FittedText;
                    float  textChunkWidth    = textFitter.FittedWidth;
                    PointF textChunkLocation = new PointF(
                        (float)currentRow.Width,
                        (float)currentRow.Y
                        );

                    // Render the fitting text:
                    // - open the row object's local state!

                    /*
                     * NOTE: This device allows a fine-grained control over the row object's representation.
                     * It MUST be coupled with a closing statement on row object's end.
                     */
                    RowObject obj = new RowObject(
                        baseComposer.BeginLocalState(),
                        lineHeight,
                        textChunkWidth,
                        CountOccurrence(' ', textChunk)
                        );
                    currentRow.Objects.Add(obj);
                    currentRow.SpaceCount += obj.SpaceCount;
                    // - show the text chunk!
                    baseComposer.ShowText(
                        textChunk,
                        textChunkLocation
                        );
                    // - close the row object's local state!
                    baseComposer.End();

                    // Update ancillary parameters:
                    // - update row width!
                    currentRow.Width += textChunkWidth;
                    // - update cursor position!
                    index = textFitter.EndIndex;
                }

                // Evaluating trailing text...
                while (true)
                {
                    // Did we reach the text end?
                    if (index == textLength)
                    {
                        goto endTextShowing; // NOTE: I know GOTO is evil, yet in this case it's a much cleaner solution.
                    }
                    switch (text[index])
                    {
                    case '\r':
                        break;

                    case '\n':
                        // New paragraph!
                        index++;
                        ShowBreak();
                        goto endTrailParsing; // NOTE: I know GOTO is evil, yet in this case it's a much cleaner solution.

                    default:
                        // New row (within the same paragraph)!
                        EndRow(false); BeginRow();
                        goto endTrailParsing; // NOTE: I know GOTO is evil, yet in this case it's a much cleaner solution.
                    }

                    index++;
                }
                endTrailParsing :;
            }
            endTextShowing :;

            return(index);
        }
示例#25
0
        private void BuildMiscellaneousPage(
            Document document
            )
        {
            // 1. Add the page to the document!
              Page page = new Page(document); // Instantiates the page inside the document context.
              document.Pages.Add(page); // Puts the page in the pages collection.

              SizeF pageSize = page.Size;

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

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

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

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

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

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

              composer.Stroke();

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

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

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

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

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

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

            y += 30;
              }

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

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

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

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

              // 4. Flush the contents into the page!
              composer.Flush();
        }
示例#26
0
        private void DrawText(
            PrimitiveComposer composer,
            string value,
            PointF location,
            XAlignmentEnum xAlignment,
            YAlignmentEnum yAlignment,
            float rotation
            )
        {
            // Show the anchor point!
              DrawCross(composer,location);

              composer.BeginLocalState();
              composer.SetFillColor(SampleColor);
              // Show the text onto the page!
              Quad textFrame = composer.ShowText(
            value,
            location,
            xAlignment,
            yAlignment,
            rotation
            );
              composer.End();

              // Draw the frame binding the shown text!
              DrawFrame(
            composer,
            textFrame.Points
            );

              composer.BeginLocalState();
              composer.SetFont(composer.State.Font,8);
              // Draw the rotation degrees!
              composer.ShowText(
            "(" + ((int)rotation) + " degrees)",
            new PointF(
              location.X+70,
              location.Y
              ),
            XAlignmentEnum.Left,
            YAlignmentEnum.Middle,
            0
            );
              composer.End();
        }
示例#27
0
        private void Populate(
            Document document
            )
        {
            Page page = new Page(document);
              document.Pages.Add(page);
              SizeF pageSize = page.Size;

              PrimitiveComposer composer = new PrimitiveComposer(page);

              int x = Margin, y = Margin;
              StandardType1Font titleFont = new StandardType1Font(
            document,
            StandardType1Font.FamilyEnum.Times,
            true,
            true
            );
              StandardType1Font font = null;
              // Iterating through the standard Type 1 fonts...
              foreach(StandardType1Font.FamilyEnum fontFamily
            in (StandardType1Font.FamilyEnum[])Enum.GetValues(typeof(StandardType1Font.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 == StandardType1Font.FamilyEnum.Symbol
              || fontFamily == StandardType1Font.FamilyEnum.ZapfDingbats))
              break;

              bool bold, italic;
              switch(styleIndex)
              {
            case 0: // Regular.
              bold = false;
              italic = false;
              break;
            case 1: // Bold.
              bold = true;
              italic = false;
              break;
            case 2: // Italic.
              bold = false;
              italic = true;
              break;
            case 3: // Bold italic.
              bold = true;
              italic = true;
              break;
            default:
              throw new Exception("styleIndex " + styleIndex + " not supported.");
              }
              // Define the font used to show its character set!
              font = new StandardType1Font(
            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 PointF(x,y),
              new PointF(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 PointF(x,y)
            );

              y += 40;
              // Set the font used to show its character set!
              composer.SetFont(font,FontBaseSize);
              // Iterating through the font characters...
              for(int charCode = 32; charCode < 256; charCode++)
              {
            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 PointF(pageSize.Width - Margin, y),
                XAlignmentEnum.Right,
                YAlignmentEnum.Top,
                0
                );
              composer.SetFont(font,FontBaseSize);
              y += FontBaseSize * 2;
            }

            try
            {
              // Show the current character (using the current standard Type 1 font)!
              composer.ShowText(
                new String(new char[]{(char)charCode}),
                new PointF(x,y)
                );
              x += FontBaseSize;
              if(x > pageSize.Width - Margin)
              {x = Margin; y += 30;}
            }
            catch
            { /* Ignore */ }
              }

              x = Margin; y += Margin;
            }
              }
              composer.Flush();
        }
示例#28
0
        public override ContentObject ToInlineObject(
      PrimitiveComposer composer
      )
        {
            ContentObject barcodeObject = composer.BeginLocalState();
              {
            fonts::Font font = new fonts::StandardType1Font(
              composer.Scanner.Contents.Document,
              fonts::StandardType1Font.FamilyEnum.Helvetica,
              false,
              false
              );
            double fontSize = (DigitGlyphWidth / font.GetWidth(code.Substring(0,1), 1));

            // 1. Bars.
            {
              double elementX = DigitWidth;
              int[] elementWidths = GetElementWidths();

              double guardBarIndentY = DigitHeight / 2;
              bool isBar = true;
              for(
            int elementIndex = 0;
            elementIndex < elementWidths.Length;
            elementIndex++
            )
              {
            double elementWidth = elementWidths[elementIndex];
            // Dark element?
            /*
              NOTE: EAN symbol elements alternate bars to spaces.
            */
            if(isBar)
            {
              composer.DrawRectangle(
                new RectangleF(
                  (float)elementX,
                  0,
                  (float)elementWidth,
                  (float)(BarHeight + (
                    // Guard bar?
                    Array.BinarySearch<int>(GuardBarIndexes, elementIndex) >= 0
                      ? guardBarIndentY // Guard bar.
                      : 0 // Symbol character.
                    ))
                  )
                );
            }

            elementX += elementWidth;
            isBar = !isBar;
              }
              composer.Fill();
            }

            // 2. Digits.
            {
              composer.SetFont(font,fontSize);
              double digitY = BarHeight + (DigitHeight - (font.GetAscent(fontSize))) / 2;
              // Showing the digits...
              for(
            int digitIndex = 0;
            digitIndex < 13;
            digitIndex++
            )
              {
            string digit = code.Substring(digitIndex, 1);
            double pX = DigitGlyphXs[digitIndex] // Digit position.
              - font.GetWidth(digit,fontSize) / 2; // Centering.
            // Show the current digit!
            composer.ShowText(
              digit,
              new PointF((float)pX,(float)digitY)
              );
              }
            }
            composer.End();
              }
              return barcodeObject;
        }
示例#29
0
        private void BuildTextBlockPage3(
            Document document
            )
        {
            // 1. Add the page to the document!
              Page page = new Page(document); // Instantiates the page inside the document context.
              document.Pages.Add(page); // Puts the page in the pages collection.

              SizeF pageSize = page.Size;

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

              // 3. Drawing the page contents...
              fonts::Font mainFont = new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Courier, true, false);
              int stepCount = 5;
              int step = (int)(pageSize.Height) / (stepCount + 1);

              // 3.1. Drawing the page title...
              BlockComposer blockComposer = new BlockComposer(composer);
              {
            blockComposer.Begin(
              new RectangleF(
            30,
            0,
            pageSize.Width-60,
            step*.8f
            ),
              XAlignmentEnum.Center,
              YAlignmentEnum.Middle
              );
            composer.SetFont(mainFont, 32);
            blockComposer.ShowText("Block line space");
            blockComposer.End();
              }

              // 3.2. Drawing the text blocks...
              fonts::Font sampleFont = new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Times, false, false);
              int x = 30;
              int y = (int)(step * 1.1);
              blockComposer.LineSpace.UnitMode = Length.UnitModeEnum.Relative;
              for(int index = 0; index < stepCount; index++)
              {
            float relativeLineSpace = 0.5f * index;
            blockComposer.LineSpace.Value = relativeLineSpace;

            composer.SetFont(mainFont, 12);
            composer.ShowText(
              relativeLineSpace + ":",
              new PointF(x,y),
              XAlignmentEnum.Left,
              YAlignmentEnum.Middle,
              0
              );

            composer.SetFont(sampleFont, 10);
            RectangleF frame = new RectangleF(150, y - step * .4f, 350, step * .9f);
            blockComposer.Begin(frame,XAlignmentEnum.Left,YAlignmentEnum.Top);
            blockComposer.ShowText("Demonstrating how to set the block line space. Line space can be expressed either as an absolute value (in user-space units) or as a relative one (floating-point ratio); in the latter case the base value is represented by the current font's line height (so that, for example, 2 means \"a line space that's twice as the line height\").");
            blockComposer.End();

            composer.BeginLocalState();
            {
              composer.SetLineWidth(0.2);
              composer.SetLineDash(new LineDash(new double[]{5,5}, 5));
              composer.DrawRectangle(frame);
              composer.Stroke();
            }
            composer.End();

            y+=step;
              }

              // 4. Flush the contents into the page!
              composer.Flush();
        }
示例#30
0
        private void BuildLinks(
            Document document
            )
        {
            Pages pages = document.Pages;
              Page page = new Page(document);
              pages.Add(page);

              StandardType1Font font = new StandardType1Font(
            document,
            StandardType1Font.FamilyEnum.Courier,
            true,
            false
            );

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

              /*
            2.1. Goto-URI link.
              */
              {
            blockComposer.Begin(new RectangleF(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();

            try
            {
              /*
            NOTE: This statement instructs the PDF viewer to navigate to the given URI when the link is clicked.
              */
              annotations::Link link = new annotations::Link(
            page,
            new Rectangle(240,100,100,50),
            "Link annotation",
            new GoToURI(
              document,
              new Uri("http://www.sourceforge.net/projects/clown")
              )
            );
              link.Border = new annotations::Border(
            document,
            3,
            annotations::Border.StyleEnum.Beveled,
            null
            );
            }
            catch(Exception exception)
            {throw new Exception("",exception);}
              }

              /*
            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);
            annotations::FileAttachment attachment = new annotations::FileAttachment(
              page,
              new Rectangle(0, -20, 10, 10),
              "File attachment annotation",
              FileSpecification.Get(
            EmbeddedFile.Get(
              document,
              filePath
              ),
            fileName
            )
              );
            attachment.Name = fileAttachmentName;
            attachment.IconType = annotations::FileAttachment.IconTypeEnum.PaperClip;

            blockComposer.Begin(new RectangleF(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.
            */
            annotations::Link link = new annotations::Link(
              page,
              new Rectangle(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.
            )
              );
            link.Border = new annotations::Border(
              document,
              1,
              annotations::Border.StyleEnum.Dashed,
              new LineDash(new double[]{8,5,2,5})
              );
              }

              /*
            2.3. Textual link.
              */
              {
            blockComposer.Begin(new RectangleF(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();

            try
            {
              composer.BeginLocalState();
              composer.SetFont(font,10);
              composer.SetFillColor(DeviceRGBColor.Get(System.Drawing.Color.Blue));
              composer.ShowText(
            "PDF Clown Project's repository at SourceForge.net",
            new PointF(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 PointF(240,285),
            XAlignmentEnum.Left,
            YAlignmentEnum.Bottom,
            -90,
            new GoToURI(
              document,
              new Uri("http://www.pdfclown.org")
              )
            );
              composer.End();
            }
            catch
            {}
              }

              composer.Flush();
        }
示例#31
0
        private void Populate(Document document)
        {
            Page page = new Page(document);

            document.Pages.Add(page);

            PrimitiveComposer        composer = new PrimitiveComposer(page);
            fonts::StandardType1Font font     = new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Courier, true, false);

            composer.SetFont(font, 12);

            // Sticky note.
            composer.ShowText("Sticky note annotation:", new SKPoint(35, 35));
            new StickyNote(page, new SKPoint(50, 50), "Text of the Sticky note annotation")
            {
                IconType = StickyNote.IconTypeEnum.Note,
                Color    = DeviceRGBColor.Get(SKColors.Yellow),
                Popup    = new Popup(
                    page,
                    SKRect.Create(200, 25, 200, 75),
                    "Text of the Popup annotation (this text won't be visible as associating popups to markup annotations overrides the former's properties with the latter's)"
                    ),
                Author  = "Stefano",
                Subject = "Sticky note",
                IsOpen  = true
            };
            new StickyNote(page, new SKPoint(80, 50), "Text of the Help sticky note annotation")
            {
                IconType = StickyNote.IconTypeEnum.Help,
                Color    = DeviceRGBColor.Get(SKColors.Pink),
                Author   = "Stefano",
                Subject  = "Sticky note",
                Popup    = new Popup(
                    page,
                    SKRect.Create(400, 25, 200, 75),
                    "Text of the Popup annotation (this text won't be visible as associating popups to markup annotations overrides the former's properties with the latter's)"
                    )
            };
            new StickyNote(page, new SKPoint(110, 50), "Text of the Comment sticky note annotation")
            {
                IconType = StickyNote.IconTypeEnum.Comment,
                Color    = DeviceRGBColor.Get(SKColors.Green),
                Author   = "Stefano",
                Subject  = "Sticky note"
            };
            new StickyNote(page, new SKPoint(140, 50), "Text of the Key sticky note annotation")
            {
                IconType = StickyNote.IconTypeEnum.Key,
                Color    = DeviceRGBColor.Get(SKColors.Blue),
                Author   = "Stefano",
                Subject  = "Sticky note"
            };

            // Callout.
            composer.ShowText("Callout note annotation:", new SKPoint(35, 85));
            new FreeText(page, SKRect.Create(250, 90, 150, 70), "Text of the Callout note annotation")
            {
                Line = new FreeText.CalloutLine(
                    page,
                    new SKPoint(100, 100),
                    new SKPoint(150, 125),
                    new SKPoint(250, 125)
                    ),
                Type         = FreeText.TypeEnum.Callout,
                LineEndStyle = LineEndStyleEnum.OpenArrow,
                Border       = new Border(1),
                Color        = DeviceRGBColor.Get(SKColors.Yellow)
            };

            // File attachment.
            composer.ShowText("File attachment annotation:", new SKPoint(35, 135));
            new FileAttachment(
                page,
                SKRect.Create(50, 150, 15, 20),
                "Text of the File attachment annotation",
                FileSpecification.Get(
                    EmbeddedFile.Get(document, GetResourcePath("images" + Path.DirectorySeparatorChar + "gnu.jpg")),
                    "happyGNU.jpg")
                )
            {
                IconType = FileAttachment.IconTypeEnum.PaperClip,
                Author   = "Stefano",
                Subject  = "File attachment"
            };

            composer.ShowText("Line annotation:", new SKPoint(35, 185));
            {
                composer.BeginLocalState();
                composer.SetFont(font, 10);

                // Arrow line.
                composer.ShowText("Arrow:", new SKPoint(50, 200));
                new Line(
                    page,
                    new SKPoint(50, 260),
                    new SKPoint(200, 210),
                    "Text of the Arrow line annotation",
                    DeviceRGBColor.Get(SKColors.Black))
                {
                    StartStyle     = LineEndStyleEnum.Circle,
                    EndStyle       = LineEndStyleEnum.ClosedArrow,
                    CaptionVisible = true,
                    FillColor      = DeviceRGBColor.Get(SKColors.Green),
                    Author         = "Stefano",
                    Subject        = "Arrow line"
                };

                // Dimension line.
                composer.ShowText("Dimension:", new SKPoint(300, 200));
                new Line(
                    page,
                    new SKPoint(300, 220),
                    new SKPoint(500, 220),
                    "Text of the Dimension line annotation",
                    DeviceRGBColor.Get(SKColors.Blue)
                    )
                {
                    LeaderLineLength          = 20,
                    LeaderLineExtensionLength = 10,
                    StartStyle     = LineEndStyleEnum.OpenArrow,
                    EndStyle       = LineEndStyleEnum.OpenArrow,
                    Border         = new Border(1),
                    CaptionVisible = true,
                    Author         = "Stefano",
                    Subject        = "Dimension line"
                };

                composer.End();
            }

            var path = new SKPath();

            path.MoveTo(new SKPoint(50, 320));
            path.LineTo(new SKPoint(70, 305));
            path.LineTo(new SKPoint(110, 335));
            path.LineTo(new SKPoint(130, 320));
            path.LineTo(new SKPoint(110, 305));
            path.LineTo(new SKPoint(70, 335));
            path.LineTo(new SKPoint(50, 320));
            // Scribble.
            composer.ShowText("Scribble annotation:", new SKPoint(35, 285));
            new Scribble(
                page,
                new List <SKPath> {
                path
            },
                "Text of the Scribble annotation",
                DeviceRGBColor.Get(SKColors.Orange))
            {
                Border  = new Border(1, new LineDash(new double[] { 5, 2, 2, 2 })),
                Author  = "Stefano",
                Subject = "Scribble"
            };

            // Rectangle.
            composer.ShowText("Rectangle annotation:", new SKPoint(35, 350));
            new PdfClown.Documents.Interaction.Annotations.Rectangle(
                page,
                SKRect.Create(50, 370, 100, 30),
                "Text of the Rectangle annotation")
            {
                Color   = DeviceRGBColor.Get(SKColors.Red),
                Border  = new Border(1, new LineDash(new double[] { 5 })),
                Author  = "Stefano",
                Subject = "Rectangle",
                Popup   = new Popup(
                    page,
                    SKRect.Create(200, 325, 200, 75),
                    "Text of the Popup annotation (this text won't be visible as associating popups to markup annotations overrides the former's properties with the latter's)"
                    )
            };

            // Ellipse.
            composer.ShowText("Ellipse annotation:", new SKPoint(35, 415));
            new Ellipse(
                page,
                SKRect.Create(50, 440, 100, 30),
                "Text of the Ellipse annotation")
            {
                BorderEffect = new BorderEffect(BorderEffect.TypeEnum.Cloudy, 1),
                FillColor    = DeviceRGBColor.Get(SKColors.Cyan),
                Color        = DeviceRGBColor.Get(SKColors.Black),
                Author       = "Stefano",
                Subject      = "Ellipse"
            };

            // Rubber stamp.
            composer.ShowText("Rubber stamp annotations:", new SKPoint(35, 505));
            {
                fonts::Font stampFont = fonts::Font.Get(document, GetResourcePath("fonts" + Path.DirectorySeparatorChar + "TravelingTypewriter.otf"));
                new Stamp(
                    page,
                    new SKPoint(75, 570),
                    "This is a round custom stamp",
                    new StampAppearanceBuilder(document, StampAppearanceBuilder.TypeEnum.Round, "Done", 50, stampFont)
                    .Build()
                    )
                {
                    Rotation = -10,
                    Author   = "Stefano",
                    Subject  = "Custom stamp"
                };

                new Stamp(
                    page,
                    new SKPoint(210, 570),
                    "This is a squared (and round-cornered) custom stamp",
                    new StampAppearanceBuilder(document, StampAppearanceBuilder.TypeEnum.Squared, "Classified", 150, stampFont)
                {
                    Color = DeviceRGBColor.Get(SKColors.Orange)
                }.Build()
                    )
                {
                    Rotation = 15,
                    Author   = "Stefano",
                    Subject  = "Custom stamp"
                };

                fonts::Font stampFont2 = fonts::Font.Get(document, GetResourcePath("fonts" + Path.DirectorySeparatorChar + "MgOpenCanonicaRegular.ttf"));
                new Stamp(
                    page,
                    new SKPoint(350, 570),
                    "This is a striped custom stamp",
                    new StampAppearanceBuilder(document, StampAppearanceBuilder.TypeEnum.Striped, "Out of stock", 100, stampFont2)
                {
                    Color = DeviceRGBColor.Get(SKColors.Gray)
                }.Build()
                    )
                {
                    Rotation = 90,
                    Author   = "Stefano",
                    Subject  = "Custom stamp"
                };

                // Define the standard stamps template path!

                /*
                 * NOTE: The PDF specification defines several stamps (aka "standard stamps") whose rendering
                 * depends on the support of viewer applications. As such support isn't guaranteed, PDF Clown
                 * offers smooth, ready-to-use embedding of these stamps through the StampPath property of the
                 * document configuration: you can decide to point to the stamps directory of your Acrobat
                 * installation (e.g., in my GNU/Linux system it's located in
                 * "/opt/Adobe/Reader9/Reader/intellinux/plug_ins/Annotations/Stamps/ENU") or to the
                 * collection included in this distribution (std-stamps.pdf).
                 */
                document.Configuration.StampPath = GetResourcePath("../../pkg/templates/std-stamps.pdf");

                // Add a standard stamp, rotating it 15 degrees counterclockwise!
                new Stamp(
                    page,
                    new SKPoint(485, 515),
                    null, // Default size is natural size.
                    "This is 'Confidential', a standard stamp",
                    StandardStampEnum.Confidential)
                {
                    Rotation = 15,
                    Author   = "Stefano",
                    Subject  = "Standard stamp"
                };

                // Add a standard stamp, without rotation!
                new Stamp(
                    page,
                    new SKPoint(485, 580),
                    null, // Default size is natural size.
                    "This is 'SBApproved', a standard stamp",
                    StandardStampEnum.BusinessApproved)
                {
                    Author  = "Stefano",
                    Subject = "Standard stamp"
                };

                // Add a standard stamp, rotating it 10 degrees clockwise!
                new Stamp(
                    page,
                    new SKPoint(485, 635),
                    new SKSize(0, 40), // This scales the width proportionally to the 40-unit height (you can obviously do also the opposite, defining only the width).
                    "This is 'SHSignHere', a standard stamp",
                    StandardStampEnum.SignHere)
                {
                    Rotation = -10,
                    Author   = "Stefano",
                    Subject  = "Standard stamp"
                };
            }

            composer.ShowText("Text markup annotations:", new SKPoint(35, 650));
            {
                composer.BeginLocalState();
                composer.SetFont(font, 8);

                new TextMarkup(
                    page,
                    composer.ShowText("Highlight annotation", new SKPoint(35, 680)),
                    "Text of the Highlight annotation",
                    TextMarkup.MarkupTypeEnum.Highlight)
                {
                    Author  = "Stefano",
                    Subject = "An highlight text markup!"
                };
                new TextMarkup(
                    page,
                    composer.ShowText("Highlight annotation 2", new SKPoint(35, 695)).Inflate(0, 1),
                    "Text of the Highlight annotation 2",
                    TextMarkup.MarkupTypeEnum.Highlight)
                {
                    Color = DeviceRGBColor.Get(SKColors.Magenta)
                };
                new TextMarkup(
                    page,
                    composer.ShowText("Highlight annotation 3", new SKPoint(35, 710)).Inflate(0, 2),
                    "Text of the Highlight annotation 3",
                    TextMarkup.MarkupTypeEnum.Highlight)
                {
                    Color = DeviceRGBColor.Get(SKColors.Red)
                };

                new TextMarkup(
                    page,
                    composer.ShowText("Squiggly annotation", new SKPoint(180, 680)),
                    "Text of the Squiggly annotation",
                    TextMarkup.MarkupTypeEnum.Squiggly);
                new TextMarkup(
                    page,
                    composer.ShowText("Squiggly annotation 2", new SKPoint(180, 695)).Inflate(0, 2.5f),
                    "Text of the Squiggly annotation 2",
                    TextMarkup.MarkupTypeEnum.Squiggly)
                {
                    Color = DeviceRGBColor.Get(SKColors.Orange)
                };
                new TextMarkup(
                    page,
                    composer.ShowText("Squiggly annotation 3", new SKPoint(180, 710)).Inflate(0, 3),
                    "Text of the Squiggly annotation 3",
                    TextMarkup.MarkupTypeEnum.Squiggly)
                {
                    Color = DeviceRGBColor.Get(SKColors.Pink)
                };

                new TextMarkup(
                    page,
                    composer.ShowText("Underline annotation", new SKPoint(320, 680)),
                    "Text of the Underline annotation",
                    TextMarkup.MarkupTypeEnum.Underline
                    );
                new TextMarkup(
                    page,
                    composer.ShowText("Underline annotation 2", new SKPoint(320, 695)).Inflate(0, 2.5f),
                    "Text of the Underline annotation 2",
                    TextMarkup.MarkupTypeEnum.Underline
                    )
                {
                    Color = DeviceRGBColor.Get(SKColors.Orange)
                };
                new TextMarkup(
                    page,
                    composer.ShowText("Underline annotation 3", new SKPoint(320, 710)).Inflate(0, 3),
                    "Text of the Underline annotation 3",
                    TextMarkup.MarkupTypeEnum.Underline
                    )
                {
                    Color = DeviceRGBColor.Get(SKColors.Green)
                };

                new TextMarkup(
                    page,
                    composer.ShowText("StrikeOut annotation", new SKPoint(455, 680)),
                    "Text of the StrikeOut annotation",
                    TextMarkup.MarkupTypeEnum.StrikeOut
                    );
                new TextMarkup(
                    page,
                    composer.ShowText("StrikeOut annotation 2", new SKPoint(455, 695)).Inflate(0, 2.5f),
                    "Text of the StrikeOut annotation 2",
                    TextMarkup.MarkupTypeEnum.StrikeOut
                    )
                {
                    Color = DeviceRGBColor.Get(SKColors.Orange)
                };
                new TextMarkup(
                    page,
                    composer.ShowText("StrikeOut annotation 3", new SKPoint(455, 710)).Inflate(0, 3),
                    "Text of the StrikeOut annotation 3",
                    TextMarkup.MarkupTypeEnum.StrikeOut
                    )
                {
                    Color = DeviceRGBColor.Get(SKColors.Green)
                };

                composer.End();
            }
            composer.Flush();
        }
示例#32
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);
        }
示例#33
0
        private void Populate(
            Document document
            )
        {
            Page page = new Page(document);
              document.Pages.Add(page);

              PrimitiveComposer composer = new PrimitiveComposer(page);
              StandardType1Font font = new StandardType1Font(
            document,
            StandardType1Font.FamilyEnum.Courier,
            true,
            false
            );
              composer.SetFont(font,12);

              // Note.
              composer.ShowText("Note annotation:", new Point(35,35));
              annotations::Note note = new annotations::Note(
            page,
            new Point(50, 50),
            "Note annotation"
            );
              note.IconType = annotations::Note.IconTypeEnum.Help;
              note.ModificationDate = new DateTime();
              note.IsOpen = true;

              // Callout.
              composer.ShowText("Callout note annotation:", new Point(35,85));
              annotations::CalloutNote calloutNote = new annotations::CalloutNote(
            page,
            new Rectangle(50, 100, 200, 24),
            "Callout note annotation"
            );
              calloutNote.Justification = JustificationEnum.Right;
              calloutNote.Line = new annotations::CalloutNote.LineObject(
            page,
            new Point(150,650),
            new Point(100,600),
            new Point(50,100)
            );

              // File attachment.
              composer.ShowText("File attachment annotation:", new Point(35,135));
              annotations::FileAttachment attachment = new annotations::FileAttachment(
            page,
            new Rectangle(50, 150, 12, 12),
            "File attachment annotation",
            FileSpecification.Get(
              EmbeddedFile.Get(
            document,
            GetResourcePath("images" + Path.DirectorySeparatorChar + "gnu.jpg")
            ),
              "happyGNU.jpg"
              )
            );
              attachment.IconType = annotations::FileAttachment.IconTypeEnum.PaperClip;

              composer.BeginLocalState();

              // Arrow line.
              composer.ShowText("Line annotation:", new Point(35,185));
              composer.SetFont(font,10);
              composer.ShowText("Arrow:", new Point(50,200));
              annotations::Line line = new annotations::Line(
            page,
            new Point(50, 260),
            new Point(200,210),
            "Arrow line annotation"
            );
              line.FillColor = new DeviceRGBColor(1,0,0);
              line.StartStyle = annotations::Line.LineEndStyleEnum.Circle;
              line.EndStyle = annotations::Line.LineEndStyleEnum.ClosedArrow;
              line.CaptionVisible = true;

              // Dimension line.
              composer.ShowText("Dimension:", new Point(300,200));
              line = new annotations::Line(
            page,
            new Point(300,220),
            new Point(500,220),
            "Dimension line annotation"
            );
              line.LeaderLineLength = 20;
              line.LeaderLineExtensionLength = 10;
              line.CaptionVisible = true;

              composer.End();

              // Scribble.
              composer.ShowText("Scribble annotation:", new Point(35,285));
              new annotations::Scribble(
            page,
            new RectangleF(50, 300, 100, 30),
            "Scribble annotation",
            new List<IList<PointF>>(
              new List<PointF>[]
              {
            new List<PointF>(
              new PointF[]
              {
                new PointF(50,300),
                new PointF(70,310),
                new PointF(100,320)
              }
              )
              }
              )
            );

              // Rectangle.
              composer.ShowText("Rectangle annotation:", new Point(35,335));
              annotations::Rectangle rectangle = new annotations::Rectangle(
            page,
            new Rectangle(50, 350, 100, 30),
            "Rectangle annotation"
            );
              rectangle.FillColor = new DeviceRGBColor(1,0,0);
              rectangle.Alpha = .25;

              // Ellipse.
              composer.ShowText("Ellipse annotation:", new Point(35,385));
              annotations::Ellipse ellipse = new annotations::Ellipse(
            page,
            new Rectangle(50, 400, 100, 30),
            "Ellipse annotation"
            );
              ellipse.FillColor = new DeviceRGBColor(0,0,1);

              // Rubber stamp.
              composer.ShowText("Rubber stamp annotation:", new Point(35,435));
              new annotations::RubberStamp(
            page,
            new Rectangle(50, 450, 100, 30),
            "Rubber stamp annotation",
            annotations::RubberStamp.IconTypeEnum.Approved
            );

              // Caret.
              composer.ShowText("Caret annotation:", new Point(35,485));
              annotations::Caret caret = new annotations::Caret(
            page,
            new Rectangle(50, 500, 100, 30),
            "Caret annotation"
            );
              caret.SymbolType = annotations::Caret.SymbolTypeEnum.NewParagraph;

              composer.Flush();
        }
示例#34
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(new StandardType1Font(document, StandardType1Font.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.PageMode = Document.PageModeEnum.Layers; // Shows the layers tab on document opening.

              // Get the root layers collection!
              Layers rootLayers = layerDefinition.Layers;

              // 1. Nested layers.
              {
            Layer nestedLayer = new Layer(document, "Nested layers");
            rootLayers.Add(nestedLayer);
            Layers nestedSubLayers = nestedLayer.Layers;

            Layer nestedLayer1 = new Layer(document, "Nested layer 1");
            nestedSubLayers.Add(nestedLayer1);

            Layer nestedLayer2 = new Layer(document, "Nested layer 2");
            nestedSubLayers.Add(nestedLayer2);
            nestedLayer2.Locked = true;

            /*
              NOTE: Text in this section is shown using PrimitiveComposer.
            */
            composer.BeginLayer(nestedLayer);
            composer.ShowText(nestedLayer.Title, new PointF(50, 50));
            composer.End();

            composer.BeginLayer(nestedLayer1);
            composer.ShowText(nestedLayer1.Title, new PointF(50, 75));
            composer.End();

            composer.BeginLayer(nestedLayer2);
            composer.ShowText(nestedLayer2.Title, new PointF(50, 100));
            composer.End();
              }

              // 2. Simple group (labeled group of non-nested, inclusive-state layers).
              {
            Layers simpleGroup = new Layers(document, "Simple group");
            rootLayers.Add(simpleGroup);

            Layer layer1 = new Layer(document, "Grouped layer 1");
            simpleGroup.Add(layer1);

            Layer layer2 = new Layer(document, "Grouped layer 2");
            simpleGroup.Add(layer2);

            /*
              NOTE: Text in this section is shown using BlockComposer along with PrimitiveComposer
              to demonstrate their flexible cooperation.
            */
            blockComposer.Begin(new RectangleF(50, 125, 200, 50), XAlignmentEnum.Left, YAlignmentEnum.Middle);

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

            blockComposer.ShowBreak(new SizeF(0, 15));

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

            blockComposer.End();
              }

              // 3. Radio group (labeled group of non-nested, exclusive-state layers).
              {
            Layers radioGroup = new Layers(document, "Radio group");
            rootLayers.Add(radioGroup);

            Layer radio1 = new Layer(document, "Radiogrouped layer 1");
            radioGroup.Add(radio1);
            radio1.Visible = true;

            Layer radio2 = new Layer(document, "Radiogrouped layer 2");
            radioGroup.Add(radio2);
            radio2.Visible = false;

            Layer radio3 = new Layer(document, "Radiogrouped layer 3");
            radioGroup.Add(radio3);
            radio3.Visible = false;

            // Register this option group in the layer configuration!
            LayerGroup options = new LayerGroup(document);
            options.Add(radio1);
            options.Add(radio2);
            options.Add(radio3);
            layerDefinition.OptionGroups.Add(options);

            /*
              NOTE: Text in this section is shown using BlockComposer along with PrimitiveComposer
              to demonstrate their flexible cooperation.
            */
            blockComposer.Begin(new RectangleF(50, 185, 200, 75), XAlignmentEnum.Left, YAlignmentEnum.Middle);

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

            blockComposer.ShowBreak(new SizeF(0, 15));

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

            blockComposer.ShowBreak(new SizeF(0, 15));

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

            blockComposer.End();
              }

              // 4. Print-only layer.
              {
            Layer printOnlyLayer = new Layer(document, "Print-only layer");
            printOnlyLayer.Visible = false;
            printOnlyLayer.Printable = true;
            printOnlyLayer.Locked = true;
            rootLayers.Add(printOnlyLayer);

            composer.BeginLayer(printOnlyLayer);
            composer.ShowText(printOnlyLayer.Title, new PointF(50, 270));
            composer.End();
              }
              composer.Flush();
        }
        private void BuildSimpleTextPage(
            Document document
            )
        {
            // 1. Add the page to the document!
            Page page = new Page(document); // Instantiates the page inside the document context.

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

            SizeF pageSize = page.Size;

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

            // 3. Inserting contents...
            // Set the font to use!
            composer.SetFont(
                new fonts::StandardType1Font(
                    document,
                    fonts::StandardType1Font.FamilyEnum.Courier,
                    true,
                    false
                    ),
                32
                );

            XAlignmentEnum[] xAlignments = (XAlignmentEnum[])Enum.GetValues(typeof(XAlignmentEnum));
            YAlignmentEnum[] yAlignments = (YAlignmentEnum[])Enum.GetValues(typeof(YAlignmentEnum));
            int step = (int)(pageSize.Height) / ((xAlignments.Length - 1) * yAlignments.Length + 1);

            BlockComposer blockComposer = new BlockComposer(composer);
            RectangleF    frame         = new RectangleF(
                30,
                0,
                pageSize.Width - 60,
                step / 2
                );

            blockComposer.Begin(frame, XAlignmentEnum.Center, YAlignmentEnum.Middle);
            blockComposer.ShowText("Simple alignment");
            blockComposer.End();

            frame = new RectangleF(
                30,
                pageSize.Height - step / 2,
                pageSize.Width - 60,
                step / 2 - 10
                );
            blockComposer.Begin(frame, XAlignmentEnum.Left, YAlignmentEnum.Bottom);
            composer.SetFont(composer.State.Font, 10);
            blockComposer.ShowText(
                "NOTE: showText(...) methods return the actual bounding box of the text shown.\n"
                + "NOTE: The rotation parameter can be freely defined as a floating point value."
                );
            blockComposer.End();

            composer.SetFont(composer.State.Font, 12);
            int x = 30;
            int y = step;
            int alignmentIndex = 0;

            foreach (XAlignmentEnum xAlignment
                     in (XAlignmentEnum[])Enum.GetValues(typeof(XAlignmentEnum)))
            {
                /*
                 * NOTE: As text shown through PrimitiveComposer has no bounding box constraining its extension,
                 * applying the justified alignment has no effect (it degrades to center alignment);
                 * in order to get such an effect, use BlockComposer instead.
                 */
                if (xAlignment.Equals(XAlignmentEnum.Justify))
                {
                    continue;
                }

                foreach (YAlignmentEnum yAlignment
                         in (YAlignmentEnum[])Enum.GetValues(typeof(YAlignmentEnum)))
                {
                    if (alignmentIndex % 2 == 0)
                    {
                        composer.BeginLocalState();
                        composer.SetFillColor(BackColor);
                        composer.DrawRectangle(
                            new RectangleF(
                                0,
                                y - step / 2,
                                pageSize.Width,
                                step
                                )
                            );
                        composer.Fill();
                        composer.End();
                    }

                    composer.ShowText(
                        xAlignment + " " + yAlignment + ":",
                        new PointF(x, y),
                        XAlignmentEnum.Left,
                        YAlignmentEnum.Middle,
                        0
                        );

                    y += step;
                    alignmentIndex++;
                }
            }

            float rotationStep = 0;
            float rotation     = 0;

            for (
                int columnIndex = 0;
                columnIndex < 2;
                columnIndex++
                )
            {
                switch (columnIndex)
                {
                case 0:
                    x            = 200;
                    rotationStep = 0;
                    break;

                case 1:
                    x            = (int)pageSize.Width / 2 + 100;
                    rotationStep = 360 / ((xAlignments.Length - 1) * yAlignments.Length - 1);
                    break;
                }
                y        = step;
                rotation = 0;
                foreach (XAlignmentEnum xAlignment
                         in (XAlignmentEnum[])Enum.GetValues(typeof(XAlignmentEnum)))
                {
                    /*
                     * NOTE: As text shown through PrimitiveComposer has no bounding box constraining its extension,
                     * applying the justified alignment has no effect (it degrades to center alignment);
                     * in order to get such an effect, use BlockComposer instead.
                     */
                    if (xAlignment.Equals(XAlignmentEnum.Justify))
                    {
                        continue;
                    }

                    foreach (YAlignmentEnum yAlignment
                             in (YAlignmentEnum[])Enum.GetValues(typeof(YAlignmentEnum)))
                    {
                        float startArcAngle = 0;
                        switch (xAlignment)
                        {
                        case XAlignmentEnum.Left:
                            // OK -- NOOP.
                            break;

                        case XAlignmentEnum.Right:
                        case XAlignmentEnum.Center:
                            startArcAngle = 180;
                            break;
                        }

                        composer.DrawArc(
                            new RectangleF(
                                x - 10,
                                y - 10,
                                20,
                                20
                                ),
                            startArcAngle,
                            startArcAngle + rotation
                            );

                        DrawText(
                            composer,
                            "PDF Clown",
                            new PointF(x, y),
                            xAlignment,
                            yAlignment,
                            rotation
                            );
                        y        += step;
                        rotation += rotationStep;
                    }
                }
            }

            // 4. Flush the contents into the page!
            composer.Flush();
        }
示例#36
0
        private void createPDF()
        {
            SaveFileDialog saveFileDialog2 = new SaveFileDialog();

            saveFileDialog2.Filter   = "PDF File|*.pdf";
            saveFileDialog2.Title    = "Save as PDF";
            saveFileDialog2.FileName = "" + profile.fname + " " + profile.sname + " 6CIT Results";

            File     file     = new File();
            Document document = file.Document;
            Page     page     = new Page(document);

            document.Pages.Add(page);

            PrimitiveComposer Composer = new PrimitiveComposer(page);

            Composer.SetLineWidth(200);

            //Image
            Image image = Image.Get("brain100.jpg");

            org.pdfclown.documents.contents.xObjects.XObject imageXObject = image.ToXObject(document);
            Composer.ShowXObject(imageXObject, new PointF(450, 40));
            Composer.Flush();

            //Title
            Composer.SetFont(new StandardType1Font(document, StandardType1Font.FamilyEnum.Helvetica, true, false), 32);
            Composer.ShowText("6CIT Results", new PointF(32, 40));

            //Heading 1
            Composer.SetFont(new StandardType1Font(document, StandardType1Font.FamilyEnum.Helvetica, true, false), 24);
            Composer.ShowText("Patient Details", new PointF(32, 100));

            //Heading 1 - Body
            Composer.SetFont(new StandardType1Font(document, StandardType1Font.FamilyEnum.Helvetica, true, false), 12);
            Composer.ShowText("NHS ID: " + profile.ID, new PointF(32, 140));
            Composer.ShowText("Name: " + profile.fname + " " + profile.sname, new PointF(32, 160));
            Composer.ShowText("Sex: " + profile.sex, new PointF(32, 180));
            Composer.ShowText("DOB: " + profile.DOB, new PointF(32, 200));
            Composer.ShowText("Address: " + profile.al1 + " " + profile.al2, new PointF(32, 220));
            Composer.ShowText("Postcode: " + profile.postcode, new PointF(32, 240));
            Composer.ShowText("Occupation: " + profile.occupation, new PointF(32, 260));
            Composer.ShowText("Test Score: " + score + " , Advice: " + calcAdvice(score), new PointF(32, 300));


            //Patient Notes
            BlockComposer bc = new BlockComposer(Composer);

            bc.Hyphenation = false;
            bc.LineSpace   = new Length(1.0, Length.UnitModeEnum.Relative);

            int notesLength = profile.notes.Length;
            int notesHeight = 40;
            int notesY      = 320;

            if (notesLength < 300)
            {
                notesHeight = 150;
            }
            else if (notesLength > 300 && notesLength < 600)
            {
                notesHeight = 200;
            }
            else if (notesLength > 600 && notesLength <= 1000)
            {
                notesHeight = 350;
            }

            RectangleF area = new RectangleF(new PointF(32, notesY), new SizeF(400, notesHeight));

            bc.Begin(area, XAlignmentEnum.Left, YAlignmentEnum.Top);
            bc.ShowText("Notes: " + "\n" + profile.notes);
            bc.End();

            Composer.Flush();

            var date = DateTime.Now;

            //Add Page 2
            Page page2 = new Page(document);

            document.Pages.Add(page2);
            Composer = new PrimitiveComposer(page2);

            //Heading 2
            Composer.SetFont(new StandardType1Font(document, StandardType1Font.FamilyEnum.Helvetica, true, false), 24);
            Composer.ShowText("6CIT Results ", new PointF(32, 40));

            Composer.SetFont(new StandardType1Font(document, StandardType1Font.FamilyEnum.Helvetica, true, false), 12);
            Composer.ShowText("Test Carried out on: " /*+ Clinician Details Input Get*/ + " on: " + date, new PointF(32, 80));

            //Convert Question Answers to Temporary Text
            string six_q1_txt = "Incorrect";
            string six_q2_txt = "Incorrect";
            string six_q3_txt = "Incorrect";
            string six_q4_txt = "Incorrect";
            string six_q5_txt = "Incorrect";
            string six_q6_txt;

            if (q1 == 0)
            {
                six_q1_txt = "Correct";
            }
            if (q2 == 0)
            {
                six_q2_txt = "Correct";
            }
            if (q3 == 0)
            {
                six_q3_txt = "Correct";
            }

            //Q4
            if (q4 == 0)
            {
                six_q4_txt = "Correct";
            }
            else if (q4 == 4)
            {
                six_q4_txt = "More Than One Incorrect";
            }

            //Q5
            if (q5 == 0)
            {
                six_q5_txt = "Correct";
            }
            else if (q5 == 2)
            {
                six_q5_txt = "One Incorrect";
            }
            else if (q5 == 4)
            {
                six_q5_txt = "More Than One Incorrect";
            }

            //Q6
            if (q6 == 0)
            {
                six_q6_txt = "Correct";
            }
            else if (q6 == 2)
            {
                six_q6_txt = "One Incorrect";
            }
            else if (q6 == 4)
            {
                six_q6_txt = "More Than One Incorrect";
            }
            else if (q6 == 6)
            {
                six_q6_txt = "More Than Two Incorrect";
            }
            else if (q6 == 8)
            {
                six_q6_txt = "More Than Three Incorrect";
            }
            else if (q6 == 10)
            {
                six_q6_txt = "More Than Four Incorrect";
            }
            else
            {
                six_q6_txt = "All Incorrect";
            }

            Composer.ShowText("Question 1: What Year Is It? : ", new PointF(32, 120));
            Composer.ShowText(six_q1_txt, new PointF(32, 140));

            Composer.ShowText("Question 2: What Month Is It? : ", new PointF(32, 180));
            Composer.ShowText(six_q2_txt, new PointF(32, 200));

            Composer.ShowText("Question 3: What Time Is It? : ", new PointF(32, 240));
            Composer.ShowText(six_q3_txt, new PointF(32, 260));

            Composer.ShowText("Question 4: Count Backwards From 20 to 1: ", new PointF(32, 300));
            Composer.ShowText(six_q4_txt, new PointF(32, 320));

            Composer.ShowText("Question 5: Say The Months of the Year Backwards: ", new PointF(32, 360));
            Composer.ShowText(six_q5_txt, new PointF(32, 380));

            Composer.ShowText("Question 6: Repeat the Memory Phrase: ", new PointF(32, 420));
            Composer.ShowText(six_q6_txt, new PointF(32, 440));

            Composer.ShowText("Test Result was:  " + score, new PointF(32, 480));
            Composer.ShowText("Advice: " + calcAdvice(score), new PointF(32, 500));

            Composer.Flush();

            if (saveFileDialog2.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    file.Save(saveFileDialog2.FileName, SerializationModeEnum.Incremental);
                }
                catch (IOException)
                {
                    MessageBox.Show("File is open somewhere else; Cannot Save to PDF.");
                }
            }
        }
        private void BuildTextBlockPage3(
            Document document
            )
        {
            // 1. Add the page to the document!
            Page page = new Page(document); // Instantiates the page inside the document context.

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

            SizeF pageSize = page.Size;

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

            // 3. Drawing the page contents...
            fonts::Font mainFont  = new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Courier, true, false);
            int         stepCount = 5;
            int         step      = (int)(pageSize.Height) / (stepCount + 1);

            // 3.1. Drawing the page title...
            BlockComposer blockComposer = new BlockComposer(composer);
            {
                blockComposer.Begin(
                    new RectangleF(
                        30,
                        0,
                        pageSize.Width - 60,
                        step * .8f
                        ),
                    XAlignmentEnum.Center,
                    YAlignmentEnum.Middle
                    );
                composer.SetFont(mainFont, 32);
                blockComposer.ShowText("Block line space");
                blockComposer.End();
            }

            // 3.2. Drawing the text blocks...
            fonts::Font sampleFont = new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Times, false, false);
            int         x          = 30;
            int         y          = (int)(step * 1.1);

            blockComposer.LineSpace.UnitMode = Length.UnitModeEnum.Relative;
            for (int index = 0; index < stepCount; index++)
            {
                float relativeLineSpace = 0.5f * index;
                blockComposer.LineSpace.Value = relativeLineSpace;

                composer.SetFont(mainFont, 12);
                composer.ShowText(
                    relativeLineSpace + ":",
                    new PointF(x, y),
                    XAlignmentEnum.Left,
                    YAlignmentEnum.Middle,
                    0
                    );

                composer.SetFont(sampleFont, 10);
                RectangleF frame = new RectangleF(150, y - step * .4f, 350, step * .9f);
                blockComposer.Begin(frame, XAlignmentEnum.Left, YAlignmentEnum.Top);
                blockComposer.ShowText("Demonstrating how to set the block line space. Line space can be expressed either as an absolute value (in user-space units) or as a relative one (floating-point ratio); in the latter case the base value is represented by the current font's line height (so that, for example, 2 means \"a line space that's twice as the line height\").");
                blockComposer.End();

                composer.BeginLocalState();
                {
                    composer.SetLineWidth(0.2);
                    composer.SetLineDash(new LineDash(new double[] { 5, 5 }, 5));
                    composer.DrawRectangle(frame);
                    composer.Stroke();
                }
                composer.End();

                y += step;
            }

            // 4. Flush the contents into the page!
            composer.Flush();
        }
        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();
        }
示例#39
0
        private void BuildTextBlockPage(
            Document document
            )
        {
            // 1. Add the page to the document!
              Page page = new Page(document); // Instantiates the page inside the document context.
              document.Pages.Add(page); // Puts the page in the pages collection.

              SizeF pageSize = page.Size;

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

              // 3. Drawing the page contents...
              fonts::Font mainFont = new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Courier, true, false);
              int step;
              {
            XAlignmentEnum[] xAlignments = (XAlignmentEnum[])Enum.GetValues(typeof(XAlignmentEnum));
            YAlignmentEnum[] yAlignments = (YAlignmentEnum[])Enum.GetValues(typeof(YAlignmentEnum));
            step = (int)(pageSize.Height) / (xAlignments.Length * yAlignments.Length+1);
              }
              BlockComposer blockComposer = new BlockComposer(composer);
              {
            blockComposer.Begin(
              new RectangleF(
            30,
            0,
            pageSize.Width-60,
            step*.8f
            ),
              XAlignmentEnum.Center,
              YAlignmentEnum.Middle
              );
            composer.SetFont(mainFont, 32);
            blockComposer.ShowText("Block alignment");
            blockComposer.End();
              }

              // Drawing the text blocks...
              fonts::Font sampleFont = new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Times, false, false);
              int x = 30;
              int y = (int)(step*1.2);
              foreach(XAlignmentEnum xAlignment in (XAlignmentEnum[])Enum.GetValues(typeof(XAlignmentEnum)))
              {
            foreach(YAlignmentEnum yAlignment in (YAlignmentEnum[])Enum.GetValues(typeof(YAlignmentEnum)))
            {
              composer.SetFont(mainFont, 12);
              composer.ShowText(
            xAlignment + " " + yAlignment + ":",
            new PointF(x,y),
            XAlignmentEnum.Left,
            YAlignmentEnum.Middle,
            0
            );

              composer.SetFont(sampleFont, 10);
              for(int index = 0; index < 2; index++)
              {
            int frameX;
            switch(index)
            {
              case 0:
                frameX = 150;
                blockComposer.Hyphenation = false;
                break;
              case 1:
                frameX = 360;
                blockComposer.Hyphenation = true;
                break;
              default:
                throw new Exception();
            }

            RectangleF frame = new RectangleF(
              frameX,
              y-step*.4f,
              200,
              step*.8f
              );
            blockComposer.Begin(frame,xAlignment,yAlignment);
            blockComposer.ShowText(
              "Demonstrating how to constrain text inside a page area using PDF Clown. See the other available code samples (such as TypesettingSample) to discover more functionality details."
              );
            blockComposer.End();

            composer.BeginLocalState();
            composer.SetLineWidth(0.2f);
            composer.SetLineDash(new LineDash(new double[]{5,5}, 5));
            composer.DrawRectangle(frame);
            composer.Stroke();
            composer.End();
              }

              y+=step;
            }
              }

              // 4. Flush the contents into the page!
              composer.Flush();
        }
示例#40
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(
                    new StandardType1Font(
                        document,
                        StandardType1Font.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;
        }
示例#41
0
        /**
          <summary>Populates a PDF file with contents.</summary>
        */
        private void Populate(
            Document document
            )
        {
            // 1. Add the page to the document!
              Page page = new Page(document); // Instantiates the page inside the document context.
              document.Pages.Add(page); // Puts the page in the pages collection.

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

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

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

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

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

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

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

            SizeF pageSize = page.Size;

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

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

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

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

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

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

            composer.Stroke();

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

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

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

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

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

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

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

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

                y += 30;
            }

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

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

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

            // 3.6. Clipping.

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

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

            // 4. Flush the contents into the page!
            composer.Flush();
        }
示例#43
0
        /**
         * <summary>Shows text.</summary>
         * <param name="text">Text to show.</param>
         * <param name="lineAlignment">Line alignment. It can be:
         *  <list type="bullet">
         *    <item><see cref="LineAlignmentEnum"/></item>
         *    <item><see cref="Length">: arbitrary super-/sub-script, depending on whether the value is
         *    positive or not.</item>
         *  </list>
         * </param>
         * <returns>Last shown character index.</returns>
         */
        public int ShowText(
            string text,
            object lineAlignment
            )
        {
            if (currentRow == null ||
                text == null)
            {
                return(0);
            }

            ContentScanner.GraphicsState state = baseComposer.State;
            fonts::Font font       = state.Font;
            double      fontSize   = state.FontSize;
            double      lineHeight = font.GetLineHeight(fontSize);
            double      baseLine   = font.GetAscent(fontSize);

            lineAlignment = ResolveLineAlignment(lineAlignment);

            TextFitter textFitter = new TextFitter(
                text,
                0,
                font,
                fontSize,
                hyphenation,
                hyphenationCharacter
                );
            int textLength = text.Length;
            int index      = 0;

            while (true)
            {
                if (currentRow.Width == 0) // Current row has just begun.
                {
                    // Removing leading space...
                    while (true)
                    {
                        if (index == textLength) // Text end reached.
                        {
                            goto endTextShowing;
                        }
                        else if (text[index] != ' ') // No more leading spaces.
                        {
                            break;
                        }

                        index++;
                    }
                }

                if (OperationUtils.Compare(currentRow.Y + lineHeight, frame.Height) == 1) // Text's height exceeds block's remaining vertical space.
                {
                    // Terminate the current row and exit!
                    EndRow(false);
                    goto endTextShowing;
                }

                // Does the text fit?
                if (textFitter.Fit(
                        index,
                        frame.Width - currentRow.Width, // Remaining row width.
                        currentRow.SpaceCount == 0
                        ))
                {
                    // Get the fitting text!
                    string textChunk         = textFitter.FittedText;
                    double textChunkWidth    = textFitter.FittedWidth;
                    PointF textChunkLocation = new PointF(
                        (float)currentRow.Width,
                        (float)currentRow.Y
                        );

                    // Insert the fitting text!
                    RowObject obj;
                    {
                        obj = new RowObject(
                            RowObject.TypeEnum.Text,
                            baseComposer.BeginLocalState(), // Opens the row object's local state.
                            lineHeight,
                            textChunkWidth,
                            CountOccurrence(' ', textChunk),
                            lineAlignment,
                            baseLine
                            );
                        baseComposer.ShowText(textChunk, textChunkLocation);
                        baseComposer.End(); // Closes the row object's local state.
                    }
                    AddRowObject(obj, lineAlignment);

                    index = textFitter.EndIndex;
                }

                // Evaluating trailing text...
                while (true)
                {
                    if (index == textLength) // Text end reached.
                    {
                        goto endTextShowing;
                    }

                    switch (text[index])
                    {
                    case '\r':
                        break;

                    case '\n':
                        // New paragraph!
                        index++;
                        ShowBreak();
                        goto endTrailParsing;

                    default:
                        // New row (within the same paragraph)!
                        EndRow(false);
                        BeginRow();
                        goto endTrailParsing;
                    }

                    index++;
                }
                endTrailParsing :;
            }
            endTextShowing :;
            if (index >= 0 &&
                lineAlignment.Equals(LineAlignmentEnum.BaseLine))
            {
                lastFontSize = fontSize;
            }

            return(index);
        }
        private void BuildTextBlockPage(
            Document document
            )
        {
            // 1. Add the page to the document!
            Page page = new Page(document); // Instantiates the page inside the document context.

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

            SizeF pageSize = page.Size;

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

            // 3. Drawing the page contents...
            fonts::Font mainFont = new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Courier, true, false);
            int         step;
            {
                XAlignmentEnum[] xAlignments = (XAlignmentEnum[])Enum.GetValues(typeof(XAlignmentEnum));
                YAlignmentEnum[] yAlignments = (YAlignmentEnum[])Enum.GetValues(typeof(YAlignmentEnum));
                step = (int)(pageSize.Height) / (xAlignments.Length * yAlignments.Length + 1);
            }
            BlockComposer blockComposer = new BlockComposer(composer);
            {
                blockComposer.Begin(
                    new RectangleF(
                        30,
                        0,
                        pageSize.Width - 60,
                        step * .8f
                        ),
                    XAlignmentEnum.Center,
                    YAlignmentEnum.Middle
                    );
                composer.SetFont(mainFont, 32);
                blockComposer.ShowText("Block alignment");
                blockComposer.End();
            }

            // Drawing the text blocks...
            fonts::Font sampleFont = new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Times, false, false);
            int         x          = 30;
            int         y          = (int)(step * 1.2);

            foreach (XAlignmentEnum xAlignment in (XAlignmentEnum[])Enum.GetValues(typeof(XAlignmentEnum)))
            {
                foreach (YAlignmentEnum yAlignment in (YAlignmentEnum[])Enum.GetValues(typeof(YAlignmentEnum)))
                {
                    composer.SetFont(mainFont, 12);
                    composer.ShowText(
                        xAlignment + " " + yAlignment + ":",
                        new PointF(x, y),
                        XAlignmentEnum.Left,
                        YAlignmentEnum.Middle,
                        0
                        );

                    composer.SetFont(sampleFont, 10);
                    for (int index = 0; index < 2; index++)
                    {
                        int frameX;
                        switch (index)
                        {
                        case 0:
                            frameX = 150;
                            blockComposer.Hyphenation = false;
                            break;

                        case 1:
                            frameX = 360;
                            blockComposer.Hyphenation = true;
                            break;

                        default:
                            throw new Exception();
                        }

                        RectangleF frame = new RectangleF(
                            frameX,
                            y - step * .4f,
                            200,
                            step * .8f
                            );
                        blockComposer.Begin(frame, xAlignment, yAlignment);
                        blockComposer.ShowText(
                            "Demonstrating how to constrain text inside a page area using PDF Clown. See the other available code samples (such as TypesettingSample) to discover more functionality details."
                            );
                        blockComposer.End();

                        composer.BeginLocalState();
                        composer.SetLineWidth(0.2f);
                        composer.SetLineDash(new LineDash(new double[] { 5, 5 }, 5));
                        composer.DrawRectangle(frame);
                        composer.Stroke();
                        composer.End();
                    }

                    y += step;
                }
            }

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

              Appearance appearance = widget.Appearance;
              if(appearance == null)
              {widget.Appearance = appearance = new Appearance(document);}

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

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

            float lineWidth = 1;
            RectangleF frame = new RectangleF(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(
              new StandardType1Font(
            document,
            StandardType1Font.FamilyEnum.Helvetica,
            false,
            false
            ),
              FontSize
              );
            composer.ShowText(
              (string)field.Value,
              new PointF(0,size.Height/2),
              XAlignmentEnum.Left,
              YAlignmentEnum.Middle,
              0
              );
            composer.End();

            composer.Flush();
              }
              appearance.Normal[null] = normalAppearanceState;
        }
示例#46
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(
            new StandardType1Font(
              document,
              StandardType1Font.FamilyEnum.Courier,
              true,
              false
              ),
            14
            );

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

            Widget fieldWidget = new Widget(
              page,
              new RectangleF(150, 50, 136, 36)
              );
            WidgetActions fieldWidgetActions = new WidgetActions(fieldWidget);
            fieldWidget.Actions = fieldWidgetActions;
            fieldWidgetActions.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(new RectangleF(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 PointF(140, 118),
              XAlignmentEnum.Right,
              YAlignmentEnum.Middle,
              0
              );
            CheckBox field = new CheckBox(
              "myCheck",
              new Widget(
            page,
            new RectangleF(150, 100, 36, 36)
            ),
              true // Current value.
              ); // 4.1. Field instantiation.
            fieldStyle.Apply(field);
            fields.Add(field);
            field = new CheckBox(
              "myCheck2",
              new Widget(
            page,
            new RectangleF(200, 100, 36, 36)
            ),
              true // Current value.
              ); // 4.1. Field instantiation.
            fieldStyle.Apply(field);
            fields.Add(field);
            field = new CheckBox(
              "myCheck3",
              new Widget(
            page,
            new RectangleF(250, 100, 36, 36)
            ),
              false // 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.
              }

              // 4.c. Radio button.
              {
            composer.ShowText(
              "RadioButton:",
              new PointF(140, 168),
              XAlignmentEnum.Right,
              YAlignmentEnum.Middle,
              0
              );
            RadioButton field = new RadioButton(
              "myRadio",
              /*
            NOTE: A radio button field typically combines multiple alternative widgets.
              */
              new DualWidget[]
              {
            new DualWidget(
              page,
              new RectangleF(150, 150, 36, 36),
              "first"
              ),
            new DualWidget(
              page,
              new RectangleF(200, 150, 36, 36),
              "second"
              ),
            new DualWidget(
              page,
              new RectangleF(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 PointF(140, 218),
              XAlignmentEnum.Right,
              YAlignmentEnum.Middle,
              0
              );
            TextField field = new TextField(
              "myText",
              new Widget(
            page,
            new RectangleF(150, 200, 200, 36)
            ),
              "Carmen Consoli" // Current value.
              ); // 4.1. Field instantiation.
            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(new RectangleF(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 PointF(140, 268),
            XAlignmentEnum.Right,
            YAlignmentEnum.Middle,
            0
            );
              ListBox field = new ListBox(
            "myList",
            new Widget(
              page,
              new RectangleF(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 PointF(140, 350),
            XAlignmentEnum.Right,
            YAlignmentEnum.Middle,
            0
            );
              ComboBox field = new ComboBox(
            "myCombo",
            new Widget(
              page,
              new RectangleF(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();
        }
示例#47
0
        private void Apply(
      ListBox field
      )
        {
            Document document = field.Document;
              Widget widget = field.Widgets[0];

              Appearance appearance = widget.Appearance;
              if(appearance == null)
              {widget.Appearance = appearance = new Appearance(document);}

              {
            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;
              {
            SizeF size = widget.Box.Size;
            normalAppearanceState = new FormXObject(document, size);
            PrimitiveComposer composer = new PrimitiveComposer(normalAppearanceState);

            float lineWidth = 1;
            RectangleF frame = new RectangleF(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(
              new StandardType1Font(
            document,
            StandardType1Font.FamilyEnum.Helvetica,
            false,
            false
            ),
              FontSize
              );
            double y = 3;
            foreach(ChoiceItem item in field.Items)
            {
              composer.ShowText(
            item.Text,
            new PointF(0, (float)y)
            );
              y += FontSize * 1.175;
              if(y > size.Height)
            break;
            }
            composer.End();
            composer.End();

            composer.Flush();
              }
              appearance.Normal[null] = normalAppearanceState;
        }
示例#48
0
        public override ContentObject ToInlineObject(PrimitiveComposer composer)
        {
            ContentObject barcodeObject = composer.BeginLocalState();

            {
                fonts::Font font     = fonts::PdfType1Font.Load(composer.Scanner.Contents.Document, fonts::PdfType1Font.FamilyEnum.Helvetica, false, false);
                double      fontSize = (DigitGlyphWidth / font.GetWidth(code.Substring(0, 1), 1));

                // 1. Bars.
                {
                    double elementX      = DigitWidth;
                    int[]  elementWidths = GetElementWidths();

                    double guardBarIndentY = DigitHeight / 2;
                    bool   isBar           = true;
                    for (int elementIndex = 0; elementIndex < elementWidths.Length; elementIndex++)
                    {
                        double elementWidth = elementWidths[elementIndex];
                        // Dark element?

                        /*
                         * NOTE: EAN symbol elements alternate bars to spaces.
                         */
                        if (isBar)
                        {
                            composer.DrawRectangle(
                                SKRect.Create(
                                    (float)elementX,
                                    0,
                                    (float)elementWidth,
                                    (float)(BarHeight + (
                                                // Guard bar?
                                                Array.BinarySearch <int>(GuardBarIndexes, elementIndex) >= 0
                                    ? guardBarIndentY // Guard bar.
                                    : 0               // Symbol character.
                                                ))
                                    )
                                );
                        }

                        elementX += elementWidth;
                        isBar     = !isBar;
                    }
                    composer.Fill();
                }

                // 2. Digits.
                {
                    composer.SetFont(font, fontSize);
                    double digitY = BarHeight + (DigitHeight - (font.GetAscent(fontSize))) / 2;
                    // Showing the digits...
                    for (int digitIndex = 0; digitIndex < 13; digitIndex++)
                    {
                        string digit = code.Substring(digitIndex, 1);
                        double pX    = DigitGlyphXs[digitIndex]              // Digit position.
                                       - font.GetWidth(digit, fontSize) / 2; // Centering.
                                                                             // Show the current digit!
                        composer.ShowText(
                            digit,
                            new SKPoint((float)pX, (float)digitY)
                            );
                    }
                }
                composer.End();
            }
            return(barcodeObject);
        }
示例#49
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;
        }