Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
0
        private void PrintDescricaoDanfe(RectangleF area, BlockComposer bComp, PrimitiveComposer comp)
        {
            comp.SafeDrawRectangle(area);

            // Retangulo com padding
            RectangleF pRet = area.GetPaddedRectangleMm(1);

            // DANFE e descrição
            bComp.SafeBegin(pRet, XAlignmentEnum.Center, YAlignmentEnum.Top);
            comp.SetFont(Danfe.FontBold, 12);
            bComp.ShowText("DANFE");
            comp.SetFont(Danfe.Font, 6);
            bComp.ShowBreak(new SizeF(0, 1));
            bComp.ShowText(DescricaoDanfe);
            bComp.End();

            // Entrada, Saída
            RectangleF rEntrasaSaida = new RectangleF(pRet.X, bComp.BoundBox.Bottom + Utils.Mm2Pu(1.5F), pRet.Width, pRet.Bottom - bComp.BoundBox.Bottom);

            rEntrasaSaida = rEntrasaSaida.GetPaddedRectangleMm(0, 2.5F);

            comp.SetFont(Danfe.Font, 8);
            bComp.SafeBegin(rEntrasaSaida, XAlignmentEnum.Left, YAlignmentEnum.Top);
            bComp.ShowText("0 - Entrada\n1 - Saída");
            bComp.End();

            RectangleF rEntrasaSaida2 = bComp.BoundBox;

            rEntrasaSaida2 = new RectangleF(rEntrasaSaida.Right - bComp.BoundBox.Height, bComp.BoundBox.Y, bComp.BoundBox.Height, bComp.BoundBox.Height);
            comp.SafeDrawRectangle(rEntrasaSaida2);

            bComp.SafeBegin(rEntrasaSaida2, XAlignmentEnum.Center, YAlignmentEnum.Middle);
            bComp.ShowText(Danfe.Model.TipoNF.ToString());
            bComp.End();



            // Número Série e Folha
            RectangleF retEsquerdo = pRet;

            retEsquerdo.Width = Utils.Mm2Pu(8);

            RectangleF retDireito = pRet;

            retDireito.X     = retEsquerdo.Right + Utils.Mm2Pu(1);
            retDireito.Width = pRet.Right - retDireito.Left;

            RetanguloFolha     = retDireito;
            retDireito.Height -= (float)Danfe.FontBold.GetLineHeight(TamanhoFonteNumeracao);

            comp.SetFont(Danfe.FontBold, TamanhoFonteNumeracao);
            bComp.SafeBegin(retEsquerdo, XAlignmentEnum.Right, YAlignmentEnum.Bottom);
            bComp.ShowText("Nº\nSérie\nFolha");
            bComp.End();

            bComp.SafeBegin(retDireito, XAlignmentEnum.Left, YAlignmentEnum.Bottom);
            bComp.ShowText(String.Format("{0}\n{1}", Danfe.Model.NumeroNF.ToString(Formatador.FormatoNumeroNF), Danfe.Model.Serie));
            bComp.End();
        }
Exemplo n.º 3
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();
        }
        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;
        }
Exemplo n.º 5
0
        private void Populate(Document document)
        {
            PdfType1Font bodyFont = PdfType1Font.Load(document, PdfType1Font.FamilyEnum.Courier, true, false);

            Pages pages = document.Pages;

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

                    // Drawing the text label on the page...
                    SKSize            pageSize = page.Size;
                    PrimitiveComposer composer = new PrimitiveComposer(page);
                    composer.SetFont(bodyFont, 32);
                    composer.ShowText(
                        pageFormat + " (" + pageOrientation + ")", // Text.
                        new SKPoint(
                            pageSize.Width / 2,
                            pageSize.Height / 2
                            ),                 // Location: page center.
                        XAlignmentEnum.Center, // Places the text on horizontal center of the location.
                        YAlignmentEnum.Middle, // Places the text on vertical middle of the location.
                        45                     // Rotates the text 45 degrees counterclockwise.
                        );
                    composer.Flush();
                }
            }
        }
Exemplo n.º 6
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();
        }
Exemplo n.º 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);
        }
Exemplo n.º 8
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();
        }
Exemplo n.º 9
0
        public BlocoProdutoServicoTotalNFC(DanfeViewModel viewModel, Estilo estilo, PrimitiveComposer primitiveComposer, float y) : base(estilo)
        {
            primitiveComposer.BeginLocalState();

            primitiveComposer.SetFont(estilo.FonteCampoConteudo.FonteInterna, estilo.FonteCampoConteudo.Tamanho);
            primitiveComposer.ShowText("QNT. TOTAL DE ITENS", new PointF(25, y + 10), XAlignmentEnum.Left, YAlignmentEnum.Middle, 0);
            primitiveComposer.ShowText(viewModel.CalculoImposto.QuantidadeTotal.ToString(), new PointF(250, y + 10), XAlignmentEnum.Right, YAlignmentEnum.Middle, 0);

            primitiveComposer.ShowText("VALOR DOS PRODUTOS", new PointF(25, y + 20), XAlignmentEnum.Left, YAlignmentEnum.Middle, 0);
            primitiveComposer.ShowText(viewModel.CalculoImposto.ValorTotalProdutos.Formatar(), new PointF(250, y + 20), XAlignmentEnum.Right, YAlignmentEnum.Middle, 0);

            //if (viewModel.CalculoImposto.ValorFrete > 0)
            //{
            primitiveComposer.ShowText("Valor do Frete", new PointF(25, y + 30), XAlignmentEnum.Left, YAlignmentEnum.Middle, 0);
            primitiveComposer.ShowText(viewModel.CalculoImposto.ValorFrete.Formatar(), new PointF(250, y + 30), XAlignmentEnum.Right, YAlignmentEnum.Middle, 0);
            //}

            //if (viewModel.CalculoImposto.ValorSeguro > 0)
            //{
            primitiveComposer.ShowText("Valor do Seguro", new PointF(25, y + 40), XAlignmentEnum.Left, YAlignmentEnum.Middle, 0);
            primitiveComposer.ShowText(viewModel.CalculoImposto.ValorSeguro.Formatar(), new PointF(250, y + 40), XAlignmentEnum.Right, YAlignmentEnum.Middle, 0);
            //}

            //if (viewModel.CalculoImposto.OutrasDespesas > 0)
            //{
            primitiveComposer.ShowText("OUTRAS DESPESAS", new PointF(25, y + 50), XAlignmentEnum.Left, YAlignmentEnum.Middle, 0);
            primitiveComposer.ShowText(viewModel.CalculoImposto.OutrasDespesas.Formatar(), new PointF(250, y + 50), XAlignmentEnum.Right, YAlignmentEnum.Middle, 0);
            //}

            //if (viewModel.CalculoImposto.Desconto > 0)
            //{
            primitiveComposer.ShowText("DESCONTO (-)", new PointF(25, y + 60), XAlignmentEnum.Left, YAlignmentEnum.Middle, 0);
            primitiveComposer.ShowText(viewModel.CalculoImposto.Desconto.Formatar(), new PointF(250, y + 60), XAlignmentEnum.Right, YAlignmentEnum.Middle, 0);
            //}

            primitiveComposer.SetFont(estilo.FonteCampoTituloNegrito.FonteInterna, estilo.FonteCampoTituloNegrito.Tamanho);
            primitiveComposer.ShowText("VALOR TOTAL", new PointF(25, y + 70), XAlignmentEnum.Left, YAlignmentEnum.Middle, 0);
            primitiveComposer.ShowText(viewModel.CalculoImposto.ValorTotalNota.Formatar(), new PointF(250, y + 70), XAlignmentEnum.Right, YAlignmentEnum.Middle, 0);

            Y_NFC = y + 80;

            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();
        }
