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(); } }
/** * <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 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(); }
/// <summary> /// Renderiza o bloco para um XObject. /// </summary> public virtual org.pdfclown.documents.contents.xObjects.XObject ToXObject() { if (_RenderedObject == null) { _RenderedObject = new org.pdfclown.documents.contents.xObjects.FormXObject(Danfe.Document, Size); PrimitiveComposer composer = new PrimitiveComposer(_RenderedObject); var obj = composer.BeginLocalState(); composer.SetLineWidth(DanfeDocumento.LineWidth); if (PossuiCabecalho) { RectangleF rect = GetHeaderInnerRectangle(); //Danfe.PrintCabecalhoBloco2(composer, rect.Top, rect.Left, rect.Width, Cabecalho); PrintCabecalho(composer); } ToXObjectInternal(composer); foreach (var campo in Campos) { campo.Print(composer, Danfe.Font, Danfe.FontBold); } composer.Stroke(); composer.End(); composer.Flush(); } return(_RenderedObject); }
private void DrawFrame(PrimitiveComposer composer, SKPoint[] frameVertices) { composer.BeginLocalState(); composer.SetLineWidth(0.2f); composer.SetLineDash(new LineDash(new float[] { 5 }, 5)); composer.DrawPolygon(frameVertices); composer.Stroke(); composer.End(); }
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(); }
/** * <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(); }
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; }
private void DrawCross( PrimitiveComposer composer, PointF center ) { composer.DrawLine( new PointF(center.X - 10, center.Y), new PointF(center.X + 10, center.Y) ); composer.DrawLine( new PointF(center.X, center.Y - 10), new PointF(center.X, center.Y + 10) ); composer.Stroke(); }
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(); }
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(); }
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(); }
protected override void ToXObjectInternal(PrimitiveComposer composer) { DanfeProdutosServicosTabela table = new DanfeProdutosServicosTabela(Danfe); table.Valores = CellValues; int end = table.PrintTable(composer, InternalRectangle, ProdutoIndex); if (ProdutoIndex == end) { throw new Exception("O índice do produto não foi incrementado ao gerar a tabela."); } ProdutoIndexEnd = end; composer.Stroke(); }
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; } }
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(); }
/// <summary> /// Print as linhas tracejadas na tabela, ignorando a última /// </summary> /// <param name="composer"></param> /// <param name="y">Lista com as posições y</param> /// <param name="xBegin"></param> /// <param name="xEnd"></param> private void PrintLinhasTracejadas(PrimitiveComposer composer, List <float> y, float xBegin, float xEnd) { if (xBegin < 0) { throw new ArgumentOutOfRangeException("xBegin"); } if (xEnd > composer.Scanner.CanvasSize.Width) { throw new ArgumentOutOfRangeException("xEnd"); } composer.BeginLocalState(); composer.SetLineDash(new LineDash(new Double[] { 3, 2 })); for (int i = 0; i < y.Count - 1; i++) { composer.DrawLine(new PointF(xBegin, y[i]), new PointF(xEnd, y[i])); } composer.Stroke(); composer.End(); }
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)); }
private void BuildTextBlockPage( Document document ) { // 1. Add the page to the document! Page page = new Page(document); // Instantiates the page inside the document context. document.Pages.Add(page); // Puts the page in the pages collection. SizeF pageSize = page.Size; // 2. Create a content composer for the page! PrimitiveComposer composer = new PrimitiveComposer(page); // 3. Drawing the page contents... fonts::Font mainFont = new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Courier, true, false); int step; { XAlignmentEnum[] xAlignments = (XAlignmentEnum[])Enum.GetValues(typeof(XAlignmentEnum)); YAlignmentEnum[] yAlignments = (YAlignmentEnum[])Enum.GetValues(typeof(YAlignmentEnum)); step = (int)(pageSize.Height) / (xAlignments.Length * yAlignments.Length+1); } BlockComposer blockComposer = new BlockComposer(composer); { blockComposer.Begin( new RectangleF( 30, 0, pageSize.Width-60, step*.8f ), XAlignmentEnum.Center, YAlignmentEnum.Middle ); composer.SetFont(mainFont, 32); blockComposer.ShowText("Block alignment"); blockComposer.End(); } // Drawing the text blocks... fonts::Font sampleFont = new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Times, false, false); int x = 30; int y = (int)(step*1.2); foreach(XAlignmentEnum xAlignment in (XAlignmentEnum[])Enum.GetValues(typeof(XAlignmentEnum))) { foreach(YAlignmentEnum yAlignment in (YAlignmentEnum[])Enum.GetValues(typeof(YAlignmentEnum))) { composer.SetFont(mainFont, 12); composer.ShowText( xAlignment + " " + yAlignment + ":", new PointF(x,y), XAlignmentEnum.Left, YAlignmentEnum.Middle, 0 ); composer.SetFont(sampleFont, 10); for(int index = 0; index < 2; index++) { int frameX; switch(index) { case 0: frameX = 150; blockComposer.Hyphenation = false; break; case 1: frameX = 360; blockComposer.Hyphenation = true; break; default: throw new Exception(); } RectangleF frame = new RectangleF( frameX, y-step*.4f, 200, step*.8f ); blockComposer.Begin(frame,xAlignment,yAlignment); blockComposer.ShowText( "Demonstrating how to constrain text inside a page area using PDF Clown. See the other available code samples (such as TypesettingSample) to discover more functionality details." ); blockComposer.End(); composer.BeginLocalState(); composer.SetLineWidth(0.2f); composer.SetLineDash(new LineDash(new double[]{5,5}, 5)); composer.DrawRectangle(frame); composer.Stroke(); composer.End(); } y+=step; } } // 4. Flush the contents into the page! composer.Flush(); }
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(); }
private void BuildMiscellaneousPage( Document document ) { // 1. Add the page to the document! Page page = new Page(document); // Instantiates the page inside the document context. document.Pages.Add(page); // Puts the page in the pages collection. SizeF pageSize = page.Size; // 2. Create a content composer for the page! PrimitiveComposer composer = new PrimitiveComposer(page); // 3. Drawing the page contents... composer.SetFont( new fonts::StandardType1Font( document, fonts::StandardType1Font.FamilyEnum.Courier, true, false ), 32 ); { BlockComposer blockComposer = new BlockComposer(composer); blockComposer.Begin(new RectangleF(30,0,pageSize.Width-60,50),XAlignmentEnum.Center,YAlignmentEnum.Middle); blockComposer.ShowText("Miscellaneous"); blockComposer.End(); } composer.BeginLocalState(); composer.SetLineJoin(LineJoinEnum.Round); composer.SetLineCap(LineCapEnum.Round); // 3.1. Polygon. composer.DrawPolygon( new PointF[] { new PointF(100,200), new PointF(150,150), new PointF(200,150), new PointF(250,200) } ); // 3.2. Polyline. composer.DrawPolyline( new PointF[] { new PointF(300,200), new PointF(350,150), new PointF(400,150), new PointF(450,200) } ); composer.Stroke(); // 3.3. Rectangle (both squared and rounded). int x = 50; int radius = 0; while(x < 500) { if(x > 300) { composer.SetLineDash(new LineDash(new double[]{5,5}, 3)); } composer.SetFillColor(new DeviceRGBColor(1, x / 500d, x / 500d)); composer.DrawRectangle( new RectangleF(x, 250, 150, 100), radius // NOTE: radius parameter determines the rounded angle size. ); composer.FillStroke(); x += 175; radius += 10; } composer.End(); // End local state. composer.BeginLocalState(); composer.SetFont( composer.State.Font, 12 ); // 3.4. Line cap parameter. int y = 400; foreach(LineCapEnum lineCap in (LineCapEnum[])Enum.GetValues(typeof(LineCapEnum))) { composer.ShowText( lineCap + ":", new PointF(50,y), XAlignmentEnum.Left, YAlignmentEnum.Middle, 0 ); composer.SetLineWidth(12); composer.SetLineCap(lineCap); composer.DrawLine( new PointF(120,y), new PointF(220,y) ); composer.Stroke(); composer.BeginLocalState(); composer.SetLineWidth(1); composer.SetStrokeColor(DeviceRGBColor.White); composer.SetLineCap(LineCapEnum.Butt); composer.DrawLine( new PointF(120,y), new PointF(220,y) ); composer.Stroke(); composer.End(); // End local state. y += 30; } // 3.5. Line join parameter. y += 50; foreach(LineJoinEnum lineJoin in (LineJoinEnum[])Enum.GetValues(typeof(LineJoinEnum))) { composer.ShowText( lineJoin + ":", new PointF(50,y), XAlignmentEnum.Left, YAlignmentEnum.Middle, 0 ); composer.SetLineWidth(12); composer.SetLineJoin(lineJoin); PointF[] points = new PointF[] { new PointF(120,y+25), new PointF(150,y-25), new PointF(180,y+25) }; composer.DrawPolyline(points); composer.Stroke(); composer.BeginLocalState(); composer.SetLineWidth(1); composer.SetStrokeColor(DeviceRGBColor.White); composer.SetLineCap(LineCapEnum.Butt); composer.DrawPolyline(points); composer.Stroke(); composer.End(); // End local state. y += 50; } composer.End(); // End local state. // 3.6. Clipping. /* NOTE: Clipping should be conveniently enclosed within a local state in order to easily resume the unaltered drawing area after the operation completes. */ composer.BeginLocalState(); composer.DrawPolygon( new PointF[] { new PointF(220,410), new PointF(300,490), new PointF(450,360), new PointF(430,520), new PointF(590,565), new PointF(420,595), new PointF(460,730), new PointF(380,650), new PointF(330,765), new PointF(310,640), new PointF(220,710), new PointF(275,570), new PointF(170,500), new PointF(275,510) } ); composer.Clip(); // Showing a clown image... // Instantiate a jpeg image object! entities::Image image = entities::Image.Get(GetResourcePath("images" + System.IO.Path.DirectorySeparatorChar + "Clown.jpg")); // Abstract image (entity). xObjects::XObject imageXObject = image.ToXObject(document); // Show the image! composer.ShowXObject( imageXObject, new PointF(170, 320), GeomUtils.Scale(imageXObject.Size, new SizeF(450,0)) ); composer.End(); // End local state. // 4. Flush the contents into the page! composer.Flush(); }
private void BuildTextBlockPage2( 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("Block line alignment"); blockComposer.End(); } // Drawing the text block... { fonts::Font sampleFont = new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Times, false, false); entities::Image sampleImage = entities::Image.Get(GetResourcePath("images" + System.IO.Path.DirectorySeparatorChar + "gnu.jpg")); xObjects::XObject sampleImageXObject = sampleImage.ToXObject(document); IList<LineAlignmentEnum> lineAlignments = new List<LineAlignmentEnum>((LineAlignmentEnum[])Enum.GetValues(typeof(LineAlignmentEnum))); float frameHeight = (pageSize.Height - 130 - 5 * lineAlignments.Count * 2) / (lineAlignments.Count * 2); float frameWidth = (pageSize.Width - 60 - 5 * lineAlignments.Count) / lineAlignments.Count; int imageSize = 7; for(int index = 0, length = lineAlignments.Count; index < length; index++) { LineAlignmentEnum lineAlignment = lineAlignments[index]; for(int imageIndex = 0, imageLength = lineAlignments.Count; imageIndex < imageLength; imageIndex++) { LineAlignmentEnum imageAlignment = lineAlignments[imageIndex]; for(int index2 = 0, length2 = 2; index2 < length2; index2++) { RectangleF frame = new RectangleF( 30 + (frameWidth + 5) * imageIndex, 100 + (frameHeight + 5) * (index * 2 + index2), frameWidth, frameHeight ); blockComposer.Begin(frame,XAlignmentEnum.Left,YAlignmentEnum.Top); { composer.SetFont(mainFont, 3); blockComposer.ShowText("Text: " + lineAlignment); blockComposer.ShowBreak(); blockComposer.ShowText("Image: " + imageAlignment); } blockComposer.End(); blockComposer.Begin(frame,XAlignmentEnum.Left,YAlignmentEnum.Middle); { composer.SetFont(sampleFont, 3); blockComposer.ShowText("Previous row boundary."); blockComposer.ShowBreak(); composer.SetFont(sampleFont, index2 == 0 ? 3 : 6); blockComposer.ShowText("Alignment:"); composer.SetFont(sampleFont, index2 == 0 ? 6 : 3); blockComposer.ShowText(" aligned to " + lineAlignment + " ", lineAlignment); blockComposer.ShowXObject(sampleImageXObject, new SizeF(imageSize, imageSize), imageAlignment); blockComposer.ShowBreak(); composer.SetFont(sampleFont, 3); blockComposer.ShowText("Next row boundary."); } blockComposer.End(); composer.BeginLocalState(); { composer.SetLineWidth(0.1f); composer.SetLineDash(new LineDash(new double[]{1,4}, 4)); composer.DrawRectangle(blockComposer.Frame); composer.Stroke(); } composer.End(); composer.BeginLocalState(); { composer.SetLineWidth(0.1f); composer.SetLineDash(new LineDash(new double[]{1,1}, 1)); composer.DrawRectangle(blockComposer.BoundBox); composer.Stroke(); } composer.End(); } } } } // 4. Flush the contents into the page! composer.Flush(); }
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(); }
private void BuildTextBlockPage3( Document document ) { // 1. Add the page to the document! Page page = new Page(document); // Instantiates the page inside the document context. document.Pages.Add(page); // Puts the page in the pages collection. SizeF pageSize = page.Size; // 2. Create a content composer for the page! PrimitiveComposer composer = new PrimitiveComposer(page); // 3. Drawing the page contents... fonts::Font mainFont = new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Courier, true, false); int stepCount = 5; int step = (int)(pageSize.Height) / (stepCount + 1); // 3.1. Drawing the page title... BlockComposer blockComposer = new BlockComposer(composer); { blockComposer.Begin( new RectangleF( 30, 0, pageSize.Width-60, step*.8f ), XAlignmentEnum.Center, YAlignmentEnum.Middle ); composer.SetFont(mainFont, 32); blockComposer.ShowText("Block line space"); blockComposer.End(); } // 3.2. Drawing the text blocks... fonts::Font sampleFont = new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Times, false, false); int x = 30; int y = (int)(step * 1.1); blockComposer.LineSpace.UnitMode = Length.UnitModeEnum.Relative; for(int index = 0; index < stepCount; index++) { float relativeLineSpace = 0.5f * index; blockComposer.LineSpace.Value = relativeLineSpace; composer.SetFont(mainFont, 12); composer.ShowText( relativeLineSpace + ":", new PointF(x,y), XAlignmentEnum.Left, YAlignmentEnum.Middle, 0 ); composer.SetFont(sampleFont, 10); RectangleF frame = new RectangleF(150, y - step * .4f, 350, step * .9f); blockComposer.Begin(frame,XAlignmentEnum.Left,YAlignmentEnum.Top); blockComposer.ShowText("Demonstrating how to set the block line space. Line space can be expressed either as an absolute value (in user-space units) or as a relative one (floating-point ratio); in the latter case the base value is represented by the current font's line height (so that, for example, 2 means \"a line space that's twice as the line height\")."); blockComposer.End(); composer.BeginLocalState(); { composer.SetLineWidth(0.2); composer.SetLineDash(new LineDash(new double[]{5,5}, 5)); composer.DrawRectangle(frame); composer.Stroke(); } composer.End(); y+=step; } // 4. Flush the contents into the page! composer.Flush(); }
private void DrawCross( PrimitiveComposer composer, PointF center ) { composer.DrawLine( new PointF(center.X-10,center.Y), new PointF(center.X+10,center.Y) ); composer.DrawLine( new PointF(center.X,center.Y-10), new PointF(center.X,center.Y+10) ); composer.Stroke(); }
/* TODO: refresh should happen just before serialization, on document event (e.g. OnWrite()) */ private void RefreshAppearance( ) { FormXObject normalAppearance; RectangleF box = org.pdfclown.objects.Rectangle.Wrap(BaseDataObject[PdfName.Rect]).ToRectangleF(); { AppearanceStates normalAppearances = Appearance.Normal; normalAppearance = normalAppearances[null]; if(normalAppearance != null) { normalAppearance.Box = box; normalAppearance.BaseDataObject.Body.SetLength(0); } else {normalAppearances[null] = normalAppearance = new FormXObject(Document, box);} } PrimitiveComposer composer = new PrimitiveComposer(normalAppearance); { float yOffset = box.Height - Page.Box.Height; MarkupTypeEnum markupType = MarkupType; switch(markupType) { case MarkupTypeEnum.Highlight: { ExtGState defaultExtGState; { ExtGStateResources extGStates = normalAppearance.Resources.ExtGStates; defaultExtGState = extGStates[HighlightExtGStateName]; if(defaultExtGState == null) { if(extGStates.Count > 0) {extGStates.Clear();} extGStates[HighlightExtGStateName] = defaultExtGState = new ExtGState(Document); defaultExtGState.AlphaShape = false; defaultExtGState.BlendMode = new List<BlendModeEnum>(new BlendModeEnum[]{BlendModeEnum.Multiply}); } } composer.ApplyState(defaultExtGState); composer.SetFillColor(Color); { foreach(Quad markupBox in MarkupBoxes) { PointF[] points = markupBox.Points; float markupBoxHeight = points[3].Y - points[0].Y; float markupBoxMargin = GetMarkupBoxMargin(markupBoxHeight); composer.DrawCurve( new PointF(points[3].X, points[3].Y + yOffset), new PointF(points[0].X, points[0].Y + yOffset), new PointF(points[3].X - markupBoxMargin, points[3].Y - markupBoxMargin + yOffset), new PointF(points[0].X - markupBoxMargin, points[0].Y + markupBoxMargin + yOffset) ); composer.DrawLine( new PointF(points[1].X, points[1].Y + yOffset) ); composer.DrawCurve( new PointF(points[2].X, points[2].Y + yOffset), new PointF(points[1].X + markupBoxMargin, points[1].Y + markupBoxMargin + yOffset), new PointF(points[2].X + markupBoxMargin, points[2].Y - markupBoxMargin + yOffset) ); composer.Fill(); } } } break; case MarkupTypeEnum.Squiggly: { composer.SetStrokeColor(Color); composer.SetLineCap(LineCapEnum.Round); composer.SetLineJoin(LineJoinEnum.Round); { foreach(Quad markupBox in MarkupBoxes) { PointF[] points = markupBox.Points; float markupBoxHeight = points[3].Y - points[0].Y; float lineWidth = markupBoxHeight * .02f; float step = markupBoxHeight * .125f; float boxXOffset = points[3].X; float boxYOffset = points[3].Y + yOffset - lineWidth; bool phase = false; composer.SetLineWidth(lineWidth); for(float x = 0, xEnd = points[2].X - boxXOffset; x < xEnd || !phase; x += step) { PointF point = new PointF(x + boxXOffset, (phase ? -step : 0) + boxYOffset); if(x == 0) {composer.StartPath(point);} else {composer.DrawLine(point);} phase = !phase; } } composer.Stroke(); } } break; case MarkupTypeEnum.StrikeOut: case MarkupTypeEnum.Underline: { composer.SetStrokeColor(Color); { float lineYRatio = 0; switch(markupType) { case MarkupTypeEnum.StrikeOut: lineYRatio = .575f; break; case MarkupTypeEnum.Underline: lineYRatio = .85f; break; default: throw new NotImplementedException(); } foreach(Quad markupBox in MarkupBoxes) { PointF[] points = markupBox.Points; float markupBoxHeight = points[3].Y - points[0].Y; float boxYOffset = markupBoxHeight * lineYRatio + yOffset; composer.SetLineWidth(markupBoxHeight * .065); composer.DrawLine( new PointF(points[3].X, points[0].Y + boxYOffset), new PointF(points[2].X, points[1].Y + boxYOffset) ); } composer.Stroke(); } } break; default: throw new NotImplementedException(); } } composer.Flush(); }
private void DrawFrame( PrimitiveComposer composer, PointF[] frameVertices ) { composer.BeginLocalState(); composer.SetLineWidth(0.2f); composer.SetLineDash(new LineDash(new double[]{5,5}, 5)); composer.DrawPolygon(frameVertices); composer.Stroke(); composer.End(); }
public TabelaProdutosServicosNFC(DanfeViewModel viewModel, Estilo estilo, PrimitiveComposer primitiveComposer, float y) : base(estilo) { if (y == 40) { Y_NFC = 100; } if (y == 50) { Y_NFC = 100 + 10; } primitiveComposer.BeginLocalState(); primitiveComposer.SetFont(estilo.FonteCampoTituloNegrito.FonteInterna, estilo.FonteCampoTituloNegrito.Tamanho); primitiveComposer.ShowText("DOCUMENTO AUXILIAR DA NOTA FISCAL", new PointF(140, y + 10), XAlignmentEnum.Center, YAlignmentEnum.Middle, 0); primitiveComposer.ShowText("DE CONSUMIDOR ELETRÔNICA", new PointF(140, y + 20), XAlignmentEnum.Center, YAlignmentEnum.Middle, 0); primitiveComposer.DrawLine(new PointF(15, y + 30), new PointF(265, y + 30)); primitiveComposer.SetLineDash(new org.pdfclown.documents.contents.LineDash(new double[] { 3, 2 })); primitiveComposer.SetFont(estilo.FonteCampoConteudoNegrito.FonteInterna, estilo.FonteCampoConteudoNegrito.Tamanho); primitiveComposer.ShowText("DETALHE DA VENDA", new PointF(140, y + 40), XAlignmentEnum.Center, YAlignmentEnum.Middle, 0); primitiveComposer.DrawLine(new PointF(15, y + 50), new PointF(265, y + 50)); primitiveComposer.SetLineDash(new org.pdfclown.documents.contents.LineDash(new double[] { 3, 2 })); primitiveComposer.SetFont(estilo.FonteCampoConteudo.FonteInterna, estilo.FonteCampoConteudo.Tamanho); primitiveComposer.ShowText("CÓDIGO", new PointF(40, Y_NFC), XAlignmentEnum.Center, YAlignmentEnum.Middle, 0); primitiveComposer.ShowText("DESC.", new PointF(80, Y_NFC), XAlignmentEnum.Center, YAlignmentEnum.Middle, 0); primitiveComposer.ShowText("QTD.", new PointF(120, Y_NFC), XAlignmentEnum.Center, YAlignmentEnum.Middle, 0); primitiveComposer.ShowText("UNID.", new PointF(160, Y_NFC), XAlignmentEnum.Center, YAlignmentEnum.Middle, 0); primitiveComposer.ShowText("PREÇO", new PointF(200, Y_NFC), XAlignmentEnum.Center, YAlignmentEnum.Middle, 0); primitiveComposer.ShowText("TOTAL", new PointF(240, Y_NFC), XAlignmentEnum.Center, YAlignmentEnum.Middle, 0); foreach (var produto in viewModel.Produtos) { Y_NFC = Y_NFC + 10; primitiveComposer.SetFont(estilo.FonteCampoConteudo.FonteInterna, estilo.FonteCampoConteudo.Tamanho); primitiveComposer.ShowText(produto.Codigo, new PointF(40, Y_NFC), XAlignmentEnum.Center, YAlignmentEnum.Middle, 0); if (produto.Descricao.Length >= 10) { primitiveComposer.ShowText(produto.Descricao.Substring(0, 10), new PointF(80, Y_NFC), XAlignmentEnum.Center, YAlignmentEnum.Middle, 0); } else { primitiveComposer.ShowText(produto.Descricao, new PointF(80, Y_NFC), XAlignmentEnum.Center, YAlignmentEnum.Middle, 0); } primitiveComposer.ShowText(produto.Quantidade.Formatar(), new PointF(120, Y_NFC), XAlignmentEnum.Center, YAlignmentEnum.Middle, 0); primitiveComposer.ShowText(produto.Unidade, new PointF(160, Y_NFC), XAlignmentEnum.Center, YAlignmentEnum.Middle, 0); primitiveComposer.ShowText(produto.ValorUnitario.Formatar(), new PointF(200, Y_NFC), XAlignmentEnum.Center, YAlignmentEnum.Middle, 0); primitiveComposer.ShowText(produto.ValorTotal.Formatar(), new PointF(240, Y_NFC), XAlignmentEnum.Center, YAlignmentEnum.Middle, 0); } Y_NFC = Y_NFC + 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(); }
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"); } }
/// <summary> /// Print as linhas tracejadas na tabela, ignorando a última /// </summary> /// <param name="composer"></param> /// <param name="y">Lista com as posições y</param> /// <param name="xBegin"></param> /// <param name="xEnd"></param> private void PrintLinhasTracejadas(PrimitiveComposer composer, List<float> y, float xBegin, float xEnd) { if (xBegin < 0) { throw new ArgumentOutOfRangeException("xBegin"); } if (xEnd > composer.Scanner.CanvasSize.Width) { throw new ArgumentOutOfRangeException("xEnd"); } composer.BeginLocalState(); composer.SetLineDash(new LineDash(new Double[] { 3, 2 })); for (int i = 0; i < y.Count - 1; i++) { composer.DrawLine(new PointF(xBegin, y[i]), new PointF(xEnd, y[i])); } composer.Stroke(); 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; }
/** <summary>Scans a content level looking for text.</summary> */ /* NOTE: Page contents are represented by a sequence of content objects, possibly nested into multiple levels. */ private void Extract( ContentScanner level, PrimitiveComposer composer ) { if(level == null) return; while(level.MoveNext()) { ContentObject content = level.Current; if(content is Text) { ContentScanner.TextWrapper text = (ContentScanner.TextWrapper)level.CurrentWrapper; int colorIndex = 0; foreach(ContentScanner.TextStringWrapper textString in text.TextStrings) { RectangleF textStringBox = textString.Box.Value; Console.WriteLine( "Text [" + "x:" + Math.Round(textStringBox.X) + "," + "y:" + Math.Round(textStringBox.Y) + "," + "w:" + Math.Round(textStringBox.Width) + "," + "h:" + Math.Round(textStringBox.Height) + "] [font size:" + Math.Round(textString.Style.FontSize) + "]: " + textString.Text ); // Drawing text character bounding boxes... colorIndex = (colorIndex + 1) % textCharBoxColors.Length; composer.SetStrokeColor(textCharBoxColors[colorIndex]); foreach(TextChar textChar in textString.TextChars) { /* NOTE: You can get further text information (font, font size, text color, text rendering mode) through textChar.style. */ composer.DrawRectangle(textChar.Box); composer.Stroke(); } // Drawing text string bounding box... composer.BeginLocalState(); composer.SetLineDash(new LineDash(new double[]{5,5})); composer.SetStrokeColor(textStringBoxColor); composer.DrawRectangle(textString.Box.Value); composer.Stroke(); composer.End(); } } else if(content is ContainerObject) { // Scan the inner level! Extract(level.ChildLevel, composer); } } }
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); }
/* * TODO: refresh should happen just before serialization, on document event (e.g. OnWrite()) */ private void RefreshAppearance( ) { FormXObject normalAppearance; RectangleF box = org.pdfclown.objects.Rectangle.Wrap(BaseDataObject[PdfName.Rect]).ToRectangleF(); { AppearanceStates normalAppearances = Appearance.Normal; normalAppearance = normalAppearances[null]; if (normalAppearance != null) { normalAppearance.Box = box; normalAppearance.BaseDataObject.Body.SetLength(0); } else { normalAppearances[null] = normalAppearance = new FormXObject(Document, box); } } PrimitiveComposer composer = new PrimitiveComposer(normalAppearance); { float yOffset = box.Height - Page.Box.Height; MarkupTypeEnum markupType = MarkupType; switch (markupType) { case MarkupTypeEnum.Highlight: { ExtGState defaultExtGState; { ExtGStateResources extGStates = normalAppearance.Resources.ExtGStates; defaultExtGState = extGStates[HighlightExtGStateName]; if (defaultExtGState == null) { if (extGStates.Count > 0) { extGStates.Clear(); } extGStates[HighlightExtGStateName] = defaultExtGState = new ExtGState(Document); defaultExtGState.AlphaShape = false; defaultExtGState.BlendMode = new List <BlendModeEnum>(new BlendModeEnum[] { BlendModeEnum.Multiply }); } } composer.ApplyState(defaultExtGState); composer.SetFillColor(Color); { foreach (Quad markupBox in MarkupBoxes) { PointF[] points = markupBox.Points; float markupBoxHeight = points[3].Y - points[0].Y; float markupBoxMargin = GetMarkupBoxMargin(markupBoxHeight); composer.DrawCurve( new PointF(points[3].X, points[3].Y + yOffset), new PointF(points[0].X, points[0].Y + yOffset), new PointF(points[3].X - markupBoxMargin, points[3].Y - markupBoxMargin + yOffset), new PointF(points[0].X - markupBoxMargin, points[0].Y + markupBoxMargin + yOffset) ); composer.DrawLine( new PointF(points[1].X, points[1].Y + yOffset) ); composer.DrawCurve( new PointF(points[2].X, points[2].Y + yOffset), new PointF(points[1].X + markupBoxMargin, points[1].Y + markupBoxMargin + yOffset), new PointF(points[2].X + markupBoxMargin, points[2].Y - markupBoxMargin + yOffset) ); composer.Fill(); } } } break; case MarkupTypeEnum.Squiggly: { composer.SetStrokeColor(Color); composer.SetLineCap(LineCapEnum.Round); composer.SetLineJoin(LineJoinEnum.Round); { foreach (Quad markupBox in MarkupBoxes) { PointF[] points = markupBox.Points; float markupBoxHeight = points[3].Y - points[0].Y; float lineWidth = markupBoxHeight * .05f; float step = markupBoxHeight * .125f; float boxXOffset = points[3].X; float boxYOffset = points[3].Y + yOffset - lineWidth; bool phase = false; composer.SetLineWidth(lineWidth); for (float x = 0, xEnd = points[2].X - boxXOffset; x < xEnd || !phase; x += step) { PointF point = new PointF(x + boxXOffset, (phase ? -step : 0) + boxYOffset); if (x == 0) { composer.StartPath(point); } else { composer.DrawLine(point); } phase = !phase; } } composer.Stroke(); } } break; case MarkupTypeEnum.StrikeOut: case MarkupTypeEnum.Underline: { composer.SetStrokeColor(Color); { float lineYRatio = 0; switch (markupType) { case MarkupTypeEnum.StrikeOut: lineYRatio = .5f; break; case MarkupTypeEnum.Underline: lineYRatio = .9f; break; default: throw new NotImplementedException(); } foreach (Quad markupBox in MarkupBoxes) { PointF[] points = markupBox.Points; float markupBoxHeight = points[3].Y - points[0].Y; float boxYOffset = markupBoxHeight * lineYRatio + yOffset; composer.SetLineWidth(markupBoxHeight * .065); composer.DrawLine( new PointF(points[3].X, points[0].Y + boxYOffset), new PointF(points[2].X, points[1].Y + boxYOffset) ); } composer.Stroke(); } } break; default: throw new NotImplementedException(); } } composer.Flush(); }
private void BuildCurvesPage( Document document ) { // 1. Add the page to the document! Page page = new Page(document); // Instantiates the page inside the document context. document.Pages.Add(page); // Puts the page in the pages collection. SizeF pageSize = page.Size; // 2. Create a content composer for the page! PrimitiveComposer composer = new PrimitiveComposer(page); // 3. Drawing the page contents... composer.SetFont( new fonts::StandardType1Font( document, fonts::StandardType1Font.FamilyEnum.Courier, true, false ), 32 ); { BlockComposer blockComposer = new BlockComposer(composer); blockComposer.Begin(new RectangleF(30, 0, pageSize.Width - 60, 50), XAlignmentEnum.Center, YAlignmentEnum.Middle); blockComposer.ShowText("Curves"); blockComposer.End(); } // 3.1. Arcs. { float y = 100; for ( int rowIndex = 0; rowIndex < 4; rowIndex++ ) { int angleStep = 45; int startAngle = 0; int endAngle = angleStep; float x = 100; float diameterX; float diameterY; switch (rowIndex) { case 0: default: diameterX = 40; diameterY = 40; break; case 1: diameterX = 40; diameterY = 20; break; case 2: diameterX = 20; diameterY = 40; break; case 3: diameterX = 40; diameterY = 40; break; } for ( int index = 0, length = 360 / angleStep; index < length; index++ ) { RectangleF arcFrame = new RectangleF((float)x, (float)y, (float)diameterX, (float)diameterY); // Drawing the arc frame... composer.BeginLocalState(); composer.SetLineWidth(0.25f); composer.SetLineDash(new LineDash(new double[] { 5, 5 }, 3)); composer.DrawRectangle(arcFrame); composer.Stroke(); composer.End(); // Draw the arc! composer.DrawArc(arcFrame, startAngle, endAngle); composer.Stroke(); endAngle += angleStep; switch (rowIndex) { case 3: startAngle += angleStep; break; } x += 50; } y += diameterY + 10; } } // 3.2. Circle. { RectangleF arcFrame = new RectangleF(100, 300, 100, 100); // Drawing the circle frame... composer.BeginLocalState(); composer.SetLineWidth(0.25f); composer.SetLineDash(new LineDash(new double[] { 5, 5 }, 3)); composer.DrawRectangle(arcFrame); composer.Stroke(); composer.End(); // Drawing the circle... composer.SetFillColor(DeviceRGBColor.Get(System.Drawing.Color.Red)); composer.DrawEllipse(arcFrame); composer.FillStroke(); } // 3.3. Horizontal ellipse. { RectangleF arcFrame = new RectangleF(210, 300, 100, 50); // Drawing the ellipse frame... composer.BeginLocalState(); composer.SetLineWidth(0.25f); composer.SetLineDash(new LineDash(new double[] { 5, 5 }, 3)); composer.DrawRectangle(arcFrame); composer.Stroke(); composer.End(); // Drawing the ellipse... composer.SetFillColor(DeviceRGBColor.Get(System.Drawing.Color.Green)); composer.DrawEllipse(arcFrame); composer.FillStroke(); } // 3.4. Vertical ellipse. { RectangleF arcFrame = new RectangleF(320, 300, 50, 100); // Drawing the ellipse frame... composer.BeginLocalState(); composer.SetLineWidth(0.25f); composer.SetLineDash(new LineDash(new double[] { 5, 5 }, 3)); composer.DrawRectangle(arcFrame); composer.Stroke(); composer.End(); // Drawing the ellipse... composer.SetFillColor(DeviceRGBColor.Get(System.Drawing.Color.Blue)); composer.DrawEllipse(arcFrame); composer.FillStroke(); } // 3.5. Spirals. { float y = 500; float spiralWidth = 100; composer.SetLineWidth(.5f); for ( int rowIndex = 0; rowIndex < 3; rowIndex++ ) { float x = 150; float branchWidth = .5f; float branchRatio = 1; for ( int spiralIndex = 0; spiralIndex < 4; spiralIndex++ ) { float spiralTurnsCount; switch (rowIndex) { case 0: default: spiralTurnsCount = spiralWidth / (branchWidth * 8); break; case 1: spiralTurnsCount = (float)(spiralWidth / (branchWidth * 8 * (spiralIndex * 1.15 + 1))); break; } switch (rowIndex) { case 2: composer.SetLineDash(new LineDash(new double[] { 10, 5 })); composer.SetLineCap(LineCapEnum.Round); break; default: break; } composer.DrawSpiral( new PointF((float)x, (float)y), 0, 360 * spiralTurnsCount, branchWidth, branchRatio ); composer.Stroke(); x += spiralWidth + 10; switch (rowIndex) { case 0: default: branchWidth += 1; break; case 1: branchRatio += .035f; break; } switch (rowIndex) { case 2: composer.SetLineWidth(composer.State.LineWidth + .5f); break; } } y += spiralWidth + 10; } } // 4. Flush the contents into the page! composer.Flush(); }
/** * <summary>Scans a content level looking for text.</summary> */ /* * NOTE: Page contents are represented by a sequence of content objects, * possibly nested into multiple levels. */ private void Extract(ContentScanner level, PrimitiveComposer composer) { if (level == null) { return; } while (level.MoveNext()) { ContentObject content = level.Current; if (content is Text) { TextWrapper text = (TextWrapper)level.CurrentWrapper; int colorIndex = 0; foreach (TextStringWrapper textString in text.TextStrings) { SKRect textStringBox = textString.Box.Value; Console.WriteLine( "Text [" + "x:" + Math.Round(textStringBox.Left) + "," + "y:" + Math.Round(textStringBox.Top) + "," + "w:" + Math.Round(textStringBox.Width) + "," + "h:" + Math.Round(textStringBox.Height) + "] [font size:" + Math.Round(textString.Style.FontSize) + "]: " + textString.Text ); // Drawing text character bounding boxes... colorIndex = (colorIndex + 1) % textCharBoxColors.Length; composer.SetStrokeColor(textCharBoxColors[colorIndex]); foreach (TextChar textChar in textString.TextChars) { /* * NOTE: You can get further text information * (font, font size, text color, text rendering mode) * through textChar.style. */ composer.DrawPolygon(textChar.Quad.GetPoints()); composer.Stroke(); } // Drawing text string bounding box... composer.BeginLocalState(); composer.SetLineDash(new LineDash(new float[] { 5 })); composer.SetStrokeColor(textStringBoxColor); composer.DrawRectangle(textString.Box.Value); composer.Stroke(); composer.End(); } } else if (content is XObject) { // Scan the external level! Extract(((XObject)content).GetScanner(level), composer); } else if (content is ContainerObject) { // Scan the inner level! Extract(level.ChildLevel, composer); } } }
private void BuildTextBlockPage2( 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("Block line alignment"); blockComposer.End(); } // Drawing the text block... { fonts::Font sampleFont = new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Times, false, false); entities::Image sampleImage = entities::Image.Get(GetResourcePath("images" + System.IO.Path.DirectorySeparatorChar + "gnu.jpg")); xObjects::XObject sampleImageXObject = sampleImage.ToXObject(document); IList <LineAlignmentEnum> lineAlignments = new List <LineAlignmentEnum>((LineAlignmentEnum[])Enum.GetValues(typeof(LineAlignmentEnum))); float frameHeight = (pageSize.Height - 130 - 5 * lineAlignments.Count * 2) / (lineAlignments.Count * 2); float frameWidth = (pageSize.Width - 60 - 5 * lineAlignments.Count) / lineAlignments.Count; int imageSize = 7; for (int index = 0, length = lineAlignments.Count; index < length; index++) { LineAlignmentEnum lineAlignment = lineAlignments[index]; for (int imageIndex = 0, imageLength = lineAlignments.Count; imageIndex < imageLength; imageIndex++) { LineAlignmentEnum imageAlignment = lineAlignments[imageIndex]; for (int index2 = 0, length2 = 2; index2 < length2; index2++) { RectangleF frame = new RectangleF( 30 + (frameWidth + 5) * imageIndex, 100 + (frameHeight + 5) * (index * 2 + index2), frameWidth, frameHeight ); blockComposer.Begin(frame, XAlignmentEnum.Left, YAlignmentEnum.Top); { composer.SetFont(mainFont, 3); blockComposer.ShowText("Text: " + lineAlignment); blockComposer.ShowBreak(); blockComposer.ShowText("Image: " + imageAlignment); } blockComposer.End(); blockComposer.Begin(frame, XAlignmentEnum.Left, YAlignmentEnum.Middle); { composer.SetFont(sampleFont, 3); blockComposer.ShowText("Previous row boundary."); blockComposer.ShowBreak(); composer.SetFont(sampleFont, index2 == 0 ? 3 : 6); blockComposer.ShowText("Alignment:"); composer.SetFont(sampleFont, index2 == 0 ? 6 : 3); blockComposer.ShowText(" aligned to " + lineAlignment + " ", lineAlignment); blockComposer.ShowXObject(sampleImageXObject, new SizeF(imageSize, imageSize), imageAlignment); blockComposer.ShowBreak(); composer.SetFont(sampleFont, 3); blockComposer.ShowText("Next row boundary."); } blockComposer.End(); composer.BeginLocalState(); { composer.SetLineWidth(0.1f); composer.SetLineDash(new LineDash(new double[] { 1, 4 }, 4)); composer.DrawRectangle(blockComposer.Frame); composer.Stroke(); } composer.End(); composer.BeginLocalState(); { composer.SetLineWidth(0.1f); composer.SetLineDash(new LineDash(new double[] { 1, 1 }, 1)); composer.DrawRectangle(blockComposer.BoundBox); composer.Stroke(); } composer.End(); } } } } // 4. Flush the contents into the page! composer.Flush(); }
/// <summary> /// Renderiza o bloco para um XObject. /// </summary> public virtual org.pdfclown.documents.contents.xObjects.XObject ToXObject() { if(_RenderedObject == null) { _RenderedObject = new org.pdfclown.documents.contents.xObjects.FormXObject(Danfe.Document, Size); PrimitiveComposer composer = new PrimitiveComposer(_RenderedObject); var obj = composer.BeginLocalState(); composer.SetLineWidth(DanfeDocumento.LineWidth); if (PossuiCabecalho) { RectangleF rect = GetHeaderInnerRectangle(); //Danfe.PrintCabecalhoBloco2(composer, rect.Top, rect.Left, rect.Width, Cabecalho); PrintCabecalho(composer); } ToXObjectInternal(composer); foreach (var campo in Campos) { campo.Print(composer, Danfe.Font, Danfe.FontBold); } composer.Stroke(); composer.End(); composer.Flush(); } return _RenderedObject; }
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(); }
private void BuildMiscellaneousPage( Document document ) { // 1. Add the page to the document! Page page = new Page(document); // Instantiates the page inside the document context. document.Pages.Add(page); // Puts the page in the pages collection. SizeF pageSize = page.Size; // 2. Create a content composer for the page! PrimitiveComposer composer = new PrimitiveComposer(page); // 3. Drawing the page contents... composer.SetFont( new fonts::StandardType1Font( document, fonts::StandardType1Font.FamilyEnum.Courier, true, false ), 32 ); { BlockComposer blockComposer = new BlockComposer(composer); blockComposer.Begin(new RectangleF(30, 0, pageSize.Width - 60, 50), XAlignmentEnum.Center, YAlignmentEnum.Middle); blockComposer.ShowText("Miscellaneous"); blockComposer.End(); } composer.BeginLocalState(); composer.SetLineJoin(LineJoinEnum.Round); composer.SetLineCap(LineCapEnum.Round); // 3.1. Polygon. composer.DrawPolygon( new PointF[] { new PointF(100, 200), new PointF(150, 150), new PointF(200, 150), new PointF(250, 200) } ); // 3.2. Polyline. composer.DrawPolyline( new PointF[] { new PointF(300, 200), new PointF(350, 150), new PointF(400, 150), new PointF(450, 200) } ); composer.Stroke(); // 3.3. Rectangle (both squared and rounded). int x = 50; int radius = 0; while (x < 500) { if (x > 300) { composer.SetLineDash(new LineDash(new double[] { 5, 5 }, 3)); } composer.SetFillColor(new DeviceRGBColor(1, x / 500d, x / 500d)); composer.DrawRectangle( new RectangleF(x, 250, 150, 100), radius // NOTE: radius parameter determines the rounded angle size. ); composer.FillStroke(); x += 175; radius += 10; } composer.End(); // End local state. composer.BeginLocalState(); composer.SetFont( composer.State.Font, 12 ); // 3.4. Line cap parameter. int y = 400; foreach (LineCapEnum lineCap in (LineCapEnum[])Enum.GetValues(typeof(LineCapEnum))) { composer.ShowText( lineCap + ":", new PointF(50, y), XAlignmentEnum.Left, YAlignmentEnum.Middle, 0 ); composer.SetLineWidth(12); composer.SetLineCap(lineCap); composer.DrawLine( new PointF(120, y), new PointF(220, y) ); composer.Stroke(); composer.BeginLocalState(); composer.SetLineWidth(1); composer.SetStrokeColor(DeviceRGBColor.White); composer.SetLineCap(LineCapEnum.Butt); composer.DrawLine( new PointF(120, y), new PointF(220, y) ); composer.Stroke(); composer.End(); // End local state. y += 30; } // 3.5. Line join parameter. y += 50; foreach (LineJoinEnum lineJoin in (LineJoinEnum[])Enum.GetValues(typeof(LineJoinEnum))) { composer.ShowText( lineJoin + ":", new PointF(50, y), XAlignmentEnum.Left, YAlignmentEnum.Middle, 0 ); composer.SetLineWidth(12); composer.SetLineJoin(lineJoin); PointF[] points = new PointF[] { new PointF(120, y + 25), new PointF(150, y - 25), new PointF(180, y + 25) }; composer.DrawPolyline(points); composer.Stroke(); composer.BeginLocalState(); composer.SetLineWidth(1); composer.SetStrokeColor(DeviceRGBColor.White); composer.SetLineCap(LineCapEnum.Butt); composer.DrawPolyline(points); composer.Stroke(); composer.End(); // End local state. y += 50; } composer.End(); // End local state. // 3.6. Clipping. /* * NOTE: Clipping should be conveniently enclosed within a local state * in order to easily resume the unaltered drawing area after the operation completes. */ composer.BeginLocalState(); composer.DrawPolygon( new PointF[] { new PointF(220, 410), new PointF(300, 490), new PointF(450, 360), new PointF(430, 520), new PointF(590, 565), new PointF(420, 595), new PointF(460, 730), new PointF(380, 650), new PointF(330, 765), new PointF(310, 640), new PointF(220, 710), new PointF(275, 570), new PointF(170, 500), new PointF(275, 510) } ); composer.Clip(); // Showing a clown image... // Instantiate a jpeg image object! entities::Image image = entities::Image.Get(GetResourcePath("images" + System.IO.Path.DirectorySeparatorChar + "Clown.jpg")); // Abstract image (entity). xObjects::XObject imageXObject = image.ToXObject(document); // Show the image! composer.ShowXObject( imageXObject, new PointF(170, 320), GeomUtils.Scale(imageXObject.Size, new SizeF(450, 0)) ); composer.End(); // End local state. // 4. Flush the contents into the page! composer.Flush(); }
private void BuildSteps( PrimitiveComposer composer, string[] steps, colorSpaces::Color[] colors, SKSize pageSize ) { composer.SetFont(ResourceName_DefaultFont, 32); SKRect frame = SKRect.Create( 0, 0, pageSize.Width, pageSize.Height ); // Step 0. { colors[0] = new colorSpaces::DeviceRGBColor(30 / 255d, 10 / 255d, 0); composer.SetFillColor(colors[0]); composer.SetStrokeColor(colors[0]); // Draw the page frame! composer.DrawRectangle(frame); composer.Stroke(); // Draw the lower-left corner mark! composer.ShowText( "Step 0", new SKPoint(0, pageSize.Height), XAlignmentEnum.Left, YAlignmentEnum.Bottom, 0 ); steps[0] = GetStepNote(composer, "default"); } // Step 1. { colors[1] = new colorSpaces::DeviceRGBColor(80 / 255d, 25 / 255d, 0); composer.SetFillColor(colors[1]); composer.SetStrokeColor(colors[1]); // Transform the coordinate space, applying translation! composer.Translate(72, 72); // Draw the page frame! composer.DrawRectangle(frame); composer.Stroke(); // Draw the lower-left corner mark! composer.ShowText( "Step 1", new SKPoint(0, pageSize.Height), XAlignmentEnum.Left, YAlignmentEnum.Bottom, 0 ); steps[1] = GetStepNote(composer, "after translate(72,72)"); } // Step 2. { colors[2] = new colorSpaces::DeviceRGBColor(130 / 255d, 45 / 255d, 0); composer.SetFillColor(colors[2]); composer.SetStrokeColor(colors[2]); // Transform the coordinate space, applying clockwise rotation! composer.Rotate(-20); // Draw the page frame! composer.DrawRectangle(frame); composer.Stroke(); // Draw the coordinate space origin mark! composer.ShowText("Origin 2"); // Draw the lower-left corner mark! composer.ShowText( "Step 2", new SKPoint(0, pageSize.Height), XAlignmentEnum.Left, YAlignmentEnum.Bottom, 0 ); steps[2] = GetStepNote(composer, "after rotate(20)"); } // Step 3. { colors[3] = new colorSpaces::DeviceRGBColor(180 / 255d, 60 / 255d, 0); composer.SetFillColor(colors[3]); composer.SetStrokeColor(colors[3]); // Transform the coordinate space, applying translation and scaling! composer.Translate(0, 72); composer.Scale(.5f, .5f); // Draw the page frame! composer.DrawRectangle(frame); composer.Stroke(); // Draw the lower-left corner mark! composer.ShowText( "Step 3", new SKPoint(0, pageSize.Height), XAlignmentEnum.Left, YAlignmentEnum.Bottom, 0 ); steps[3] = GetStepNote(composer, "after translate(0,72) and scale(.5,.5)"); } // Step 4. { colors[4] = new colorSpaces::DeviceRGBColor(230 / 255d, 75 / 255d, 0); composer.SetFillColor(colors[4]); composer.SetStrokeColor(colors[4]); // Transform the coordinate space, restoring its initial CTM! composer.Add( ModifyCTM.GetResetCTM( composer.Scanner.State ) ); // Draw the page frame! composer.DrawRectangle(frame); composer.Stroke(); // Draw the lower-left corner mark! composer.ShowText( "Step 4", new SKPoint(0, pageSize.Height), XAlignmentEnum.Left, YAlignmentEnum.Bottom, 0 ); steps[4] = GetStepNote(composer, "after resetting CTM"); } }
private void BuildTextBlockPage( Document document ) { // 1. Add the page to the document! Page page = new Page(document); // Instantiates the page inside the document context. document.Pages.Add(page); // Puts the page in the pages collection. SizeF pageSize = page.Size; // 2. Create a content composer for the page! PrimitiveComposer composer = new PrimitiveComposer(page); // 3. Drawing the page contents... fonts::Font mainFont = new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Courier, true, false); int step; { XAlignmentEnum[] xAlignments = (XAlignmentEnum[])Enum.GetValues(typeof(XAlignmentEnum)); YAlignmentEnum[] yAlignments = (YAlignmentEnum[])Enum.GetValues(typeof(YAlignmentEnum)); step = (int)(pageSize.Height) / (xAlignments.Length * yAlignments.Length + 1); } BlockComposer blockComposer = new BlockComposer(composer); { blockComposer.Begin( new RectangleF( 30, 0, pageSize.Width - 60, step * .8f ), XAlignmentEnum.Center, YAlignmentEnum.Middle ); composer.SetFont(mainFont, 32); blockComposer.ShowText("Block alignment"); blockComposer.End(); } // Drawing the text blocks... fonts::Font sampleFont = new fonts::StandardType1Font(document, fonts::StandardType1Font.FamilyEnum.Times, false, false); int x = 30; int y = (int)(step * 1.2); foreach (XAlignmentEnum xAlignment in (XAlignmentEnum[])Enum.GetValues(typeof(XAlignmentEnum))) { foreach (YAlignmentEnum yAlignment in (YAlignmentEnum[])Enum.GetValues(typeof(YAlignmentEnum))) { composer.SetFont(mainFont, 12); composer.ShowText( xAlignment + " " + yAlignment + ":", new PointF(x, y), XAlignmentEnum.Left, YAlignmentEnum.Middle, 0 ); composer.SetFont(sampleFont, 10); for (int index = 0; index < 2; index++) { int frameX; switch (index) { case 0: frameX = 150; blockComposer.Hyphenation = false; break; case 1: frameX = 360; blockComposer.Hyphenation = true; break; default: throw new Exception(); } RectangleF frame = new RectangleF( frameX, y - step * .4f, 200, step * .8f ); blockComposer.Begin(frame, xAlignment, yAlignment); blockComposer.ShowText( "Demonstrating how to constrain text inside a page area using PDF Clown. See the other available code samples (such as TypesettingSample) to discover more functionality details." ); blockComposer.End(); composer.BeginLocalState(); composer.SetLineWidth(0.2f); composer.SetLineDash(new LineDash(new double[] { 5, 5 }, 5)); composer.DrawRectangle(frame); composer.Stroke(); composer.End(); } y += step; } } // 4. Flush the contents into the page! composer.Flush(); }
/** <summary>Populates a PDF file with contents.</summary> */ private void Populate( Document document ) { // 1. Add the page to the document! Page page = new Page(document); // Instantiates the page inside the document context. document.Pages.Add(page); // Puts the page in the pages collection. // 2. Create a content composer for the page! PrimitiveComposer composer = new PrimitiveComposer(page); colors::Color textColor = new colors::DeviceRGBColor(115 / 255d, 164 / 255d, 232 / 255d); composer.SetFillColor(textColor); BlockComposer blockComposer = new BlockComposer(composer); blockComposer.Begin(new RectangleF(300, 400, 200, 100), XAlignmentEnum.Left, YAlignmentEnum.Middle); composer.SetFont( new fonts::StandardType1Font( document, fonts::StandardType1Font.FamilyEnum.Times, false, true ), 12 ); blockComposer.ShowText("PrimitiveComposer.ShowText(...) methods return the actual bounding box of the text shown, allowing to precisely determine its location on the page."); blockComposer.End(); // 3. Inserting contents... // Set the font to use! composer.SetFont( new fonts::StandardType1Font( document, fonts::StandardType1Font.FamilyEnum.Courier, true, false ), 72 ); composer.DrawPolygon( composer.ShowText( "Text frame", new PointF(150, 360), XAlignmentEnum.Left, YAlignmentEnum.Middle, 45 ).Points ); composer.Stroke(); composer.SetFont( fonts::Font.Get( document, GetResourcePath("fonts" + System.IO.Path.DirectorySeparatorChar + "Ruritania-Outline.ttf") ), 102 ); composer.DrawPolygon( composer.ShowText( "Text frame", new PointF(300, 600), XAlignmentEnum.Center, YAlignmentEnum.Middle, -25 ).Points ); composer.Stroke(); // 4. Flush the contents into the page! composer.Flush(); }
private void 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(); }
public FormXObject Build( ) { bool isRound = type == TypeEnum.Round; bool isStriped = type == TypeEnum.Striped; double textScale = .5; double borderWidth = this.borderWidth.GetValue(width); double doubleBorderGap = borderDoubled ? borderWidth : 0; double fontSize = 10; fontSize *= ((width - (isStriped ? 2 : doubleBorderGap * 2 + (borderWidth * (borderDoubled ? 1.5 : 1) * 2) + width * (isRound ? .15 : .05))) / textScale) / font.GetWidth(text, fontSize); float height = (float)(isRound ? width : (font.GetAscent(fontSize) * 1.2 + doubleBorderGap * 2 + (borderWidth * (borderDoubled ? 1.5 : 1) * 2))); SizeF size = new SizeF(width, height); FormXObject appearance = new FormXObject(document, size); { PrimitiveComposer composer = new PrimitiveComposer(appearance); if (color != null) { composer.SetStrokeColor(color); composer.SetFillColor(color); } composer.SetTextScale(textScale); composer.SetFont(font, fontSize); composer.ShowText(text, new PointF(size.Width / 2, (float)(size.Height / 2 - font.GetDescent(fontSize) * .4)), XAlignmentEnum.Center, YAlignmentEnum.Middle, 0); double borderRadius = isRound ? 0 : this.borderRadius.GetValue((size.Width + size.Height) / 2); RectangleF prevBorderBox = appearance.Box; for (int borderStep = 0, borderStepLimit = (borderDoubled ? 2 : 1); borderStep < borderStepLimit; borderStep++) { if (borderStep == 0) { composer.SetLineWidth(borderWidth); } else { composer.SetLineWidth(composer.State.LineWidth / 2); } float lineWidth = (float)(borderStep > 0 ? composer.State.LineWidth / 2 : borderWidth); float marginY = (float)(lineWidth / 2 + (borderStep > 0 ? composer.State.LineWidth + doubleBorderGap : 0)); float marginX = isStriped ? 0 : marginY; RectangleF borderBox = new RectangleF(prevBorderBox.X + marginX, prevBorderBox.Y + marginY, prevBorderBox.Width - marginX * 2, prevBorderBox.Height - marginY * 2); if (isRound) { composer.DrawEllipse(borderBox); } else { if (isStriped) { composer.DrawLine(new PointF(borderBox.Left, borderBox.Top), new PointF(borderBox.Right, borderBox.Top)); composer.DrawLine(new PointF(borderBox.Left, borderBox.Bottom), new PointF(borderBox.Right, borderBox.Bottom)); } else { composer.DrawRectangle(borderBox, borderRadius * (1 - .5 * borderStep)); } } composer.Stroke(); prevBorderBox = borderBox; } composer.Flush(); } return(appearance); }
private void BuildCurvesPage( Document document ) { // 1. Add the page to the document! Page page = new Page(document); // Instantiates the page inside the document context. document.Pages.Add(page); // Puts the page in the pages collection. SizeF pageSize = page.Size; // 2. Create a content composer for the page! PrimitiveComposer composer = new PrimitiveComposer(page); // 3. Drawing the page contents... composer.SetFont( new fonts::StandardType1Font( document, fonts::StandardType1Font.FamilyEnum.Courier, true, false ), 32 ); { BlockComposer blockComposer = new BlockComposer(composer); blockComposer.Begin(new RectangleF(30,0,pageSize.Width-60,50),XAlignmentEnum.Center,YAlignmentEnum.Middle); blockComposer.ShowText("Curves"); blockComposer.End(); } // 3.1. Arcs. { float y = 100; for( int rowIndex = 0; rowIndex < 4; rowIndex++ ) { int angleStep = 45; int startAngle = 0; int endAngle = angleStep; float x = 100; float diameterX; float diameterY; switch(rowIndex) { case 0: default: diameterX = 40; diameterY = 40; break; case 1: diameterX = 40; diameterY = 20; break; case 2: diameterX = 20; diameterY = 40; break; case 3: diameterX = 40; diameterY = 40; break; } for( int index = 0, length = 360/angleStep; index < length; index++ ) { RectangleF arcFrame = new RectangleF((float)x,(float)y,(float)diameterX,(float)diameterY); // Drawing the arc frame... composer.BeginLocalState(); composer.SetLineWidth(0.25f); composer.SetLineDash(new LineDash(new double[]{5,5}, 3)); composer.DrawRectangle(arcFrame); composer.Stroke(); composer.End(); // Draw the arc! composer.DrawArc(arcFrame,startAngle,endAngle); composer.Stroke(); endAngle += angleStep; switch(rowIndex) { case 3: startAngle += angleStep; break; } x += 50; } y += diameterY + 10; } } // 3.2. Circle. { RectangleF arcFrame = new RectangleF(100, 300, 100, 100); // Drawing the circle frame... composer.BeginLocalState(); composer.SetLineWidth(0.25f); composer.SetLineDash(new LineDash(new double[]{5,5}, 3)); composer.DrawRectangle(arcFrame); composer.Stroke(); composer.End(); // Drawing the circle... composer.SetFillColor(DeviceRGBColor.Get(System.Drawing.Color.Red)); composer.DrawEllipse(arcFrame); composer.FillStroke(); } // 3.3. Horizontal ellipse. { RectangleF arcFrame = new RectangleF(210, 300, 100, 50); // Drawing the ellipse frame... composer.BeginLocalState(); composer.SetLineWidth(0.25f); composer.SetLineDash(new LineDash(new double[]{5,5}, 3)); composer.DrawRectangle(arcFrame); composer.Stroke(); composer.End(); // Drawing the ellipse... composer.SetFillColor(DeviceRGBColor.Get(System.Drawing.Color.Green)); composer.DrawEllipse(arcFrame); composer.FillStroke(); } // 3.4. Vertical ellipse. { RectangleF arcFrame = new RectangleF(320, 300, 50, 100); // Drawing the ellipse frame... composer.BeginLocalState(); composer.SetLineWidth(0.25f); composer.SetLineDash(new LineDash(new double[]{5,5}, 3)); composer.DrawRectangle(arcFrame); composer.Stroke(); composer.End(); // Drawing the ellipse... composer.SetFillColor(DeviceRGBColor.Get(System.Drawing.Color.Blue)); composer.DrawEllipse(arcFrame); composer.FillStroke(); } // 3.5. Spirals. { float y = 500; float spiralWidth = 100; composer.SetLineWidth(.5f); for( int rowIndex = 0; rowIndex < 3; rowIndex++ ) { float x = 150; float branchWidth = .5f; float branchRatio = 1; for( int spiralIndex = 0; spiralIndex < 4; spiralIndex++ ) { float spiralTurnsCount; switch(rowIndex) { case 0: default: spiralTurnsCount = spiralWidth/(branchWidth*8); break; case 1: spiralTurnsCount = (float)(spiralWidth/(branchWidth*8*(spiralIndex*1.15+1))); break; } switch(rowIndex) { case 2: composer.SetLineDash(new LineDash(new double[]{10,5})); composer.SetLineCap(LineCapEnum.Round); break; default: break; } composer.DrawSpiral( new PointF((float)x,(float)y), 0, 360*spiralTurnsCount, branchWidth, branchRatio ); composer.Stroke(); x += spiralWidth + 10; switch(rowIndex) { case 0: default: branchWidth += 1; break; case 1: branchRatio += .035f; break; } switch(rowIndex) { case 2: composer.SetLineWidth(composer.State.LineWidth+.5f); break; } } y += spiralWidth + 10; } } // 4. Flush the contents into the page! composer.Flush(); }