Exemplo n.º 1
0
        public byte[] CreatePDF()
        {
            byte[] bytePDF = null;

            if (this.parameters != null)
            {
                this.reportDoc.SetParameters(parameters);

                if (this.tableCollection != null)
                {
                    foreach (DataTable table in this.tableCollection)
                    {
                        reportDoc.AddData(table);
                    }
                }

                if (this.Pictures != null)
                {
                    foreach (Picture picture in this.Pictures)
                    {
                        reportDoc.AddPicture(picture.Name, picture.Image, picture.Stretch);
                    }
                }

                bytePDF = reportDoc.SerializeToPdfStream();

                //this.response.ContentType = "application/pdf";
                //this.response.OutputStream.Write(bytePDF, 0, bytePDF.Length);
                //this.response.End();

                //this.reportDoc.Dispose();
            }

            return(bytePDF);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creazione dell'array di byte associato al PDF
        /// </summary>
        public byte[] CreateHTMLByte()
        {
            byte[] byteHTML = null;

            if (this.parameters != null)
            {
                this.reportDoc = new ReportDocument();
                this.reportDoc.SetParameters(parameters);
                this.reportDoc.setXML(tpuXML, tpuXML.DocumentElement.Name);
                if (this.tableCollection != null)
                {
                    foreach (DataTable table in this.tableCollection)
                    {
                        reportDoc.AddData(table);
                    }
                }

                if (this.Pictures != null)
                {
                    foreach (Picture picture in this.Pictures)
                    {
                        reportDoc.AddPicture(picture.Name, picture.Image, picture.Stretch);
                    }
                }
                byteHTML = reportDoc.SerializeToHtmlStream();
            }
            return(byteHTML);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creazione dell'array di byte associato al PDF
        /// </summary>
        public byte[] CreateImage()
        {
            byte[] bytePDF = null;

            if (this.parameters != null)
            {
                this.reportDoc = new ReportDocument();
                this.reportDoc.SetParameters(parameters);
                this.reportDoc.setXML(tpuXML, tpuXML.DocumentElement.Name);
                if (this.tableCollection != null)
                {
                    foreach (DataTable table in this.tableCollection)
                    {
                        reportDoc.AddData(table);
                    }
                }

                if (this.Pictures != null)
                {
                    foreach (Picture picture in this.Pictures)
                    {
                        reportDoc.AddPicture(picture.Name, picture.Image, picture.Stretch);
                    }
                }

                Image[]      images = reportDoc.SerializeToImages();
                Image        image  = images[0];
                MemoryStream ms     = new MemoryStream();
                image.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
                bytePDF = ms.ToArray();
            }

            return(bytePDF);
        }
Exemplo n.º 4
0
        public byte[] GetPdfTpuStampeTableBUS(XmlDocument tpu, XmlDocument pru)
        {
            ReportDocument document = new ReportDocument();

            document.setXML(tpu, tpu.DocumentElement.Name);
            System.IO.Stream str = null;
            Hashtable        ht  = new Hashtable();

            XmlDocument XMLData = new XmlDocument();

            XMLData.LoadXml(pru.OuterXml);

            // Estrae i valori dei parametri
            System.Xml.XmlNodeList nl = XMLData.SelectNodes("params/p");
            foreach (System.Xml.XmlNode xn in nl)
            {
                ht.Add(xn.Attributes["name"].Value, xn.InnerText);
            }

            document.SetParameters(ht);

            // Estrae le tabelle
            DataTable        dt          = new DataTable();
            StringCollection sCollection = new StringCollection();

            System.Xml.XmlNodeList nlt = XMLData.SelectNodes("params/t");
            foreach (System.Xml.XmlNode xn in nlt)
            {
                sCollection.Add(xn.InnerXml);
            }
            DataSet ds = new DataSet();

            System.IO.MemoryStream memStream;
            System.IO.StreamWriter sWriter;

            foreach (string tabella in sCollection)
            {
                ds.Tables.Clear();
                memStream = new System.IO.MemoryStream();
                sWriter   = new System.IO.StreamWriter(memStream);
                sWriter.Write(tabella);

                sWriter.Flush();
                memStream.Position = 0;

                ds.ReadXml(memStream);

                if (ds.Tables.Count > 0)
                {
                    dt = ds.Tables[0];
                }

                sWriter.Dispose();
                memStream.Dispose();
            }
            document.AddData(dt);
            byte[] ser = null;
            try
            {
                XDocument xTpu = XDocument.Parse(tpu.InnerXml);
                //elementi picture
                var picturesTag = from nd in xTpu.Root.DescendantNodesAndSelf().OfType <XElement>()
                                  where nd.Name.LocalName.Equals("pictureBox")
                                  select nd;
                //estrae gli attributi delle picture
                var pictures = from nd in picturesTag
                               select new
                {
                    Name     = nd.Attribute("name").Value,
                    FileName = nd.Element("file").Attribute("value").Value,
                    Width    = int.Parse(nd.Attribute("width").Value),
                    Heigth   = int.Parse(nd.Attribute("height").Value)
                };
                //aggiunge le picture alla stampa
                foreach (var pic in pictures)
                {
                    String keyImg = System.IO.Path.GetFileNameWithoutExtension(pic.FileName);

                    Com.Delta.Web.Cache.Types.TpuBinaryResource im =
                        CacheManager <Com.Delta.Web.Cache.Types.TpuBinaryResource> .get(
                            (CacheKeys)Enum.Parse(typeof(CacheKeys), keyImg, true),
                            VincoloType.FILESYSTEM);

                    System.IO.MemoryStream ms = new System.IO.MemoryStream(im.File);
                    System.Drawing.Bitmap  bb = (System.Drawing.Bitmap)System.Drawing.Bitmap.FromStream(ms);
                    document.AddPicture(pic.Name, bb, true);
                }

                ser = document.SerializeToPdfStream();
            }
            catch
            {
            }
            return(ser);
        }