コード例 #1
0
ファイル: Mandrill_PDF.cs プロジェクト: tatlin/Mandrill
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            D3jsLib.PdfStyle style    = null;
            string           filePath = null;

            D3jsLib.Report report = null;
            bool           print  = false;

            if (!DA.GetData <string>(0, ref filePath))
            {
                return;
            }
            if (!DA.GetData <D3jsLib.Report>(1, ref report))
            {
                return;
            }
            if (!DA.GetData <D3jsLib.PdfStyle>(2, ref style))
            {
                return;
            }
            if (!DA.GetData <bool>(3, ref print))
            {
                return;
            }

            if (print)
            {
                PrintPDF(report, style, filePath);
            }
        }
コード例 #2
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            D3jsLib.Report report = null;
            bool           show   = false;

            if (!DA.GetData <D3jsLib.Report>(0, ref report))
            {
                return;
            }
            if (!DA.GetData <bool>(1, ref show))
            {
                return;
            }

            if (show)
            {
                shouldBeVisible = true;
                this.mw.Show();
            }
            else
            {
                shouldBeVisible = false;
                this.mw.Hide();
            }

            this.MyHtml = report.HtmlString;
        }
コード例 #3
0
            private void SaveHtml(D3jsLib.Report report, string filePath)
            {
                HtmlDocument htmlDoc = new HtmlDocument();

                htmlDoc.LoadHtml(report.HtmlString);

                HtmlNodeCollection nodes = htmlDoc.DocumentNode.SelectNodes("//div[@class='gridster-box']");

                foreach (HtmlNode n in nodes)
                {
                    n.InnerHtml = "";
                }

                // created unescaped file path removes %20 from path etc.
                string finalFilePath = filePath;

                Uri    uri = new Uri(filePath);
                string absoluteFilePath = Uri.UnescapeDataString(uri.AbsoluteUri);

                if (Uri.IsWellFormedUriString(absoluteFilePath, UriKind.RelativeOrAbsolute))
                {
                    Uri newUri = new Uri(absoluteFilePath);
                    finalFilePath = newUri.LocalPath;
                }

                try
                {
                    // save html
                    System.IO.File.WriteAllText(filePath, htmlDoc.DocumentNode.InnerHtml);
                }
                catch
                {
                    MessageBox.Show("Printing failed. Is file open in another application?");
                }
            }
コード例 #4
0
            private void PrintPDF(D3jsLib.Report report, D3jsLib.PdfStyle style, string filePath)
            {
                HtmlDocument htmlDoc = new HtmlDocument();

                htmlDoc.LoadHtml(report.HtmlString);

                HtmlNodeCollection nodes = htmlDoc.DocumentNode.SelectNodes("//div[@class='gridster-box']");

                foreach (HtmlNode n in nodes)
                {
                    n.InnerHtml = "";
                }

                // attempt to move *dep file
                D3jsLib.Utilities.ChartsUtilities.MoveDepFile();

                // create converter
                SelectPdf.HtmlToPdf converter = new SelectPdf.HtmlToPdf();

                // set converter options
                SelectPdf.HtmlToPdfOptions options = converter.Options;
                options.PdfPageOrientation   = style.Orientation;
                options.PdfPageSize          = style.Size;
                options.JpegCompressionLevel = style.Compression;
                options.JavaScriptEnabled    = true;
                options.EmbedFonts           = true;
                options.KeepImagesTogether   = true;
                options.KeepTextsTogether    = true;
                options.AutoFitHeight        = style.VerticalFit;
                options.AutoFitWidth         = style.HorizontalFit;
                options.MarginTop            = style.MarginTop;
                options.MarginRight          = style.MarginRight;
                options.MarginBottom         = style.MarginBottom;
                options.MarginLeft           = style.MarginLeft;

                // created unescaped file path removes %20 from path etc.
                string finalFilePath = filePath;

                Uri    uri = new Uri(filePath);
                string absoluteFilePath = Uri.UnescapeDataString(uri.AbsoluteUri);

                if (Uri.IsWellFormedUriString(absoluteFilePath, UriKind.RelativeOrAbsolute))
                {
                    Uri newUri = new Uri(absoluteFilePath);
                    finalFilePath = newUri.LocalPath;
                }

                try
                {
                    // convert html to document object and save
                    SelectPdf.PdfDocument pdfDoc = converter.ConvertHtmlString(htmlDoc.DocumentNode.InnerHtml);
                    pdfDoc.Save(finalFilePath);
                    pdfDoc.Close();
                }
                catch
                {
                    MessageBox.Show("Printing failed. Is file open in another application?");
                }
            }
