public void Gera(string arquivo, Cabecalho2_Pedido cab2, cOrcamentoPDF pdf_orcamento, bool mostrar_valores, bool mostrar_subcodigo)
        {
            FileStream fs;

            try
            {
                fs = new FileStream(arquivo, FileMode.Create);
            }
            catch
            {
                return;
            }
            doc    = new Document(PageSize.LETTER.Rotate());
            writer = PdfWriter.GetInstance(doc, fs);
            doc.Open();
            Parte1();
            Parte2(cab2);
            Parte3(pdf_orcamento.areas, mostrar_valores);
            Parte4(cab2, mostrar_valores);
            doc.Close();
            fs.Close();
        }
        private void Parte4(Cabecalho2_Pedido cab2, bool mostrar_valores)
        {
            Chunk  chunk;
            Celula cell;
            Tabela table = new Tabela(31);

            // linha1
            cell         = new Celula(Frase("", 10));
            cell.Colspan = mostrar_valores ? 22 : 31;
            table.AddCell(cell);

            if (mostrar_valores)
            {
                chunk        = new Chunk("TOTAL GERAL COM IPI", FontFactory.GetFont(BaseFont.HELVETICA, 10));
                cell         = new Celula(new Phrase(chunk));
                cell.Colspan = 6;
                table.AddCell(cell);

                chunk = new Chunk(total.ToString("###,###,##0.00"), FontFactory.GetFont(BaseFont.HELVETICA_BOLD, 10));
                cell  = new Celula(new Phrase(chunk));
                cell.HorizontalAlignment = Element.ALIGN_RIGHT;
                cell.BorderWidth         = 1;
                cell.Colspan             = 3;
                table.AddCell(cell);
            }

            // linha2
            chunk        = new Chunk("No PEDIDO REPRESENTANTE", FontFactory.GetFont(BaseFont.HELVETICA, 10));
            cell         = new Celula(new Phrase(chunk));
            cell.Colspan = 4;
            table.AddCell(cell);

            chunk                    = new Chunk(NRO_PEDIDO.ToString(), FontFactory.GetFont(BaseFont.HELVETICA_BOLD, 10));
            cell                     = new Celula(new Phrase(chunk));
            cell.Colspan             = 4;
            cell.BorderWidth         = 1;
            cell.HorizontalAlignment = Element.ALIGN_CENTER;
            table.AddCell(cell);

            cell         = new Celula(new Phrase(""));
            cell.Colspan = 1;
            table.AddCell(cell);

            chunk        = new Chunk("No O.C. CLIENTE", FontFactory.GetFont(BaseFont.HELVETICA, 10));
            cell         = new Celula(new Phrase(chunk));
            cell.Colspan = 4;
            table.AddCell(cell);

            cell             = new Celula(new Phrase(""));
            cell.Colspan     = 4;
            cell.BorderWidth = 1;
            table.AddCell(cell);

            cell         = new Celula(new Phrase(""));
            cell.Colspan = 1;
            table.AddCell(cell);

            chunk        = new Chunk("No PED ESPECIAL", FontFactory.GetFont(BaseFont.HELVETICA, 10));
            cell         = new Celula(new Phrase(chunk));
            cell.Colspan = 5;
            table.AddCell(cell);

            cell             = new Celula(new Phrase(""));
            cell.Colspan     = 4;
            cell.BorderWidth = 1;
            table.AddCell(cell);

            cell         = new Celula(new Phrase(""));
            cell.Colspan = 4;
            table.AddCell(cell);

            // linha3
            string observacao = cab2.observacao;

            string[] linhas = observacao.Split('\n');
            int      lin    = 0;

            foreach (string linha in linhas)
            {
                if (++lin == 1)
                {
                    chunk = new Chunk("OBS: ", FontFactory.GetFont(BaseFont.HELVETICA, 10));
                }
                else
                {
                    chunk = new Chunk("", FontFactory.GetFont(BaseFont.HELVETICA, 10));
                }
                cell                   = new Celula(new Phrase(chunk));
                cell.Colspan           = 2;
                cell.VerticalAlignment = Element.ALIGN_BOTTOM;
                table.AddCell(cell);

                chunk                  = new Chunk(linha, FontFactory.GetFont(BaseFont.HELVETICA, 10));
                cell                   = new Celula(new Phrase(chunk));
                cell.Colspan           = 29;
                cell.VerticalAlignment = Element.ALIGN_BOTTOM;
                cell.BorderWidthBottom = 1;
                table.AddCell(cell);
            }

/*
 *                      chunk = new Chunk("OBS:", FontFactory.GetFont(BaseFont.HELVETICA, 10));
 *                      cell = new Celula(new Phrase(chunk));
 *                      cell.Colspan = 2;
 *                      cell.VerticalAlignment = Element.ALIGN_BOTTOM;
 *                      table.AddCell(cell);
 *
 *                      chunk = new Chunk(cab2.observacao, FontFactory.GetFont(BaseFont.HELVETICA, 10));
 *                      cell = new Celula(new Phrase(chunk));
 *                      cell.Colspan = 29;
 *                      cell.BorderWidthBottom = 1;
 *                      table.AddCell(cell);
 *
 *                      // linha4
 *                      cell = new Celula(new Phrase(""));
 *                      cell.Colspan = 31;
 *                      cell.BorderWidthBottom = 1;
 *                      table.AddCell(cell);
 */
            // linha5
            cell         = new Celula(new Phrase(""));
            cell.Colspan = 31;
            table.AddCell(cell);

            chunk        = new Chunk("PEDIDO APROVADO", FontFactory.GetFont(BaseFont.HELVETICA, 10));
            cell         = new Celula(new Phrase(chunk));
            cell.Colspan = 5;
            table.AddCell(cell);

            cell             = new Celula(new Phrase(""));
            cell.Colspan     = 1;
            cell.BorderWidth = 1;
            table.AddCell(cell);

            chunk        = new Chunk("SIM", FontFactory.GetFont(BaseFont.HELVETICA, 10));
            cell         = new Celula(new Phrase(chunk));
            cell.Colspan = 2;
            table.AddCell(cell);

            cell             = new Celula(new Phrase(""));
            cell.Colspan     = 1;
            cell.BorderWidth = 1;
            table.AddCell(cell);

            chunk        = new Chunk("NÃO", FontFactory.GetFont(BaseFont.HELVETICA, 10));
            cell         = new Celula(new Phrase(chunk));
            cell.Colspan = 2;
            table.AddCell(cell);

            chunk                  = new Chunk("ASS. CLIENTE:", FontFactory.GetFont(BaseFont.HELVETICA, 10));
            cell                   = new Celula(new Phrase(chunk));
            cell.Colspan           = 4;
            cell.VerticalAlignment = Element.ALIGN_BOTTOM;
            table.AddCell(cell);

            cell                   = new Celula(new Phrase(""));
            cell.Colspan           = 6;
            cell.BorderWidthBottom = 1;
            table.AddCell(cell);

            chunk                  = new Chunk("ASS. REPRES:", FontFactory.GetFont(BaseFont.HELVETICA, 10));
            cell                   = new Celula(new Phrase(chunk));
            cell.Colspan           = 4;
            cell.VerticalAlignment = Element.ALIGN_BOTTOM;
            table.AddCell(cell);

            cell                   = new Celula(new Phrase(""));
            cell.Colspan           = 6;
            cell.BorderWidthBottom = 1;
            table.AddCell(cell);

            doc.Add(table);
        }
        private void Parte2(Cabecalho2_Pedido cab2)
        {
            Tabela table = new Tabela(31);
            Celula cell;

            // linha1
            cell         = new Celula(Frase("CLIENTE: ", cab2.cliente, 10));
            cell.Colspan = 22;
            table.AddCell(cell);

            cell         = new Celula(Frase("CONTATO: ", cab2.contato, 10));
            cell.Colspan = 22;
            table.AddCell(cell);

            // linha2
            cell         = new Celula(Frase("ENDEREÇO: ", cab2.endereco + "," + cab2.numero, 10));
            cell.Colspan = 22;
            table.AddCell(cell);

            cell         = new Celula(Frase("E-mail: ", cab2.email, 10));
            cell.Colspan = 9;
            table.AddCell(cell);

            // linha3
            cell         = new Celula(Frase("BAIRRO: ", cab2.bairro, 10));
            cell.Colspan = 11;
            table.AddCell(cell);

            cell         = new Celula(Frase("CIDADE: ", cab2.cidade, 10));
            cell.Colspan = 11;
            table.AddCell(cell);

            cell         = new Celula(Frase("UF: ", cab2.estado, 10));
            cell.Colspan = 5;
            table.AddCell(cell);

            cell         = new Celula(Frase("CEP: ", CEP.PoeEdicao(cab2.cep), 10));
            cell.Colspan = 4;
            table.AddCell(cell);

            // linha4
            cell         = new Celula(Frase("CNPJ: ", cab2.cnpj, 10));
            cell.Colspan = 11;
            table.AddCell(cell);

            cell         = new Celula(Frase("INCRIÇÃO ESTADUAL: ", cab2.ie, 10));
            cell.Colspan = 16;
            table.AddCell(cell);

            cell         = new Celula(Frase("FONE: ", FONE.PoeEdicao(cab2.fone), 10));
            cell.Colspan = 4;
            table.AddCell(cell);

            // linha4
            if (cab2.entrega.Trim().Length > 0)
            {
                cell = new Celula(Frase("LOCAL DE ENTREGA: ",
                                        cab2.entrega.Trim() + "," + cab2.numero_entrega.Trim() + " - " +
                                        cab2.compl_entrega.Trim() + " - " +
                                        cab2.bairro_entrega.Trim() + " - " + cab2.cidade_entrega.Trim() +
                                        cab2.estado_entrega.Trim() + " - " +
                                        CEP.PoeEdicao(cab2.cep_entrega), 10));
            }
            else
            {
                cell = new Celula(Frase("LOCAL DE ENTREGA: ", "IDEM", 10));
            }
            cell.Colspan = 31;
            table.AddCell(cell);

            // linha5
            if (cab2.cobranca.Trim().Length > 0)
            {
                cell = new Celula(Frase("LOCAL DE COBRANÇA: ",
                                        cab2.cobranca.Trim() + "," + cab2.numero_cobranca.Trim() + " - " +
                                        cab2.compl_cobranca.Trim() + " - " +
                                        cab2.bairro_cobranca.Trim() + " - " + cab2.cidade_cobranca.Trim() +
                                        cab2.estado_cobranca.Trim() + " - " +
                                        CEP.PoeEdicao(cab2.cep_cobranca), 10));
            }
            else
            {
                cell = new Celula(Frase("LOCAL DE COBRANÇA: ", "IDEM", 10));
            }
            cell.Colspan = 31;
            table.AddCell(cell);

            // linha6
            cell         = new Celula(Frase("FRETE: % ", 10));
            cell.Colspan = 5;
            table.AddCell(cell);

            if (IDT_FRETE == 'C')
            {
                cell = new Celula(new Phrase(""));
            }
            else
            {
                Chunk chunk = new Chunk("X", FontFactory.GetFont(BaseFont.HELVETICA_BOLD, 16));
                cell = new Celula(new Phrase(chunk));
            }
            cell.Colspan     = 1;
            cell.BorderWidth = 1;
            table.AddCell(cell);

            cell         = new Celula(Frase("FORNECEDOR", 10));
            cell.Colspan = 4;
            table.AddCell(cell);

            if (IDT_FRETE == 'C')
            {
                Chunk chunk = new Chunk("X", FontFactory.GetFont(BaseFont.HELVETICA_BOLD, 16));
                cell = new Celula(new Phrase(chunk));
            }
            else
            {
                cell = new Celula(new Phrase(""));
            }
            cell.Colspan     = 1;
            cell.BorderWidth = 1;
            table.AddCell(cell);

            cell         = new Celula(Frase("CLIENTE", 10));
            cell.Colspan = 4;
            table.AddCell(cell);

            cell         = new Celula(Frase("TRANSPORTADORA: ", "", 10));
            cell.Colspan = 12;
            table.AddCell(cell);

            cell         = new Celula(Frase("FONE: ", "", 10));
            cell.Colspan = 5;
            table.AddCell(cell);

            // linha7
            cell         = new Celula(Frase("CONDIÇÕES DE PAGAMENTO: ", "", 10));
            cell.Colspan = 8;
            table.AddCell(cell);

            cell         = new Celula(Frase("SINAL-R$ ", "", 10));
            cell.Colspan = 5;
            table.AddCell(cell);

            cell         = new Celula(Frase("PARCELAS 1-R$ ", "", 10));
            cell.Colspan = 6;
            table.AddCell(cell);

            cell         = new Celula(Frase("2-R$ ", "", 10));
            cell.Colspan = 4;
            table.AddCell(cell);

            cell         = new Celula(Frase("3-R$ ", "", 10));
            cell.Colspan = 4;
            table.AddCell(cell);

            cell         = new Celula(Frase("4-R$ ", "", 10));
            cell.Colspan = 4;
            table.AddCell(cell);

            // linha8
            cell         = new Celula(Frase("SAÍDA DA FÁBRICA: ", "", 10));
            cell.Colspan = 19;
            table.AddCell(cell);

            cell         = new Celula(Frase("DESCONTO: ", "", 10));
            cell.Colspan = 5;
            table.AddCell(cell);

            cell         = new Celula(Frase("ENC FINANCEIRO: ", "", 10));
            cell.Colspan = 7;
            table.AddCell(cell);
            doc.Add(table);
        }