예제 #1
1
        public override void OnEndPage(PdfWriter writer, Document document)
        {
            base.OnEndPage(writer, document);

            if (_isLastPage)
            {
                var relativeWidths = ColumnsHelper.GetRelativeColumnsForProducts(PageSize.A4);

                //RODAPE
                var pdfTableFooter = new BuilderTable().Create(relativeWidths).Standard();
                pdfTableFooter.AddCell(new BuilderCell("", 5).Create("DADOS ADICIONAIS").FixedHeight(15).Bold().HorizontalLeft().VerticalBottom().Colspan(42).NoBorder().BorderBuilder(false, false, false, false).Standard());

                pdfTableFooter.AddCell(new BuilderCell("", 5).Create("INFORMAÇÕES COMPLEMENTARES").FixedHeight(5).Bold().HorizontalLeft().VerticalTop().Colspan(32).NoBorder().BorderBuilder(true, true, false, true).Standard());
                pdfTableFooter.AddCell(new BuilderCell("", 5).Create("RESERVADO AO FISCO").Bold().HorizontalLeft().VerticalTop().Colspan(10).NoBorder().BorderBuilder(true, true, false, true).Standard());

                var infAdicional = _nfe.NFe.infNFe.infAdic;
                pdfTableFooter.AddCell(new BuilderCell("", 5).Create(infAdicional.infCpl).FixedHeight(25).HorizontalLeft().VerticalTop().Colspan(32).NoBorder().BorderBuilder(true, true, false, false).Standard());
                pdfTableFooter.AddCell(new BuilderCell("", 5).Create(" ").HorizontalLeft().VerticalTop().Colspan(10).NoBorder().BorderBuilder(true, true, false, false).Standard());

                if (_isHomolog)
                {
                    pdfTableFooter.AddCell(new BuilderCell("", 5).Create("SEM VALOR FISCAL").FixedHeight(5).HorizontalLeft().VerticalTop().Colspan(32).NoBorder().BorderBuilder(true, true, true, false).Standard());
                    pdfTableFooter.AddCell(new BuilderCell("", 5).Create(" ").HorizontalLeft().VerticalTop().Colspan(10).NoBorder().BorderBuilder(true, true, true, false).Standard());
                }

                document.Add(pdfTableFooter);
            }

            const float posX = 325f;
            const float posY = 662f;

            var pageN = writer.PageNumber;
            var text = "Folha " + pageN + "/";
            var len = _baseFont.GetWidthPoint(text, 8);

            _pdfContent = writer.DirectContent;
            _pdfContent.SetRGBColorFill(100, 100, 100);
            _pdfContent.BeginText();
            _pdfContent.SetFontAndSize(_baseFont, 8f);
            _pdfContent.SetTextMatrix(posX, posY);
            _pdfContent.ShowText(text);
            _pdfContent.EndText();
            _pdfContent.AddTemplate(_pageNumberTemplate, posX + len, posY);
            _pdfContent.BeginText();
            _pdfContent.SetFontAndSize(_baseFont, 8f);
            _pdfContent.EndText();
        }
예제 #2
0
        public void CreateDanfe(Document document)
        {
            var relativeColumns = ColumnsHelper.GetRelativeColumns(PageSize.A4);

            var pdfTable = new BuilderTable().Create(relativeColumns).Standard();

            if (_nfe.NFe == null) return;
            var emit = _nfe.NFe.infNFe.emit;
            var dest = _nfe.NFe.infNFe.dest;
            var total = _nfe.NFe.infNFe.total;
            var ide = _nfe.NFe.infNFe.ide;
            var protocol = _nfe.protNFe.infProt;
            var transp = _nfe.NFe.infNFe.transp;

            //---INICIO CANHOTO
            string serie;
            var nfNr = PrintCanhoto(emit, pdfTable, ide, out serie);
            //---FINAL CANHOTO

            //---INICIO CABECALHO
            PrintCabecalho(protocol, pdfTable, emit, ide, nfNr, serie);

            //DESTINATARIO
            PrintDestinatario(pdfTable, dest, ide);

            //CALCULOS IMPOSTOS
            PrintImpostos(pdfTable, total);

            //TRANSPORTADORA
            PrintTransportadora(pdfTable, transp);

            //PRODUTOS
            var pdfTable2 = PrintProdutos(pdfTable);
            //---FINAL CABECALHO

            document.Add(pdfTable);
            document.Add(pdfTable2);
        }