Exemplo n.º 10
0
        private void Populate(
            Document document
            )
        {
            Page page = new Page(document);

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

            PrimitiveComposer composer = new PrimitiveComposer(page);

            {
                BlockComposer blockComposer = new BlockComposer(composer);
                blockComposer.Hyphenation = true;
                blockComposer.Begin(
                    new RectangleF(
                        Margin,
                        Margin,
                        (float)pageSize.Width - Margin * 2,
                        (float)pageSize.Height - Margin * 2
                        ),
                    XAlignmentEnum.Justify,
                    YAlignmentEnum.Top
                    );
                StandardType1Font bodyFont = new StandardType1Font(
                    document,
                    StandardType1Font.FamilyEnum.Courier,
                    true,
                    false
                    );
                composer.SetFont(bodyFont, 32);
                blockComposer.ShowText("Inline image sample"); blockComposer.ShowBreak();
                composer.SetFont(bodyFont, 16);
                blockComposer.ShowText("Showing the GNU logo as an inline image within the page content stream.");
                blockComposer.End();
            }
            // Showing the 'GNU' image...
            {
                // Instantiate a jpeg image object!
                entities::Image image = entities::Image.Get(GetResourcePath("images" + Path.DirectorySeparatorChar + "gnu.jpg")); // Abstract image (entity).
                // Set the position of the image in the page!
                composer.ApplyMatrix(200, 0, 0, 200, (pageSize.Width - 200) / 2, (pageSize.Height - 200) / 2);
                // Show the image!
                image.ToInlineObject(composer); // Transforms the image entity into an inline image within the page.
            }
            composer.Flush();
        }
Exemplo n.º 11
0
        protected override void ToXObjectInternal(PrimitiveComposer comp)
        {
            var duplicatas = Danfe.Model.Duplicatas;

            BlockComposer bComp = new BlockComposer(comp);

            RectangleF r1 = InternalRectangle;

            r1.Height = RetanguloH;

            RectangleF[] colunas     = r1.SplitRectangle(Colunas);
            int          colunaIndex = 0;


            for (int i = 0; i < duplicatas.Count; i++)
            {
                if (i > 0 && i % Colunas == 0)
                {
                    colunaIndex = 0;

                    for (int i2 = 0; i2 < Colunas; i2++)
                    {
                        colunas[i2].Y += RetanguloH;
                    }
                }

                var        duplicata = duplicatas[i];
                RectangleF pRet      = colunas[colunaIndex].GetPaddedRectangleMm(1);
                comp.SetFont(Danfe.Font, 6);
                bComp.SafeBegin(pRet, XAlignmentEnum.Left, YAlignmentEnum.Middle);
                bComp.ShowText("Número:\nVenc.:\nValor:\n");
                bComp.End();


                comp.SetFont(Danfe.FontBold, 6);

                bComp.SafeBegin(pRet, XAlignmentEnum.Right, YAlignmentEnum.Middle);
                bComp.ShowText(String.Format("{0}\n{1}\n{2}\n", duplicata.Numero, duplicata.Vecimento.Formatar(), duplicata.Valor.Formatar()));
                bComp.End();

                comp.SafeDrawRectangle(colunas[colunaIndex]);

                colunaIndex++;
            }

            comp.Stroke();
        }
Exemplo n.º 12
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;
        }
        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();
            }
        }
Exemplo n.º 14
0
        private void Populate(
            Document document
            )
        {
            Page page = new Page(document);
              document.Pages.Add(page);
              SizeF pageSize = page.Size;

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

            Appearance appearance = widget.Appearance;

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

            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();
                }

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

                composer.Flush();
            }
            appearance.Normal[null] = normalAppearanceState;
        }
Exemplo n.º 16
0
        protected override void ToXObjectInternal(PrimitiveComposer composer)
        {
            EmpresaViewModel empresa = null;

            if (Danfe.Model.TipoNF == 1)
            {
                empresa = Danfe.Model.Emitente;
            }
            else if (Danfe.Model.TipoNF == 0)
            {
                empresa = Danfe.Model.Destinatario;
            }
            else
            {
                throw new Exception("Tipo de NF não suportado.");
            }

            BlockComposer bComp = new BlockComposer(composer);

            composer.SafeDrawRectangle(RetNumeracao);
            composer.SafeDrawRectangle(RetRecebemos);

            composer.SetFont(Danfe.Font, 6);
            bComp.SafeBegin(RetRecebemos.GetPaddedRectangleMm(1), XAlignmentEnum.Left, YAlignmentEnum.Middle);
            bComp.ShowText(String.Format("RECEBEMOS DE {0} OS PRODUTOS E/OU SERVIÇOS CONSTANTES DA NOTA FISCAL ELETRÔNICA INDICADA ABAIXO.", empresa.Nome));
            bComp.End();

            // Numeração da NFe
            composer.SafeDrawRectangle(RetNumeracao);
            composer.SetFont(Danfe.FontBold, 12);
            bComp.SafeBegin(RetNumeracao, XAlignmentEnum.Center, YAlignmentEnum.Middle);
            bComp.ShowText(String.Format("NF-e\nNº {0}\nSérie {1}", Danfe.Model.NumeroNF.ToString(Formatador.FormatoNumeroNF), Danfe.Model.Serie));
            bComp.End();

            composer.Stroke();

            // Linha pontilhada
            composer.BeginLocalState();
            composer.SetLineDash(new org.pdfclown.documents.contents.LineDash(new double[] { 3, 2 }));
            composer.DrawLine(new PointF(InternalRectangle.Left, Size.Height - MargemLinhaPontilhada), new PointF(InternalRectangle.Right, Size.Height - MargemLinhaPontilhada));
            composer.Stroke();
            composer.End();
        }