コード例 #5
0
ファイル: Mandrill_PDF.cs プロジェクト: tatlin/Mandrill
        private void PrintPDF(D3jsLib.Report report, D3jsLib.PdfStyle style, string filePath)
        {
            HtmlDocument htmlDoc = new HtmlDocument();

            htmlDoc.LoadHtml(report.HtmlString);

            HtmlNodeCollection nodes = htmlDoc.DocumentNode.SelectNodes("//div[@class='gridster-box']");

            foreach (HtmlNode n in nodes)
            {
                n.InnerHtml = "";
            }

            // create converter
            SelectPdf.HtmlToPdf converter = new SelectPdf.HtmlToPdf();

            // set converter options
            SelectPdf.HtmlToPdfOptions options = converter.Options;
            options.PdfPageOrientation   = style.Orientation;
            options.PdfPageSize          = style.Size;
            options.JpegCompressionLevel = style.Compression;
            options.JavaScriptEnabled    = true;
            options.EmbedFonts           = true;
            options.KeepImagesTogether   = true;
            options.KeepTextsTogether    = true;
            options.AutoFitHeight        = style.VerticalFit;
            options.AutoFitWidth         = style.HorizontalFit;
            options.MarginTop            = style.MarginTop;
            options.MarginRight          = style.MarginRight;
            options.MarginBottom         = style.MarginBottom;
            options.MarginLeft           = style.MarginLeft;

            try
            {
                // convert html to document object and save
                SelectPdf.PdfDocument pdfDoc = converter.ConvertHtmlString(htmlDoc.DocumentNode.InnerHtml);
                pdfDoc.Save(filePath);
                pdfDoc.Close();
            }
            catch
            {
                MessageBox.Show("Printing failed. Is file open in another application?");
            }
        }
コード例 #6
0
        /// <summary>
        ///     Retrieves input string from connected input node.
        /// </summary>
        /// <param name="engine"></param>
        /// <returns></returns>
        public string GetInputString(EngineController engine)
        {
            string htmlString;

            // If there is an input supplied
            if (HasConnectedInput(0))
            {
                // retrieve input string from input
                var            node       = InPorts[0].Connectors[0].Start.Owner;
                var            nodeIndex  = InPorts[0].Connectors[0].Start.Index;
                var            nodeName   = node.GetAstIdentifierForOutputIndex(nodeIndex).Name;
                var            mirrorData = engine.GetMirror(nodeName);
                D3jsLib.Report report     = mirrorData.GetData().Data as D3jsLib.Report;
                htmlString = report.HtmlString;
            }
            else
            {
                htmlString = string.Empty;
            }
            return(htmlString);
        }
コード例 #7
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            List <object> charts = new List <object>();

            for (int i = 0; i < Params.Input.Count; i++)
            {
                D3jsLib.Chart currentChart = null;
                DA.GetData <D3jsLib.Chart>(i, ref currentChart);
                if (currentChart != null)
                {
                    charts.Add(currentChart);
                }
                else
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, Resources.Warning_MissingInput);
                }
            }

            string finalHtmlString = D3jsLib.Charts.CompileHtmlString(charts, false);

            this.innerHtml = finalHtmlString;
            D3jsLib.Report report = new D3jsLib.Report(finalHtmlString);
            DA.SetData(0, report);
        }