예제 #3
0
        private byte[] GenareteDanfe(Rectangle format)
        {
            using (var memoryStream = new MemoryStream())
            {
                using (var pdfDocument = new BuilderDocument().Create(format).Standard())
                {
                    var pdfWriter = new BuilderPdfWriter().Create(pdfDocument, memoryStream);
                    var obj = (TNfeProc)Helper.LoadXmltoStr(_xml.ReadToEnd(), VersaoNFe.v310, "TNfeProc");
                    var header = new DanfeHeader(obj, _isHomolog);
                    pdfWriter.PageEvent = header;

                    pdfDocument.Open();

                    var relativeWidths = ColumnsHelper.GetRelativeColumnsForProducts(format);
                    var pdfTable = new BuilderTable().Create(relativeWidths).Standard();

                    GetProducts(pdfTable, obj.NFe.infNFe.det);

                    pdfDocument.Add(pdfTable);

                    const float footerSize = 78f;
                    const float headerSize = 444f;
                    const float pageBorder = 40f;

                    var usedTotalSize = (header.GetTotalPages() * headerSize) + pdfTable.TotalHeight + (header.GetTotalPages() * pageBorder);
                    var availableTotalSize = PageSize.A4.Height * header.GetTotalPages();
                    var freeSpaceToEmptyProducts = (int)(availableTotalSize - (usedTotalSize + footerSize));

                    var pdfEmptyTable = new BuilderTable().Create(1).Standard();
                    pdfEmptyTable.AddCell(new BuilderCell().Create("").HorizontalCenter().VerticalCenter().FixedHeight(freeSpaceToEmptyProducts).BorderBuilder(true, true, true, true).Standard());

                    pdfDocument.Add(pdfEmptyTable);
                    header.SetLastPage();
                }

                var reportResult = new byte[memoryStream.Position];
                memoryStream.Position = 0;
                memoryStream.Read(reportResult, 0, reportResult.Length);
                return reportResult;
            }
        }
예제 #4
0
        private static PdfPTable PrintProdutos(PdfPTable pdfTable)
        {
            pdfTable.AddCell(
                new BuilderCell("", 5).Create("DADOS DOS PRODUTOS/SERVIÇOS")
                    .Bold()
                    .HorizontalLeft()
                    .VerticalBottom()
                    .Colspan(19)
                    .NoBorder()
                    .BorderBuilder(false, false, false, true)
                    .Standard());

            var relativeColumnsForProducts = ColumnsHelper.GetRelativeColumnsForProducts(PageSize.A4);
            var pdfTable2 = new BuilderTable().Create(relativeColumnsForProducts).Standard();
            pdfTable2.AddCell(
                new BuilderCell("", 5).Create("COD PRODUTO")
                    .HorizontalCenter()
                    .VerticalCenter()
                    .Colspan(3)
                    .BorderBuilder(true, true, true, true)
                    .Standard());
            pdfTable2.AddCell(
                new BuilderCell("", 5).Create("DESCRIÇÃO PRODUTO/SERVICO")
                    .HorizontalCenter()
                    .VerticalCenter()
                    .Colspan(14)
                    .BorderBuilder(true, true, true, true)
                    .Standard());
            pdfTable2.AddCell(
                new BuilderCell("", 5).Create("NCM/SH")
                    .HorizontalCenter()
                    .VerticalCenter()
                    .Colspan(2)
                    .BorderBuilder(true, true, true, true)
                    .Standard());
            pdfTable2.AddCell(
                new BuilderCell("", 5).Create("O/CST")
                    .HorizontalCenter()
                    .VerticalCenter()
                    .Colspan(2)
                    .BorderBuilder(true, true, true, true)
                    .Standard());
            pdfTable2.AddCell(
                new BuilderCell("", 5).Create("CFOP")
                    .HorizontalCenter()
                    .VerticalCenter()
                    .Colspan(2)
                    .BorderBuilder(true, true, true, true)
                    .Standard());
            pdfTable2.AddCell(
                new BuilderCell("", 5).Create("UN")
                    .HorizontalCenter()
                    .VerticalCenter()
                    .Colspan(1)
                    .BorderBuilder(true, true, true, true)
                    .Standard());
            pdfTable2.AddCell(
                new BuilderCell("", 5).Create("QUANT")
                    .HorizontalCenter()
                    .VerticalCenter()
                    .Colspan(2)
                    .BorderBuilder(true, true, true, true)
                    .Standard());
            pdfTable2.AddCell(
                new BuilderCell("", 5).Create("VALOR UNIT")
                    .HorizontalCenter()
                    .VerticalCenter()
                    .Colspan(2)
                    .BorderBuilder(true, true, true, true)
                    .Standard());
            pdfTable2.AddCell(
                new BuilderCell("", 5).Create("VALOR TOTAL")
                    .HorizontalCenter()
                    .VerticalCenter()
                    .Colspan(2)
                    .BorderBuilder(true, true, true, true)
                    .Standard());
            pdfTable2.AddCell(
                new BuilderCell("", 5).Create("B.CÁLC ICMS")
                    .HorizontalCenter()
                    .VerticalCenter()
                    .Colspan(2)
                    .BorderBuilder(true, true, true, true)
                    .Standard());
            pdfTable2.AddCell(
                new BuilderCell("", 5).Create("VALOR ICMS")
                    .HorizontalCenter()
                    .VerticalCenter()
                    .Colspan(2)
                    .BorderBuilder(true, true, true, true)
                    .Standard());
            pdfTable2.AddCell(
                new BuilderCell("", 5).Create("VALOR IPI")
                    .HorizontalCenter()
                    .VerticalCenter()
                    .Colspan(2)
                    .BorderBuilder(true, true, true, true)
                    .Standard());
            pdfTable2.AddCell(
                new BuilderCell("", 5).Create("ALIQ ICMS")
                    .HorizontalCenter()
                    .VerticalCenter()
                    .Colspan(2)
                    .BorderBuilder(true, true, true, true)
                    .Standard());
            pdfTable2.AddCell(
                new BuilderCell("", 5).Create("ALIQ IPI")
                    .HorizontalCenter()
                    .VerticalCenter()
                    .Colspan(2)
                    .BorderBuilder(true, true, true, true)
                    .Standard());
            return pdfTable2;
        }