Exemplo n.º 17
0
        /// <summary>
        /// Imprime o campo no composer.
        /// </summary>
        /// <param name="comp"></param>
        public void Print(PrimitiveComposer comp, org.pdfclown.documents.contents.fonts.Font fonte, org.pdfclown.documents.contents.fonts.Font fonteBold)
        {
            BlockComposer bComp = new BlockComposer(comp);
            RectangleF    pRect = Retangulo.GetPaddedRectangle(PaddingHorizontal, PaddingHorizontal, PaddingSuperior, PaddingInferior);

            comp.SetFont(fonteBold, TamanhoFonteCabecalho);
            ValidadeRectangle(pRect, comp);
            bComp.SafeBegin(pRect, XAlignmentEnum.Left, YAlignmentEnum.Top);
            bComp.ShowText(Cabecalho.ToUpper());
            bComp.End();

            bComp.LineSpace = new Length(LineSpace, Length.UnitModeEnum.Absolute);

            if (!String.IsNullOrWhiteSpace(Corpo))
            {
                org.pdfclown.documents.contents.fonts.Font fonteCorpo = IsCorpoNegrito ? fonteBold : fonte;

                double largura     = fonteCorpo.GetWidth(Corpo, CorpoTamanhoFonte);
                double novoTamanho = CorpoTamanhoFonte;

                if (!MultiLinha && largura > pRect.Width)
                {
                    novoTamanho = (CorpoTamanhoFonte * pRect.Width) / largura - Utils.Mm2Pu(0.005F);
                    comp.SetFont(fonteCorpo, novoTamanho);
                }

                comp.SetFont(fonteCorpo, novoTamanho);

                if (CorpoAlinhamentoY == YAlignmentEnum.Top)
                {
                    float yOffSet = (float)fonteBold.GetLineHeight(TamanhoFonteCabecalho) + LineSpace;
                    pRect.Y      += yOffSet;
                    pRect.Height -= yOffSet;
                }

                ValidadeRectangle(pRect, comp);
                bComp.SafeBegin(pRect, CorpoAlinhamentoX, CorpoAlinhamentoY);
                bComp.ShowText(Corpo);
                bComp.End();
            }

            comp.SafeDrawRectangle(Retangulo);
        }
Exemplo n.º 18
0
        private void PrintIdentificacaoEmitente(RectangleF area, BlockComposer bComp, PrimitiveComposer comp)
        {
            comp.SafeDrawRectangle(area);

            // Retângulo com padding
            RectangleF pRet = area.GetPaddedRectangleMm(1);

            var emitente = Danfe.Model.Emitente;

            var yAlign = Danfe.PossuiLogo ? YAlignmentEnum.Bottom : YAlignmentEnum.Middle;

            bComp.SafeBegin(pRet, XAlignmentEnum.Left, yAlign);

            double bestSize = DanfeCampo.AjustarFonte(emitente.Nome, Danfe.FontBold, pRet.Width, Danfe.PossuiLogo ? 10 : 12);

            comp.SetFont(Danfe.FontBold, bestSize);

            bComp.ShowText(emitente.Nome);
            bComp.ShowBreak();
            comp.SetFont(Danfe.Font, Danfe.PossuiLogo ? 7 : 8);
            bComp.ShowText(emitente.EnderecoLinha1);
            bComp.ShowBreak();
            bComp.ShowText(emitente.EnderecoBairro);
            bComp.ShowBreak();
            bComp.ShowText(emitente.EnderecoLinha3);

            if (!String.IsNullOrWhiteSpace(emitente.Telefone))
            {
                bComp.ShowBreak();
                bComp.ShowText(String.Format("Fone: {0}", Formatador.FormatarTelefone(emitente.Telefone)));
            }

            bComp.End();

            if (Danfe.PossuiLogo)
            {
                RectangleF logoRectangle = area;
                logoRectangle.Height = bComp.BoundBox.Top - logoRectangle.Y;
                PrintLogo(comp, logoRectangle);
            }
        }
