Esempio n. 1
0
        public System.IO.MemoryStream formatData(System.Xml.XmlDocument rawData, System.Xml.XmlDocument xslt)
        {
            byte[] bPDF = null;
            try
            {
                MemoryStream ms = new MemoryStream();
                System.Web.UI.HtmlControls.HtmlGenericControl gc = new HtmlGenericControl();
                System.IO.MemoryStream inputStream   = new System.IO.MemoryStream();
                System.IO.MemoryStream outoputStream = new System.IO.MemoryStream();
                string head             = "";
                string foot             = "";
                XslCompiledTransform xs = new XslCompiledTransform();
                xs.Load(xslt);
                inputStream.Position = 0;
                rawData.Save(inputStream);
                inputStream.Position = 0;
                System.Xml.XmlTextReader xTextReader = new XmlTextReader(inputStream);
                xs.Transform(rawData, null, outoputStream);
                outoputStream.Seek(0, System.IO.SeekOrigin.Begin);
                System.IO.StreamReader streamReader = new System.IO.StreamReader(outoputStream);
                gc.TagName = "div";
                string output = streamReader.ReadToEnd();
                // Pulisco e compatto l'output
                string whattostrip = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<xsl:stylesheet version=\"2.0\" ";
                output       = output.Replace(whattostrip, String.Empty);
                whattostrip  = "<html xmlns=\"http://tempuri.org/DefinizioneResponse.xsd\">";
                output       = output.Replace(whattostrip, String.Empty);
                whattostrip  = "dd/mm/yyyy";
                output       = output.Replace(whattostrip, System.DateTime.Now.ToString("dd/MM/yyyy"));
                gc.InnerHtml = head + output + foot;
                gc.Dispose();
                streamReader.Close();
                streamReader.Dispose();
                StringReader          txtReader  = new StringReader(gc.InnerHtml);
                StringWriter          sw         = new StringWriter();
                HtmlTextWriter        hw         = new HtmlTextWriter(sw);
                Document              pdfDoc     = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
                MemoryStream          m          = new MemoryStream();
                System.Drawing.Image  imageDisco = System.Drawing.Image.FromFile(ConfigurationManager.AppSettings["ImageRoma"]);
                iTextSharp.text.Image image      = iTextSharp.text.Image.GetInstance(imageDisco, BaseColor.WHITE);
                image.ScaleToFit(336f, 86f);
                HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
                PdfWriter.GetInstance(pdfDoc, ms);
                pdfDoc.Open();
                pdfDoc.Add(image);
                htmlparser.Parse(txtReader);
                pdfDoc.Close();
                bPDF = ms.ToArray();
            }

            catch (Exception ex)
            {
                ErrorLogInfo error = new ErrorLogInfo();
                error.freeTextDetails = ex.Message;
                error.logCode         = "ERR_PDF_001";
            }
            return(StreamUty.byteArray2MemoryStream(bPDF));
        }
Esempio n. 2
0
        public System.IO.MemoryStream formatData(System.Xml.XmlDocument rawData, System.Xml.XmlDocument xslt)
        {
            string step = XmlUty.XsltToString(rawData, xslt);
            Engine en   = new Engine();

            sbyte[] pdf = null;
            try
            {
                pdf = en.Run(step);
            }
            catch (Exception ex)
            {
                ErrorLogInfo error = new ErrorLogInfo();
                error.freeTextDetails = ex.Message;
                error.logCode         = "ERR_PDF_001";
            }
            return(StreamUty.sbyteArray2MemoryStream(pdf));
        }