private void Crear_Archivo(int intTotalPaginas)
    {
        Font ftProductos = new Font(FontFactory.GetFont(FontFactory.HELVETICA, 7, Font.NORMAL));

        int intMaxWidth = 190, intMaxHeight = 50, intLogoWidth, intLogoHeight;
        HttpCookie ckSIAN = Request.Cookies["userCng"];
        int intNombreLogo = ckSIAN["ck_logo"].LastIndexOf("/") + 1;
        string[] strSize = ckSIAN["ck_logo_size"].Split('x');
        intLogoWidth = int.Parse(strSize[0]);
        intLogoHeight = int.Parse(strSize[1]);
        float flRelacion = CRutinas.Calcular_Relacion(intMaxWidth, intMaxHeight, intLogoWidth, intLogoHeight);

        MyPageEvents events = new MyPageEvents();
        events.strMapPath = Server.MapPath("../imagenes") + "/";
        events.strLogoEmpresa = ckSIAN["ck_logo"].Substring(intNombreLogo);
        events.flEscala = flRelacion * 100;

        events.strCotizacion = this.strCotizacion;

        events.strRazonSocial = this.strRazonSocial;
        events.strRFC = this.strRFC;
        events.strTelefono = this.strTelefono;
        events.strEmail = this.strEmail;
        events.objDirEmisor = this.objDirEmisor;
        events.strNumeroCliente = this.strNumeroCliente;
        events.strCliente = this.strCliente;
        events.strClienteRFC = this.strClienteRFC;
        events.strDiasCredito = this.strDiasCredito;
        events.objDirReceptor = this.objDirReceptor;
        events.objEnvio = this.objEnvio;
        events.strEjecutivoVentas = this.strEjecutivoVentas;
        events.dtFecha = this.dtFecha;
        events.strNota = this.strNota;
        events.strOrdenCompra = this.strOrdenCompra;
        events.strContacto = this.strContacto;

        events.dcmSubtotal = this.dcmSubtotal;
        events.dcmDescuento = this.dcmDescuento;
        events.dcmIVA = this.dcmIVA;
        events.dcmTotal = this.dcmTotal;
        events.strMoneda = this.strMoneda;

        events.intTotalPaginas = intTotalPaginas;

        string strArchivoFormato = Server.MapPath("remision_ipisa.pdf");
        PdfReader pdfEntrada = new PdfReader(strArchivoFormato);

        MemoryStream m = new MemoryStream();
        Document document = new Document(
            new Rectangle(PageSize.LETTER.Width, PageSize.LETTER.Height));
        // 1 in = 25.4 mm = 72 points
        document.SetMargins(32.0f, 32.0f, 290.0f, 135.0f);

        Response.ContentType = "application/pdf";
        PdfWriter writer;

        string strArchivo = "remision_" + Request.QueryString["notID"] + ".pdf";
        if (Request.QueryString["m"] == null)
        {
            writer = PdfWriter.GetInstance(document, m);
            writer.CloseStream = false;
        }
        else
        {
            FileStream flArchivo = new FileStream(Server.MapPath("../xml_facturas" + HttpContext.Current.Request.ApplicationPath + "/" + strArchivo), FileMode.Create);
            writer = PdfWriter.GetInstance(document, flArchivo);
        }

        writer.PageEvent = events;

        events.pdfPage1 = writer.GetImportedPage(pdfEntrada, 1);

        document.Open();

        float[] ancho_columnas = new float[6];
        ancho_columnas[0] = 50;
        ancho_columnas[1] = 75;
        ancho_columnas[2] = 242;
        ancho_columnas[3] = 63;
        ancho_columnas[4] = 62;
        ancho_columnas[5] = 74;

        char tab = '\u0009';

        foreach (CProducto objProducto in this.lstProductos)
        {
            PdfPTable tblLinea = new PdfPTable(ancho_columnas);
            tblLinea.TotalWidth = 532;
            tblLinea.DefaultCell.Border = Rectangle.NO_BORDER;
            tblLinea.HorizontalAlignment = Element.ALIGN_LEFT;
            tblLinea.LockedWidth = true;

            Paragraph texto = new Paragraph(string.Empty, ftProductos);
            PdfPCell celda = new PdfPCell(texto);
            celda.HorizontalAlignment = Element.ALIGN_RIGHT;
            celda.Border = Rectangle.NO_BORDER;
            tblLinea.AddCell(celda);

            texto = new Paragraph(objProducto.StrCodigo, ftProductos);
            celda = new PdfPCell(texto);
            celda.HorizontalAlignment = Element.ALIGN_LEFT;
            celda.Border = Rectangle.NO_BORDER;
            tblLinea.AddCell(celda);

            if (!string.IsNullOrEmpty(objProducto.StrDetalle))
                texto = new Paragraph(objProducto.StrDescripcion + "\n" + objProducto.StrDetalle.Replace(tab.ToString(), "    "), ftProductos);
            else
                texto = new Paragraph(objProducto.StrDescripcion, ftProductos);
            celda = new PdfPCell(texto);
            celda.HorizontalAlignment = Element.ALIGN_LEFT;
            celda.Border = Rectangle.NO_BORDER;
            if (objProducto.IntGrupoID == 0)
                celda.PaddingLeft = 0;
            else
                celda.PaddingLeft = 10;
            tblLinea.AddCell(celda);

            texto = new Paragraph((objProducto.SwKit ? string.Empty : objProducto.AmtCantidad.ToString("0.##")), ftProductos);
            celda = new PdfPCell(texto);
            celda.HorizontalAlignment = Element.ALIGN_RIGHT;
            celda.Border = Rectangle.NO_BORDER;
            tblLinea.AddCell(celda);

            texto = new Paragraph((objProducto.SwKit ? string.Empty : objProducto.AmtValorUnitario.ToString("c")), ftProductos);
            celda = new PdfPCell(texto);
            celda.HorizontalAlignment = Element.ALIGN_RIGHT;
            celda.Border = Rectangle.NO_BORDER;
            tblLinea.AddCell(celda);

            texto = new Paragraph((objProducto.SwKit ? string.Empty : objProducto.AmtImporte.ToString("c")), ftProductos);
            celda = new PdfPCell(texto);
            celda.HorizontalAlignment = Element.ALIGN_RIGHT;
            celda.Border = Rectangle.NO_BORDER;
            tblLinea.AddCell(celda);

            document.Add(tblLinea);
        }

        document.Close();
        if (Request.QueryString["m"] == null)
        {
            Response.OutputStream.Write(m.GetBuffer(), 0, m.GetBuffer().Length);
            Response.OutputStream.Flush();
            Response.OutputStream.Close();
            Response.End();
            m.Close();
        }
        else
            Response.Redirect("cotizacion_correo.aspx?t=c&c=" + Request.QueryString["notID"] +
                                                     "&f=" + strArchivo);
    }