Exemplo n.º 19
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();
            }
        }
        /**
         * <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();
        }
Exemplo n.º 21
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();
        }
Exemplo n.º 22
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();
        }
Exemplo n.º 23
0
        /// <summary>
        /// Imprime o cabeçalho do bloco.
        /// </summary>
        private void PrintCabecalho(PrimitiveComposer comp)
        {
            BlockComposer bComp = new BlockComposer(comp);

            RectangleF rect = new RectangleF(0, 0, Size.Width, Danfe.CabecalhoBlocoAltura);

            rect = rect.GetPaddedRectangleMm(0, 0, 1, 0.3F);

            comp.SetFont(Danfe.FontBold, 5);
            bComp.SafeBegin(rect, XAlignmentEnum.Left, YAlignmentEnum.Bottom);
            bComp.ShowText(Cabecalho.ToUpper());
            bComp.End();

            comp.Flush();
        }
        public void PrintCabecalhos(PrimitiveComposer composer)
        {
            BlockComposer bComp = new BlockComposer(composer);
            composer.SetFont(_Documento.FontBold, 5);

            for (int i = 0; i < _Colunas.Length; i++)
            {
                RectangleF r = _Colunas[i].Retangulo;
                r.Height = AlturaCabecalhoTabela;
                bComp.SafeBegin(r.GetPaddedRectangle(Margem), _Colunas[i].AlinhamentoHorizontal, YAlignmentEnum.Middle);
                bComp.ShowText(_Colunas[i].Cabecalho.ToUpper());
                bComp.End();

                composer.SafeDrawRectangle(r);
            }
        }
Exemplo n.º 25
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();
        }
Exemplo n.º 26
0
        public void PrintCabecalhos(PrimitiveComposer composer)
        {
            BlockComposer bComp = new BlockComposer(composer);

            composer.SetFont(_Documento.FontBold, 5);

            for (int i = 0; i < _Colunas.Length; i++)
            {
                RectangleF r = _Colunas[i].Retangulo;
                r.Height = AlturaCabecalhoTabela;
                bComp.SafeBegin(r.GetPaddedRectangle(Margem), _Colunas[i].AlinhamentoHorizontal, YAlignmentEnum.Middle);
                bComp.ShowText(_Colunas[i].Cabecalho.ToUpper());
                bComp.End();

                composer.SafeDrawRectangle(r);
            }
        }
Exemplo n.º 27
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();
            }
              }
        }
Exemplo n.º 28
0
        protected override void ToXObjectInternal(PrimitiveComposer comp)
        {
            var duplicatas = Danfe.Model.Duplicatas;

            BlockComposer bComp = new BlockComposer(comp);

            RectangleF r1 = InternalRectangle;
            r1.Height = RetanguloH;

            RectangleF[] colunas = r1.SplitRectangle(Colunas);
            int colunaIndex = 0;

            for (int i = 0; i < duplicatas.Count; i++)
            {

                if (i > 0 && i % Colunas == 0)
                {
                    colunaIndex = 0;

                    for (int i2 = 0; i2 < Colunas; i2++)
                    {
                        colunas[i2].Y += RetanguloH;
                    }
                }

                var duplicata = duplicatas[i];
                RectangleF pRet = colunas[colunaIndex].GetPaddedRectangleMm(1);
                comp.SetFont(Danfe.Font, 6);
                bComp.SafeBegin(pRet, XAlignmentEnum.Left, YAlignmentEnum.Middle);
                bComp.ShowText("Número:\nVenc.:\nValor:\n");
                bComp.End();

                comp.SetFont(Danfe.FontBold, 6);

                bComp.SafeBegin(pRet, XAlignmentEnum.Right, YAlignmentEnum.Middle);
                bComp.ShowText(String.Format("{0}\n{1}\n{2}\n", duplicata.Numero, duplicata.Vecimento.Formatar(), duplicata.Valor.Formatar()));
                bComp.End();

                comp.SafeDrawRectangle(colunas[colunaIndex]);

                colunaIndex++;
            }

            comp.Stroke();
        }
Exemplo n.º 29
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;
            }
        }
Exemplo n.º 30
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();
        }
Exemplo n.º 31
0
        protected override void ToXObjectInternal(PrimitiveComposer comp)
        {
            BlockComposer bComp = new BlockComposer(comp);

            PrintIdentificacaoEmitente(RetEmitente, bComp, comp);
            PrintDescricaoDanfe(RetDescDanfe, bComp, comp);

            var emitente = Danfe.Model.Emitente;

            comp.SafeDrawRectangle(RetCodigoBarras);
            comp.SafeDrawRectangle(RetCampoVariavel);

            comp.SetFont(Danfe.Font, 8);
            bComp.SafeBegin(RetCampoVariavel, XAlignmentEnum.Center, YAlignmentEnum.Middle);
            bComp.ShowText(MensagemConsulta);
            bComp.End();

            comp.Stroke();

            var barcode = new Barcode128C(Danfe.Model.ChaveAcesso, RetCodigoBarras.Size).ToXObject(Danfe.Document);

            comp.ShowXObject(barcode, new PointF(RetCodigoBarras.X, RetCodigoBarras.Y));
        }
Exemplo n.º 32
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();
        }
Exemplo n.º 33
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();
        }
Exemplo n.º 34
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.1. Create a content composer for the page!
              PrimitiveComposer composer = new PrimitiveComposer(page);

              // 2.2. Create a block composer!
              BlockComposer blockComposer = new BlockComposer(composer);

              // 3. Inserting contents...
              // Define the font to use!
              fonts::Font font = fonts::Font.Get(
            document,
            GetResourcePath("fonts" + Path.DirectorySeparatorChar + "GenR102.TTF")
            );
              // Define the paragraph break size!
              Size breakSize = new Size(0,10);
              // Define the text to show!
              string[] titles = new string[]
            {
              "ΑΡΘΡΟ 1",
              "ASARIYA SINTE (1)",
              "Article 1",
              "Article premier",
              "Статья 1",
              "Artículo 1",
              "Artikel 1",
              "Madde 1",
              "Artikel 1",
              "Articolo 1",
              "Artykuł 1",
              "Bend 1",
              "Abala kìíní."
            };
              string[] bodies = new string[]
            {
              "'Ολοι οι άνθρωποι γεννιούνται ελεύθεροι και ίσοι στην αξιοπρέπεια και τα δικαιώματα. Είναι προικισμένοι με λογική και συνείδηση, και οφείλουν να συμπεριφέρονται μεταξύ τους με πνεύμα αδελφοσύνης.",
              "Aduniya kuna n gu ibuna damayo hɛi nɔ dei-dei nn daama nna n burucinitɛrɛ fɔ, n lasabu nna laakari ya nam nn mɔ huro cɛrɛ kuna nyanze tɛrɛ bɔŋɔɔ.",
              "All human beings are born free and equal in dignity and rights. They are endowed with reason and conscience and should act towards one another in a spirit of brotherhood.",
              "Tous les êtres humains naissent libres et égaux en dignité et en droits. Ils sont doués de raison et de conscience et doivent agir les uns envers les autres dans un esprit de fraternité.",
              "Все люди рождаются свободными и равными в своем достоинстве и правах. Они наделены разумом и совестью и должны поступать в отношении друг друга в духе братства.",
              "Todos los seres humanos nacen libres e iguales en dignidad y derechos y, dotados como están de razón y conciencia, deben comportarse fraternalmente los unos con los otros.",
              "Alle Menschen sind frei und gleich an Würde und Rechten geboren. Sie sind mit Vernunft und Gewissen begabt und sollen einander im Geist der Brüderlichkeit begegnen.",
              "Bütün insanlar hür, haysiyet ve haklar bakımından eşit doğarlar. Akıl ve vicdana sahiptirler ve birbirlerine karşı kardeşlik zihniyeti ile hareket etmelidirler.",
              "Alla människor är födda fria och lika i värde och rättigheter. De har utrustats med förnuft och samvete och bör handla gentemot varandra i en anda av gemenskap.",
              "Tutti gli esseri umani nascono liberi ed eguali in dignità e diritti. Essi sono dotati di ragione e di coscienza e devono agire gli uni verso gli altri in spirito di fratellanza.",
              "Wszyscy ludzie rodzą się wolni i równi pod względem swej godności i swych praw. Są oni obdarzeni rozumem i sumieniem i powinni postępować wobec innych w duchu braterstwa.",
              "Hemû mirov azad û di weqar û mafan de wekhev tên dinyayê. Ew xwedî hiş û şuûr in û divê li hember hev bi zihniyeteke bratiyê bilivin.",
              "Gbogbo ènìyàn ni a bí ní òmìnira; iyì àti è̟tó̟ kò̟ò̟kan sì dó̟gba. Wó̟n ní è̟bùn ti làákàyè àti ti è̟rí-o̟kàn, ó sì ye̟ kí wo̟n ó máa hùwà sí ara wo̟n gé̟gé̟ bí o̟mo̟ ìyá."
            };
              string[] sources = new string[]
              {
            "http://www.ohchr.org/EN/UDHR/Pages/Language.aspx?LangID=grk",
            "http://www.ohchr.org/EN/UDHR/Pages/Language.aspx?LangID=den",
            "http://www.ohchr.org/EN/UDHR/Pages/Language.aspx?LangID=eng",
            "http://www.ohchr.org/EN/UDHR/Pages/Language.aspx?LangID=frn",
            "http://www.ohchr.org/EN/UDHR/Pages/Language.aspx?LangID=rus",
            "http://www.ohchr.org/EN/UDHR/Pages/Language.aspx?LangID=spn",
            "http://www.ohchr.org/EN/UDHR/Pages/Language.aspx?LangID=ger",
            "http://www.ohchr.org/EN/UDHR/Pages/Language.aspx?LangID=trk",
            "http://www.ohchr.org/EN/UDHR/Pages/Language.aspx?LangID=swd",
            "http://www.ohchr.org/EN/UDHR/Pages/Language.aspx?LangID=itn",
            "http://www.ohchr.org/EN/UDHR/Pages/Language.aspx?LangID=pql",
            "http://www.ohchr.org/EN/UDHR/Pages/Language.aspx?LangID=kdb1",
            "http://www.ohchr.org/EN/UDHR/Pages/Language.aspx?LangID=yor"
              };
              // Begin the content block!
              blockComposer.Begin(
            new RectangleF(
              Margin,
              Margin,
              page.Size.Width - Margin * 2,
              page.Size.Height - Margin * 2
              ),
            XAlignmentEnum.Justify,
            YAlignmentEnum.Top
            );
              for(
            int index = 0,
              length = titles.Length;
            index < length;
            index++
            )
              {
            composer.SetFont(font,12);
            blockComposer.ShowText(titles[index]);
            blockComposer.ShowBreak();

            composer.SetFont(font,11);
            blockComposer.ShowText(bodies[index]);
            blockComposer.ShowBreak(XAlignmentEnum.Right);

            composer.SetFont(font,8);
            blockComposer.ShowText("[Source: " + sources[index] + "]");
            blockComposer.ShowBreak(breakSize,XAlignmentEnum.Justify);
              }
              // End the content block!
              blockComposer.End();

              // 4. Flush the contents into the page!
              composer.Flush();
        }
Exemplo n.º 35
0
        static int GetFontSizeToFit(string text, RectangleF frame)
        {
            PDFFiles.File file = new PDFFiles.File();
            Page page = new Page(file.Document);
            PDFFonts.Font font = PDFFonts.Font.Get(file.Document, FONT_NAME);
            PrimitiveComposer composer;
            BlockComposer blockComposer;
            int font_size = (int)frame.Height;
            int chars = 0;

            file.Document.Pages.Add(page);
            composer = new PrimitiveComposer(page);
            blockComposer = new BlockComposer(composer);

            while (blockComposer.BoundBox.Height > frame.Height || text.Length != chars) {
                blockComposer.Begin(frame, AlignmentXEnum.Center, AlignmentYEnum.Middle);
                composer.SetFont(font, font_size);
                chars = blockComposer.ShowText(text);
                blockComposer.End();
                Console.WriteLine ("FontSize: {0}, Text Size: [w:{1} h:{2}], Frame Size: [w:{3} h:{4}], Chars: {5}", font_size,
                                   blockComposer.BoundBox.Width, blockComposer.BoundBox.Height,
                                   frame.Width, frame.Height, chars);
                font_size--;
            }

            file.Dispose();

            return font_size + 1;
        }
Exemplo n.º 36
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();
        }
Exemplo n.º 37
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;
        }
Exemplo n.º 38
0
        /// <summary>
        /// Imprime o campo no composer.
        /// </summary>
        /// <param name="comp"></param>
        public void Print(PrimitiveComposer comp, org.pdfclown.documents.contents.fonts.Font fonte, org.pdfclown.documents.contents.fonts.Font fonteBold)
        {
            BlockComposer bComp = new BlockComposer(comp);
            RectangleF pRect = Retangulo.GetPaddedRectangle(PaddingHorizontal, PaddingHorizontal, PaddingSuperior, PaddingInferior);

            comp.SetFont(fonteBold, TamanhoFonteCabecalho);
            ValidadeRectangle(pRect, comp);
            bComp.SafeBegin(pRect, XAlignmentEnum.Left, YAlignmentEnum.Top);
            bComp.ShowText(Cabecalho.ToUpper());
            bComp.End();

            bComp.LineSpace = new Length(LineSpace, Length.UnitModeEnum.Absolute);

            if (!String.IsNullOrWhiteSpace(Corpo))
            {
                org.pdfclown.documents.contents.fonts.Font fonteCorpo = IsCorpoNegrito ? fonteBold : fonte;

                double largura = fonteCorpo.GetWidth(Corpo, CorpoTamanhoFonte);
                double novoTamanho = CorpoTamanhoFonte;

                if (!MultiLinha && largura > pRect.Width)
                {
                    novoTamanho = (CorpoTamanhoFonte * pRect.Width) / largura - Utils.Mm2Pu(0.005F);
                    comp.SetFont(fonteCorpo, novoTamanho);
                }

                comp.SetFont(fonteCorpo, novoTamanho);

                if (CorpoAlinhamentoY == YAlignmentEnum.Top)
                {
                    float yOffSet = (float)fonteBold.GetLineHeight(TamanhoFonteCabecalho) + LineSpace;
                    pRect.Y += yOffSet;
                    pRect.Height -= yOffSet;
                }

                ValidadeRectangle(pRect, comp);
                bComp.SafeBegin(pRect, CorpoAlinhamentoX, CorpoAlinhamentoY);
                bComp.ShowText(Corpo);
                bComp.End();
            }

            comp.SafeDrawRectangle(Retangulo);
        }
Exemplo n.º 39
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();
        }
Exemplo n.º 40
0
        private void Build(
            Document document
            )
        {
            // Add a page to the document!
              Page page = new Page(document); // Instantiates the page inside the document context.
              document.Pages.Add(page); // Puts the page in the pages collection.

              SizeF pageSize = page.Size;

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

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

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

              // Flush the contents into the page!
              composer.Flush();
        }
Exemplo n.º 41
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();
        }
Exemplo n.º 42
0
        /// <summary>
        /// Imprime o cabeçalho do bloco.
        /// </summary>
        private void PrintCabecalho(PrimitiveComposer comp)
        {
            BlockComposer bComp = new BlockComposer(comp);

            RectangleF rect = new RectangleF(0, 0, Size.Width, Danfe.CabecalhoBlocoAltura);
            rect = rect.GetPaddedRectangleMm(0, 0, 1, 0.3F);

            comp.SetFont(Danfe.FontBold, 5);
            bComp.SafeBegin(rect, XAlignmentEnum.Left, YAlignmentEnum.Bottom);
            bComp.ShowText(Cabecalho.ToUpper());
            bComp.End();

            comp.Flush();
        }
Exemplo n.º 43
0
        private void PrintIdentificacaoEmitente(RectangleF area, BlockComposer bComp, PrimitiveComposer comp)
        {
            comp.SafeDrawRectangle(area);

            // Retângulo com padding
            RectangleF pRet = area.GetPaddedRectangleMm(1);

            var emitente = Danfe.Model.Emitente;

            var yAlign = Danfe.PossuiLogo ? YAlignmentEnum.Bottom : YAlignmentEnum.Middle;

            bComp.SafeBegin(pRet, XAlignmentEnum.Left, yAlign);

            double bestSize = DanfeCampo.AjustarFonte(emitente.Nome, Danfe.FontBold, pRet.Width, Danfe.PossuiLogo ? 10 : 12);
            comp.SetFont(Danfe.FontBold, bestSize);

            bComp.ShowText(emitente.Nome);
            bComp.ShowBreak();
            comp.SetFont(Danfe.Font, Danfe.PossuiLogo ? 7 : 8);
            bComp.ShowText(emitente.EnderecoLinha1);
            bComp.ShowBreak();
            bComp.ShowText(emitente.EnderecoBairro);
            bComp.ShowBreak();
            bComp.ShowText(emitente.EnderecoLinha3);

            if (!String.IsNullOrWhiteSpace(emitente.Telefone))
            {
                bComp.ShowBreak();
                bComp.ShowText(String.Format("Fone: {0}", Formatador.FormatarTelefone(emitente.Telefone)));
            }

            bComp.End();

            if (Danfe.PossuiLogo)
            {
                RectangleF logoRectangle = area;
                logoRectangle.Height = bComp.BoundBox.Top - logoRectangle.Y;
                PrintLogo(comp, logoRectangle);
            }
        }
Exemplo n.º 44
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);
        }
Exemplo n.º 45
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");
              }
        }
Exemplo n.º 46
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;
        }
Exemplo n.º 47
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();
        }
Exemplo n.º 48
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();
        }
Exemplo n.º 49
0
        private void Apply(
      PushButton field
      )
        {
            Document document = field.Document;
              Widget widget = field.Widgets[0];

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

              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();
            }

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

            composer.Flush();
              }
              appearance.Normal[null] = normalAppearanceState;
        }
Exemplo n.º 50
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;
        }
Exemplo n.º 51
0
        private void PrintDescricaoDanfe(RectangleF area, BlockComposer bComp, PrimitiveComposer comp)
        {
            comp.SafeDrawRectangle(area);

            // Retangulo com padding
            RectangleF pRet = area.GetPaddedRectangleMm(1);

            // DANFE e descrição
            bComp.SafeBegin(pRet, XAlignmentEnum.Center, YAlignmentEnum.Top);
            comp.SetFont(Danfe.FontBold, 12);
            bComp.ShowText("DANFE");
            comp.SetFont(Danfe.Font, 6);
            bComp.ShowBreak(new SizeF(0, 1));
            bComp.ShowText(DescricaoDanfe);
            bComp.End();

            // Entrada, Saída
            RectangleF rEntrasaSaida = new RectangleF(pRet.X, bComp.BoundBox.Bottom + Utils.Mm2Pu(1.5F), pRet.Width, pRet.Bottom - bComp.BoundBox.Bottom);
            rEntrasaSaida = rEntrasaSaida.GetPaddedRectangleMm(0, 2.5F);

            comp.SetFont(Danfe.Font, 8);
            bComp.SafeBegin(rEntrasaSaida, XAlignmentEnum.Left, YAlignmentEnum.Top);
            bComp.ShowText("0 - Entrada\n1 - Saída");
            bComp.End();

            RectangleF rEntrasaSaida2 = bComp.BoundBox;
            rEntrasaSaida2 = new RectangleF(rEntrasaSaida.Right - bComp.BoundBox.Height, bComp.BoundBox.Y, bComp.BoundBox.Height, bComp.BoundBox.Height);
            comp.SafeDrawRectangle(rEntrasaSaida2);

            bComp.SafeBegin(rEntrasaSaida2, XAlignmentEnum.Center, YAlignmentEnum.Middle);
            bComp.ShowText(Danfe.Model.TipoNF.ToString());
            bComp.End();

            // Número Série e Folha
            RectangleF retEsquerdo = pRet;
            retEsquerdo.Width = Utils.Mm2Pu(8);

            RectangleF retDireito = pRet;
            retDireito.X = retEsquerdo.Right + Utils.Mm2Pu(1);
            retDireito.Width = pRet.Right - retDireito.Left;

            RetanguloFolha = retDireito;
            retDireito.Height -= (float)Danfe.FontBold.GetLineHeight(TamanhoFonteNumeracao);

            comp.SetFont(Danfe.FontBold, TamanhoFonteNumeracao);
            bComp.SafeBegin(retEsquerdo, XAlignmentEnum.Right, YAlignmentEnum.Bottom);
            bComp.ShowText("Nº\nSérie\nFolha");
            bComp.End();

            bComp.SafeBegin(retDireito, XAlignmentEnum.Left, YAlignmentEnum.Bottom);
            bComp.ShowText(String.Format("{0}\n{1}", Danfe.Model.NumeroNF.ToString(Formatador.FormatoNumeroNF), Danfe.Model.Serie));
            bComp.End();
        }
Exemplo n.º 52
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;
        }
Exemplo n.º 53
0
        private void BuildTextBlockPage4(
            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);
            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("Unspaced block");
                blockComposer.End();
            }

            // Drawing the text block...
            {
                fonts::Font sampleFont = new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Times, false, false);
                composer.SetFont(sampleFont, 15);

                float topMargin = 100;
                float boxMargin = 30;
                float boxWidth  = pageSize.Width - boxMargin * 2;
                float boxHeight = (pageSize.Height - topMargin - boxMargin - boxMargin) / 2;
                {
                    RectangleF frame = new RectangleF(
                        boxMargin,
                        topMargin,
                        boxWidth,
                        boxHeight
                        );
                    blockComposer.Begin(frame, XAlignmentEnum.Left, YAlignmentEnum.Top);
                    // Add text until the frame area is completely filled!
                    while (blockComposer.ShowText("DemonstratingHowUnspacedTextIsManagedInCaseOfInsertionInADelimitedPageAreaThroughBlockComposerClass.") > 0)
                    {
                        ;
                    }
                    blockComposer.End();

                    composer.BeginLocalState();
                    {
                        composer.SetLineWidth(0.2);
                        composer.SetLineDash(new LineDash(new double[] { 5, 5 }, 5));
                        composer.DrawRectangle(frame);
                        composer.Stroke();
                    }
                    composer.End();
                }
                {
                    RectangleF frame = new RectangleF(
                        boxMargin,
                        topMargin + boxHeight + boxMargin,
                        boxWidth,
                        boxHeight
                        );
                    blockComposer.Begin(frame, XAlignmentEnum.Left, YAlignmentEnum.Top);
                    // Add text until the frame area is completely filled!
                    while (blockComposer.ShowText(" DemonstratingHowUnspacedTextWithLeadingSpaceIsManagedInCaseOfInsertionInADelimitedPageAreaThroughBlockComposerClass.") > 0)
                    {
                        ;
                    }
                    blockComposer.End();

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

            // 4. Flush the contents into the page!
            composer.Flush();
        }
Exemplo n.º 54
0
        private void Apply(
      CheckBox field
      )
        {
            Document document = field.Document;
              foreach(Widget widget in field.Widgets)
              {
            {
              PdfDictionary widgetDataObject = widget.BaseDataObject;
              widgetDataObject[PdfName.DA] = new PdfString("/ZaDb 0 Tf 0 0 0 rg");
              widgetDataObject[PdfName.MK] = new PdfDictionary(
            new PdfName[]
            {
              PdfName.BG,
              PdfName.BC,
              PdfName.CA
            },
            new PdfDirectObject[]
            {
              new PdfArray(new PdfDirectObject[]{PdfReal.Get(0.9412), PdfReal.Get(0.9412), PdfReal.Get(0.9412)}),
              new PdfArray(new PdfDirectObject[]{PdfInteger.Default, PdfInteger.Default, PdfInteger.Default}),
              new PdfString("4")
            }
            );
              widgetDataObject[PdfName.BS] = new PdfDictionary(
            new PdfName[]
            {
              PdfName.W,
              PdfName.S
            },
            new PdfDirectObject[]
            {
              PdfReal.Get(0.8),
              PdfName.S
            }
            );
              widgetDataObject[PdfName.H] = PdfName.P;
            }

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

            SizeF size = widget.Box.Size;

            AppearanceStates normalAppearance = appearance.Normal;
            FormXObject onState = new FormXObject(document, size);
            normalAppearance[PdfName.Yes] = onState;

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

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

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

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

              composer.Flush();
            }

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

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

            composer.Flush();
              }
            }
              }
        }
Exemplo n.º 55
0
        protected override void ToXObjectInternal(PrimitiveComposer comp)
        {
            BlockComposer bComp = new BlockComposer(comp);

            PrintIdentificacaoEmitente(RetEmitente, bComp, comp);
            PrintDescricaoDanfe(RetDescDanfe, bComp, comp);

            var emitente = Danfe.Model.Emitente;

            comp.SafeDrawRectangle(RetCodigoBarras);
            comp.SafeDrawRectangle(RetCampoVariavel);

            comp.SetFont(Danfe.Font, 8);
            bComp.SafeBegin(RetCampoVariavel, XAlignmentEnum.Center, YAlignmentEnum.Middle);
            bComp.ShowText(MensagemConsulta);
            bComp.End();

            comp.Stroke();

            var barcode = new Barcode128C(Danfe.Model.ChaveAcesso, RetCodigoBarras.Size).ToXObject(Danfe.Document);
            comp.ShowXObject(barcode, new PointF(RetCodigoBarras.X, RetCodigoBarras.Y));
        }
Exemplo n.º 56
0
        /**
          <summary>Populates a PDF file with contents.</summary>
        */
        private void Populate(
            Document document
            )
        {
            // Get the abstract barcode entity!
              EAN13Barcode barcode = new EAN13Barcode("8012345678901");
              // Create the reusable barcode within the document!
              XObject barcodeXObject = barcode.ToXObject(document);

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

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

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

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

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

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

            PrimitiveComposer composer = new PrimitiveComposer(page);
            // Show the barcode!
            composer.ShowXObject(
              barcodeXObject,
              new PointF(pageSize.Width / 2, pageSize.Height / 2),
              new SizeF(pageSize.Height, pageSize.Width),
              XAlignmentEnum.Center,
              YAlignmentEnum.Middle,
              -90
              );
            composer.Flush();
              }
        }
