private static string PrintCanhoto(TNFeInfNFeEmit emit, PdfPTable pdfTable, TNFeInfNFeIde ide, out string serie)
        {
            string msg =
                string.Format(
                    "RECEBEMOS DE {0} OS PRODUTOS E/OU SERVIÇOS CONSTANTES DA NOTA FISCAL ELETRONICA INDICADA ABAIXO.",
                    emit.xNome);
            pdfTable.AddCell(new BuilderCell("", 7).Create(msg).Colspan(16).Rowspan(2).Standard());
            pdfTable.AddCell(
                new BuilderCell().Create("NF-e")
                    .Colspan(3)
                    .Bold()
                    .HorizontalCenter()
                    .BorderBuilder(true, true, false, true)
                    .Standard());

            string nfNr = string.Format("Nº. {0}", ide.nNF);
            pdfTable.AddCell(
                new BuilderCell().Create(nfNr)
                    .Colspan(3)
                    .Bold()
                    .HorizontalCenter()
                    .BorderBuilder(true, true, false, false)
                    .Standard());

            pdfTable.AddCell(new BuilderCell("", 5).Create("DATA DE RECEBIMENTO").Colspan(4).Rowspan(2).VerticalTop().Standard());
            pdfTable.AddCell(
                new BuilderCell("", 5).Create("IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR")
                    .VerticalTop()
                    .Colspan(12)
                    .Rowspan(2)
                    .Standard());
            serie = string.Format("Série {0}", ide.serie);
            pdfTable.AddCell(
                new BuilderCell().Create(serie)
                    .Colspan(3)
                    .Rowspan(2)
                    .Bold()
                    .BorderBuilder(true, true, false, false)
                    .HorizontalCenter()
                    .FixedHeight(20)
                    .Standard());

            var separator = new DottedLineSeparator {Percentage = 100};
            var cellfields =
                new BuilderCell().Create(string.Empty)
                    .Colspan(19)
                    .Rowspan(2)
                    .FixedHeight(10)
                    .HorizontalCenter()
                    .VerticalCenter()
                    .NoBorder()
                    .BorderBuilder(false, false, false, true)
                    .Standard();
            cellfields.AddElement(separator);
            pdfTable.AddCell(cellfields);
            return nfNr;
        }
        private static void PrintDestinatario(PdfPTable pdfTable, TNFeInfNFeDest dest, TNFeInfNFeIde ide)
        {
            pdfTable.AddCell(
                new BuilderCell("", 5).Create("DESTINATÁRIO/REMETENTE")
                    .Bold()
                    .HorizontalLeft()
                    .VerticalBottom()
                    .Colspan(19)
                    .NoBorder()
                    .BorderBuilder(false, false, false, true)
                    .Standard());

            pdfTable.AddCell(
                new BuilderCell("", 5).Create("NOME/RAZÃO SOCIAL")
                    .HorizontalLeft()
                    .VerticalTop()
                    .Colspan(12)
                    .BorderBuilder(true, true, false, true)
                    .Standard());
            pdfTable.AddCell(
                new BuilderCell("", 5).Create("CNPJ/CPF")
                    .HorizontalLeft()
                    .VerticalTop()
                    .Colspan(4)
                    .BorderBuilder(true, true, false, true)
                    .Standard());
            pdfTable.AddCell(
                new BuilderCell("", 5).Create("DATA DA EMISSÃO")
                    .HorizontalLeft()
                    .VerticalTop()
                    .Colspan(3)
                    .BorderBuilder(true, true, false, true)
                    .Standard());

            pdfTable.AddCell(
                new BuilderCell("", 9).Create(dest.xNome)
                    .VerticalCenter()
                    .HorizontalLeft()
                    .Bold()
                    .Colspan(12)
                    .NoBorder()
                    .BorderBuilder(true, true, false, false)
                    .Standard());
            pdfTable.AddCell(
                new BuilderCell("", 9).Create(CustomMasks.MaskCpfCnpj(dest.Item))
                    .VerticalCenter()
                    .HorizontalCenter()
                    .Bold()
                    .Colspan(4)
                    .NoBorder()
                    .BorderBuilder(true, true, false, false)
                    .Standard());
            pdfTable.AddCell(
                new BuilderCell("", 9).Create(CustomMasks.MaskDateTime(ide.dhEmi, false))
                    .VerticalCenter()
                    .HorizontalCenter()
                    .Bold()
                    .Colspan(3)
                    .NoBorder()
                    .BorderBuilder(true, true, false, false)
                    .Standard());

            pdfTable.AddCell(
                new BuilderCell("", 5).Create("ENDEREÇO")
                    .HorizontalLeft()
                    .VerticalTop()
                    .Colspan(9)
                    .BorderBuilder(true, true, false, true)
                    .Standard());
            pdfTable.AddCell(
                new BuilderCell("", 5).Create("BAIRRO/DISTRITO")
                    .HorizontalLeft()
                    .VerticalTop()
                    .Colspan(5)
                    .BorderBuilder(true, true, false, true)
                    .Standard());
            pdfTable.AddCell(
                new BuilderCell("", 5).Create("CEP")
                    .HorizontalLeft()
                    .VerticalTop()
                    .Colspan(2)
                    .BorderBuilder(true, true, false, true)
                    .Standard());
            pdfTable.AddCell(
                new BuilderCell("", 5).Create("DATA DA SAIDA")
                    .HorizontalLeft()
                    .VerticalTop()
                    .Colspan(3)
                    .BorderBuilder(true, true, false, true)
                    .Standard());

            var destEnd = !string.IsNullOrEmpty(dest.enderDest.xCpl)
                ? string.Format("{0}, {1} - {2}", dest.enderDest.xLgr, dest.enderDest.nro, dest.enderDest.xCpl)
                : string.Format("{0}, {1}", dest.enderDest.xLgr, dest.enderDest.nro);
            pdfTable.AddCell(
                new BuilderCell("", 9).Create(destEnd)
                    .VerticalCenter()
                    .HorizontalLeft()
                    .Bold()
                    .Colspan(9)
                    .NoBorder()
                    .BorderBuilder(true, true, false, false)
                    .Standard());
            pdfTable.AddCell(dest.enderDest.xBairro.Length > 15
                ? new BuilderCell("", 5).Create(dest.enderDest.xBairro)
                    .VerticalCenter()
                    .HorizontalCenter()
                    .Bold()
                    .Colspan(5)
                    .NoBorder()
                    .BorderBuilder(true, true, false, false)
                    .Standard()
                : new BuilderCell("", 9).Create(dest.enderDest.xBairro)
                    .VerticalCenter()
                    .HorizontalCenter()
                    .Bold()
                    .Colspan(5)
                    .NoBorder()
                    .BorderBuilder(true, true, false, false)
                    .Standard());
            pdfTable.AddCell(
                new BuilderCell("", 9).Create(CustomMasks.MaskCep(dest.enderDest.CEP))
                    .VerticalCenter()
                    .HorizontalCenter()
                    .Bold()
                    .Colspan(2)
                    .NoBorder()
                    .BorderBuilder(true, true, false, false)
                    .Standard());
            pdfTable.AddCell(
                new BuilderCell("", 9).Create(CustomMasks.MaskDateTime(ide.dhSaiEnt, false))
                    .VerticalCenter()
                    .HorizontalCenter()
                    .Bold()
                    .Colspan(3)
                    .NoBorder()
                    .BorderBuilder(true, true, false, false)
                    .Standard());
            pdfTable.AddCell(
                new BuilderCell("", 5).Create("MUNICÍPIO")
                    .HorizontalLeft()
                    .VerticalTop()
                    .Colspan(9)
                    .BorderBuilder(true, true, false, true)
                    .Standard());
            pdfTable.AddCell(
                new BuilderCell("", 5).Create("UF")
                    .HorizontalLeft()
                    .VerticalTop()
                    .Colspan(1)
                    .BorderBuilder(true, true, false, true)
                    .Standard());
            pdfTable.AddCell(
                new BuilderCell("", 5).Create("FONE/FAX")
                    .HorizontalLeft()
                    .VerticalTop()
                    .Colspan(3)
                    .BorderBuilder(true, true, false, true)
                    .Standard());
            pdfTable.AddCell(
                new BuilderCell("", 5).Create("INSCRIÇÃO ESTADUAL")
                    .HorizontalLeft()
                    .VerticalTop()
                    .Colspan(3)
                    .BorderBuilder(true, true, false, true)
                    .Standard());
            pdfTable.AddCell(
                new BuilderCell("", 5).Create("HORA DA SAIDA")
                    .HorizontalLeft()
                    .VerticalTop()
                    .Colspan(3)
                    .BorderBuilder(true, true, false, true)
                    .Standard());
            pdfTable.AddCell(
                new BuilderCell("", 9).Create(dest.enderDest.xMun)
                    .VerticalCenter()
                    .HorizontalLeft()
                    .Bold()
                    .Colspan(9)
                    .NoBorder()
                    .BorderBuilder(true, true, false, false)
                    .Standard());
            pdfTable.AddCell(
                new BuilderCell("", 9).Create(dest.enderDest.UF.ToString())
                    .VerticalCenter()
                    .HorizontalCenter()
                    .Bold()
                    .Colspan(1)
                    .NoBorder()
                    .BorderBuilder(true, true, false, false)
                    .Standard());
            pdfTable.AddCell(
                new BuilderCell("", 9).Create(dest.enderDest.fone)
                    .VerticalCenter()
                    .HorizontalCenter()
                    .Bold()
                    .Colspan(3)
                    .NoBorder()
                    .BorderBuilder(true, true, false, false)
                    .Standard());
            pdfTable.AddCell(
                new BuilderCell("", 9).Create(dest.IE)
                    .VerticalCenter()
                    .HorizontalCenter()
                    .Bold()
                    .Colspan(3)
                    .NoBorder()
                    .BorderBuilder(true, true, false, false)
                    .Standard());
            pdfTable.AddCell(
                new BuilderCell("", 9).Create(CustomMasks.MaskHora(ide.dhSaiEnt))
                    .VerticalCenter()
                    .HorizontalCenter()
                    .Bold()
                    .Colspan(3)
                    .NoBorder()
                    .BorderBuilder(true, true, false, false)
                    .Standard());
        }
        private static void PrintCabecalho(TProtNFeInfProt protocol, PdfPTable pdfTable, TNFeInfNFeEmit emit, TNFeInfNFeIde ide,
            string nfNr, string serie)
        {
            var barcode = new Barcode(protocol.chNFe, TYPE.CODE128C);
            barcode.Encode(TYPE.CODE128C, protocol.chNFe, 300, 50);
            var byteImg = barcode.GetImageData(SaveTypes.JPG);
            var barCodeImg = Image.GetInstance(byteImg);

            pdfTable.AddCell(
                new BuilderCell("", 5).Create("IDENTIFICAÇÃO DO EMITENTE")
                    .HorizontalCenter()
                    .VerticalTop()
                    .Colspan(9)
                    .NoBorder()
                    .BorderBuilder(true, true, false, true)
                    .Standard());
            pdfTable.AddCell(
                new BuilderCell("", 12).Create("DANFE")
                    .Bold()
                    .HorizontalCenter()
                    .VerticalBottom()
                    .Colspan(4)
                    .NoBorder()
                    .BorderBuilder(true, true, false, true)
                    .Standard());
            var barCodeCellfields =
                new BuilderCell().Create(string.Empty).HorizontalCenter().VerticalCenter().Colspan(6).Rowspan(3).Standard();
            barCodeCellfields.AddElement(barCodeImg);
            pdfTable.AddCell(barCodeCellfields);

            pdfTable.AddCell(
                new BuilderCell("", 5).Create(" ").Colspan(9).NoBorder().BorderBuilder(true, true, false, false).Standard());
            pdfTable.AddCell(
                new BuilderCell("", 8).Create("Documento Auxiliar da Nota Fiscal Eletrônica")
                    .HorizontalCenter()
                    .VerticalTop()
                    .Colspan(4)
                    .NoBorder()
                    .BorderBuilder(true, true, false, false)
                    .Standard());

            pdfTable.AddCell(
                new BuilderCell("", 11).Create(emit.xNome)
                    .HorizontalCenter()
                    .Colspan(9)
                    .NoBorder()
                    .BorderBuilder(true, true, false, false)
                    .Standard());
            pdfTable.AddCell(
                new BuilderCell("", 10).Create("0 - ENTRADA")
                    .VerticalBottom()
                    .Colspan(3)
                    .NoBorder()
                    .BorderBuilder(true, true, false, false)
                    .Standard());
            pdfTable.AddCell(
                new BuilderCell("", 12).Create(ide.tpNF.ToString().Equals("Item1") ? "1" : "0")
                    .Bold()
                    .HorizontalCenter()
                    .VerticalCenter()
                    .Colspan(1)
                    .Rowspan(2)
                    .Standard());

            string endereçoEmit = string.Format("{0}, {1} - {2}", emit.enderEmit.xLgr, emit.enderEmit.nro, emit.enderEmit.xCpl);
            pdfTable.AddCell(
                new BuilderCell("", 8).Create(endereçoEmit)
                    .HorizontalCenter()
                    .Colspan(9)
                    .NoBorder()
                    .BorderBuilder(true, true, false, false)
                    .Standard());
            pdfTable.AddCell(
                new BuilderCell("", 10).Create("1 - SAIDA")
                    .VerticalTop()
                    .Colspan(3)
                    .NoBorder()
                    .BorderBuilder(true, true, false, false)
                    .Standard());
            pdfTable.AddCell(
                new BuilderCell("", 5).Create("CHAVE DE ACESSO")
                    .HorizontalLeft()
                    .VerticalTop()
                    .Colspan(6)
                    .NoBorder()
                    .BorderBuilder(true, true, false, true)
                    .Standard());

            string bairroCep = string.Format("{0} - {1}", emit.enderEmit.xBairro, emit.enderEmit.CEP);
            pdfTable.AddCell(
                new BuilderCell("", 8).Create(bairroCep)
                    .HorizontalCenter()
                    .Colspan(9)
                    .NoBorder()
                    .BorderBuilder(true, true, false, false)
                    .Standard());
            pdfTable.AddCell(
                new BuilderCell("", 10).Create(nfNr)
                    .Bold()
                    .VerticalBottom()
                    .HorizontalCenter()
                    .Colspan(4)
                    .NoBorder()
                    .BorderBuilder(true, true, false, false)
                    .Standard());
            pdfTable.AddCell(
                new BuilderCell("", 6).Create(CustomMasks.MaskNfeId(protocol.chNFe))
                    .Bold()
                    .HorizontalRight()
                    .VerticalTop()
                    .Colspan(6)
                    .NoBorder()
                    .BorderBuilder(true, true, true, false)
                    .Standard());

            string cityAndPhone = string.Format("{0}-{1} Fone/Fax: {2}", emit.enderEmit.xMun, emit.enderEmit.UF,
                emit.enderEmit.fone);
            pdfTable.AddCell(
                new BuilderCell("", 8).Create(cityAndPhone)
                    .HorizontalCenter()
                    .Colspan(9)
                    .NoBorder()
                    .BorderBuilder(true, true, false, false)
                    .Standard());
            pdfTable.AddCell(
                new BuilderCell("", 10).Create(serie)
                    .Bold()
                    .VerticalCenter()
                    .HorizontalCenter()
                    .Colspan(4)
                    .NoBorder()
                    .BorderBuilder(true, true, false, false)
                    .Standard());
            pdfTable.AddCell(
                new BuilderCell("", 6).Create(
                    "Consulta de autenticidade no portal nacional da NF-e www.nfe.fazenda.gov.br/portal ou no site da Sefaz Autorizadora")
                    .HorizontalCenter()
                    .VerticalCenter()
                    .Colspan(6)
                    .Rowspan(2)
                    .Standard());

            pdfTable.AddCell(
                new BuilderCell("", 8).Create(" ").Colspan(9).NoBorder().BorderBuilder(true, true, false, false).Standard());
            pdfTable.AddCell(
                new BuilderCell("", 8).Create(" ").Colspan(4).NoBorder().BorderBuilder(true, true, false, false).Standard());

            pdfTable.AddCell(
                new BuilderCell("", 5).Create("NATUREZA DA OPERAÇÃO")
                    .HorizontalLeft()
                    .VerticalTop()
                    .Colspan(13)
                    .BorderBuilder(true, true, false, true)
                    .Standard());
            pdfTable.AddCell(
                new BuilderCell("", 5).Create("PROTOCOLO DE AUTORIZAÇÃO DE USO")
                    .HorizontalLeft()
                    .VerticalTop()
                    .Colspan(6)
                    .BorderBuilder(true, true, false, true)
                    .Standard());

            string protocoloAutorizacao = string.Format("{0} - {1}", protocol.nProt,
                CustomMasks.MaskDateTime(protocol.dhRecbto, true));
            pdfTable.AddCell(
                new BuilderCell("", 9).Create(ide.natOp)
                    .VerticalCenter()
                    .HorizontalCenter()
                    .Bold()
                    .Colspan(13)
                    .NoBorder()
                    .BorderBuilder(true, true, false, false)
                    .Standard());
            pdfTable.AddCell(
                new BuilderCell("", 9).Create(protocoloAutorizacao)
                    .VerticalCenter()
                    .HorizontalCenter()
                    .Bold()
                    .Colspan(6)
                    .NoBorder()
                    .BorderBuilder(true, true, false, false)
                    .Standard());

            pdfTable.AddCell(
                new BuilderCell("", 5).Create("INSCRIÇÃO ESTADUAL")
                    .HorizontalLeft()
                    .VerticalTop()
                    .Colspan(7)
                    .BorderBuilder(true, true, false, true)
                    .Standard());
            pdfTable.AddCell(
                new BuilderCell("", 5).Create("INSCRIÇÃO ESTADUAL DO SUBST. TRIBUT")
                    .HorizontalLeft()
                    .VerticalTop()
                    .Colspan(6)
                    .BorderBuilder(true, true, false, true)
                    .Standard());
            pdfTable.AddCell(
                new BuilderCell("", 5).Create("CNPJ")
                    .HorizontalLeft()
                    .VerticalTop()
                    .Colspan(6)
                    .BorderBuilder(true, true, false, true)
                    .Standard());

            pdfTable.AddCell(
                new BuilderCell("", 9).Create(emit.IE)
                    .VerticalCenter()
                    .HorizontalCenter()
                    .Bold()
                    .Colspan(7)
                    .NoBorder()
                    .BorderBuilder(true, true, false, false)
                    .Standard());
            pdfTable.AddCell(
                new BuilderCell("", 9).Create(emit.IEST)
                    .VerticalCenter()
                    .HorizontalCenter()
                    .Bold()
                    .Colspan(6)
                    .NoBorder()
                    .BorderBuilder(true, true, false, false)
                    .Standard());
            pdfTable.AddCell(
                new BuilderCell("", 9).Create(CustomMasks.MaskCpfCnpj(emit.Item))
                    .VerticalCenter()
                    .HorizontalCenter()
                    .Bold()
                    .Colspan(6)
                    .NoBorder()
                    .BorderBuilder(true, true, false, false)
                    .Standard());
        }