Ejemplo n.º 2
0
    private void Crear_Archivo(int intTotalPaginas)
    {
        int        intMaxWidth = 190, intMaxHeight = 50, intLogoWidth, intLogoHeight;
        HttpCookie ckSIAN        = Request.Cookies["userCng"];
        int        intNombreLogo = ckSIAN["ck_logo"].LastIndexOf("/") + 1;

        string[] strSize = ckSIAN["ck_logo_size"].Split('x');
        intLogoWidth  = int.Parse(strSize[0]);
        intLogoHeight = int.Parse(strSize[1]);
        float flRelacion = CRutinas.Calcular_Relacion(intMaxWidth, intMaxHeight, intLogoWidth, intLogoHeight);

        Font ftProductos = new Font(FontFactory.GetFont(FontFactory.HELVETICA, 6, Font.NORMAL));

        MyPageEvents events = new MyPageEvents();

        events._strNotaID                  = strNotaID;
        events._strContacto                = strContacto;
        events._strCertificado             = objFactura.StrCertificadoSAT;
        events._strFolioFiscal             = objFactura.StrFolioFiscal;
        events._strSelloCFDI               = objFactura.StrSelloCFDI;
        events._strSelloSAT                = objFactura.StrSelloSAT;
        events._strCadenaOriginal          = "N/A";
        events._intFolio                   = objFactura.IntFolio;
        events._dtFechaCertificado         = objFactura.DtFechaCertificado;
        events._intNoAprobacion            = objFactura.IntNoAprobacion;
        events._intAnoAprobacion           = objFactura.IntAnoAprobacion;
        events._strMetodoDePago            = objFactura.StrMetodoDePago;
        events._strCondicionesDePago       = objFactura.StrCondicionesDePago;
        events._amtSubTotal                = objFactura.AmtSubTotal;
        events._amtDescuento               = objFactura.AmtDescuento;
        events._amtTotal                   = objFactura.AmtTotal;
        events._strTotalLetras             = CRutinas.ObtenerImporteLetras(objFactura.AmtTotal, objFactura.StrMoneda);
        events._strRFCEmisor               = objFactura.StrRFCEmisor;
        events._strNombreEmisor            = objFactura.StrNombreEmisor;
        events._dirDomicilioFiscal         = objFactura.DirDomicilioFiscal;
        events._dirDomicilioExpedicion     = objFactura.DirDomicilioExpedicion;
        events._strRFCCliente              = objFactura.StrRFCCliente;
        events._strNombreCliente           = objFactura.StrNombreCliente;
        events._strCedulaFiscalCliente     = objFactura.StrCedulaFiscalCliente;
        events._strCedulaIEPSCliente       = objFactura.StrCedulaIEPSCliente;
        events._dirDomicilioCliente        = objFactura.DirDomicilioCliente;
        events._amtTotalImpuestosRetenidos = objFactura.AmtTotalImpuestosRetenidos;
        events._amtImpuesto                = objFactura.AmtImpuesto;
        events._amtTasa           = objFactura.AmtTasa;
        events._amtImporte        = objFactura.AmtImporte;
        events._amtTotalImpuestos = objFactura.AmtTotalImpuestos;
        events._strMapPath        = Server.MapPath("../imagenes") + "/";
        events._strLogoEmpresa    = ckSIAN["ck_logo"].Substring(intNombreLogo);
        events._flEscala          = flRelacion * 100;
        events._intTotalPaginas   = intTotalPaginas;
        events._strOrdenCompra    = string.Empty;
        events._strProveedor      = strProveedor;
        events._strVendedor       = strVendedor;

        MemoryStream m        = new MemoryStream();
        Document     document = new Document(
            new Rectangle(PageSize.LETTER.Width, PageSize.LETTER.Height));

        // 1 in = 25.4 mm = 72 points
        document.SetMargins(32.0f, 32.0f, 205.0f, 150.0f);

        Response.ContentType = "application/pdf";
        PdfWriter writer = PdfWriter.GetInstance(document, m);

        writer.CloseStream = false;
        writer.PageEvent   = events;

        document.Open();

        float[] ancho_columnas = new float[5];
        ancho_columnas[0] = 60;
        ancho_columnas[1] = 10;
        ancho_columnas[2] = 335;
        ancho_columnas[3] = 73;
        ancho_columnas[4] = 60;

        foreach (CProducto objProducto in objFactura.LstProductos)
        {
            PdfPTable tblLinea = new PdfPTable(ancho_columnas);
            tblLinea.TotalWidth          = 548;
            tblLinea.DefaultCell.Border  = Rectangle.NO_BORDER;
            tblLinea.HorizontalAlignment = Element.ALIGN_LEFT;
            tblLinea.LockedWidth         = true;
            Paragraph texto = new Paragraph((objProducto.SwKit ? string.Empty : objProducto.AmtCantidad.ToString("0.##")), ftProductos);
            PdfPCell  celda = new PdfPCell(texto);
            celda.HorizontalAlignment = Element.ALIGN_RIGHT;
            celda.Border = Rectangle.NO_BORDER;
            tblLinea.AddCell(celda);

            texto = new Paragraph(string.Empty, ftProductos);
            celda = new PdfPCell(texto);
            celda.HorizontalAlignment = Element.ALIGN_LEFT;
            celda.Border = Rectangle.NO_BORDER;
            tblLinea.AddCell(celda);

            texto = new Paragraph(objProducto.StrDescripcion, ftProductos);
            celda = new PdfPCell(texto);
            celda.HorizontalAlignment = Element.ALIGN_LEFT;
            celda.Border = Rectangle.NO_BORDER;
            if (objProducto.IntGrupoID == 0)
            {
                celda.PaddingLeft = 0;
            }
            else
            {
                celda.PaddingLeft = 10;
            }
            tblLinea.AddCell(celda);

            texto = new Paragraph((objProducto.SwKit ? string.Empty : objProducto.AmtValorUnitario.ToString("c")), ftProductos);
            celda = new PdfPCell(texto);
            celda.HorizontalAlignment = Element.ALIGN_RIGHT;
            celda.Border = Rectangle.NO_BORDER;
            tblLinea.AddCell(celda);

            texto = new Paragraph((objProducto.SwKit ? string.Empty : objProducto.AmtImporte.ToString("c")), ftProductos);
            celda = new PdfPCell(texto);
            celda.HorizontalAlignment = Element.ALIGN_RIGHT;
            celda.Border = Rectangle.NO_BORDER;
            tblLinea.AddCell(celda);

            document.Add(tblLinea);
        }

        document.Close();
        Response.OutputStream.Write(m.GetBuffer(), 0, m.GetBuffer().Length);
        Response.OutputStream.Flush();
        Response.OutputStream.Close();
        Response.End();
        m.Close();
    }