Exemplo n.º 57
0
        protected override void ToXObjectInternal(PrimitiveComposer composer)
        {
            EmpresaViewModel empresa = null;

            if(Danfe.Model.TipoNF == 1)
            {
                empresa = Danfe.Model.Emitente;
            }
            else if(Danfe.Model.TipoNF == 0)
            {
                empresa = Danfe.Model.Destinatario;
            }
            else
            {
                throw new Exception("Tipo de NF não suportado.");
            }

            BlockComposer bComp = new BlockComposer(composer);

            composer.SafeDrawRectangle(RetNumeracao);
            composer.SafeDrawRectangle(RetRecebemos);

            composer.SetFont(Danfe.Font, 6);
            bComp.SafeBegin(RetRecebemos.GetPaddedRectangleMm(1), XAlignmentEnum.Left, YAlignmentEnum.Middle);
            bComp.ShowText(String.Format("RECEBEMOS DE {0} OS PRODUTOS E/OU SERVIÇOS CONSTANTES DA NOTA FISCAL ELETRÔNICA INDICADA ABAIXO.", empresa.Nome));
            bComp.End();

            // Numeração da NFe
            composer.SafeDrawRectangle(RetNumeracao);
            composer.SetFont(Danfe.FontBold, 12);
            bComp.SafeBegin(RetNumeracao, XAlignmentEnum.Center, YAlignmentEnum.Middle);
            bComp.ShowText(String.Format("NF-e\nNº {0}\nSérie {1}", Danfe.Model.NumeroNF.ToString(Formatador.FormatoNumeroNF), Danfe.Model.Serie));
            bComp.End();

            composer.Stroke();

            // Linha pontilhada
            composer.BeginLocalState();
            composer.SetLineDash(new org.pdfclown.documents.contents.LineDash(new double[] { 3, 2 }));
            composer.DrawLine(new PointF(InternalRectangle.Left, Size.Height - MargemLinhaPontilhada), new PointF(InternalRectangle.Right, Size.Height - MargemLinhaPontilhada));
            composer.Stroke();
            composer.End();
        }
Exemplo n.º 58
0
        private void BuildLegend(
            PrimitiveComposer composer,
            string[] steps,
            colorSpaces::Color[] colors,
            SizeF pageSize
            )
        {
            float maxCtmInversionApproximation;
              {
            float[] ctmInversionApproximations = new float[6];
            {
              float[] initialCtmValues, finalCtmValues;
              {
            ContentScanner.GraphicsState state = composer.Scanner.State;
            initialCtmValues = state.GetInitialCtm().Elements;
            finalCtmValues = state.Ctm.Elements;
              }
              for(
            int index = 0,
              length = finalCtmValues.Length;
            index < length;
            index++
            )
              {ctmInversionApproximations[index] = Math.Abs(finalCtmValues[index]) - initialCtmValues[index];}
            }
            maxCtmInversionApproximation = Max(ctmInversionApproximations);
              }

              BlockComposer blockComposer = new BlockComposer(composer);
              blockComposer.LineSpace = new Length(.25, Length.UnitModeEnum.Relative);

              composer.BeginLocalState();
              composer.SetFillColor(
            new colorSpaces::DeviceRGBColor(115 / 255d, 164 / 255d, 232 / 255d)
            );
              RectangleF frame = new RectangleF(
            18,
            18,
            pageSize.Width * .5f,
            pageSize.Height * .5f
            );
              blockComposer.Begin(frame,XAlignmentEnum.Left,YAlignmentEnum.Top);
              composer.SetFont(ResourceName_DefaultFont,24);
              blockComposer.ShowText("Page coordinates sample");
              SizeF breakSize = new SizeF(0,8);
              blockComposer.ShowBreak(breakSize);
              composer.SetFont(ResourceName_DefaultFont,8);
              blockComposer.ShowText(
            "This sample shows the effects of the manipulation of the CTM (Current Transformation Matrix), "
              + "that is the mathematical device which affects the page coordinate system used to place "
              + "graphic contents onto the canvas."
            );
              blockComposer.ShowBreak(breakSize);
              blockComposer.ShowText(
            "The following steps represent the operations applied to this page's CTM in order to alter it. "
              + "Each step writes the word \"Step\" at the lower-left corner of the current page frame:"
            );
              blockComposer.ShowBreak(breakSize);
              for(int i = 0; i < steps.Length; i++)
              {
            composer.SetFillColor(colors[i]);
            blockComposer.ShowText("Step " + i + ")");
            composer.SetFillColor(
              new colorSpaces::DeviceRGBColor(115 / 255d, 164 / 255d, 232 / 255d)
              );
            blockComposer.ShowText(" " + steps[i]);
            blockComposer.ShowBreak(breakSize);
              }
              blockComposer.ShowText("Note that the approximation (" + maxCtmInversionApproximation + ") of the CTM components at step 4 is due to floating point precision limits; their exact values should be 1.0, 0.0, 0.0, 1.0, 0.0, 0.0.");
              blockComposer.End();
              composer.End();
        }
        internal int PrintTable(PrimitiveComposer composer, RectangleF tableArea, int lInit = 0)
        {
            _Colunas[1].Largura = tableArea.Width - _Colunas.Sum(x => x.Largura);
            _Colunas[0].Retangulo = new RectangleF(tableArea.Left, tableArea.Top, _Colunas[0].Largura, tableArea.Height - AlturaCabecalhoTabela);

            for (int i = 1; i < _Colunas.Length; i++)
            {
                RectangleF r = _Colunas[i - 1].Retangulo;
                r.Width = _Colunas[i].Largura;
                r.X = _Colunas[i - 1].Retangulo.Right;
                _Colunas[i].Retangulo = r;
            }

            PrintCabecalhos(composer);

            composer.SetFont(_Documento.Font, 6);

            // Retângulos com padding
            var pr = _Colunas.Select(x => x.Retangulo).ToArray();

            for (int i = 0; i < _Colunas.Length; i++)
            {

                pr[i].Y += AlturaCabecalhoTabela + Margem;
                pr[i].Height -= AlturaCabecalhoTabela + 2 * Margem;
                pr[i].Width -= 2 * Margem;
                pr[i].X += Margem;
            }

            composer.Stroke();

            List<float> dashedLinesY = new List<float>();

            int l = lInit;
            for (; l < Valores.GetLength(0); l++)
            {

                if (!RowFit(l, pr) || CurrentY >= tableArea.Bottom || pr[0].Height <= 0 || ((_Documento.Font.GetLineHeight(6) + Margem) > pr[0].Height))
                {
                    break;
                }

                for (int c = 0; c < _Colunas.Length; c++)
                {
                    PrintTextCell(composer, Valores[l, c], pr[c], _Colunas[c].AlinhamentoHorizontal);
                }

                for (int c = 0; c < _Colunas.Length; c++)
                {
                    pr[c].Y = CurrentY + 2 * Margem;
                    pr[c].Height = tableArea.Bottom - pr[c].Y;
                }

                dashedLinesY.Add(CurrentY + Margem);

            }

            PrintLinhasTracejadas(composer, dashedLinesY, tableArea.Left, tableArea.Right);

            for (int i = 0; i < _Colunas.Length; i++)
            {
                RectangleF rct = _Colunas[i].Retangulo;
                rct.Height = CurrentY + Margem - _Colunas[i].Retangulo.Top;
                _Colunas[i].Retangulo = rct;
                composer.SafeDrawRectangle(_Colunas[i].Retangulo);
            }

            return l;
        }
Exemplo n.º 60
0
        /**
          <summary>Populates a PDF file with contents.</summary>
        */
        private void Populate(
            Document document,
            XObject form
            )
        {
            // 1. Add a page to the document!
              Page page = new Page(document); // Instantiates the page inside the document context.
              document.Pages.Add(page); // Puts the page in the pages collection.

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

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

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