public static bool SaveDocument(RadFlowDocument document, string selectedFormat)
        {
            IFormatProvider<RadFlowDocument> formatProvider = null;
            switch (selectedFormat)
            {
                case "Docx":
                    formatProvider = new DocxFormatProvider();
                    break;
                case "Rtf":
                    formatProvider = new RtfFormatProvider();
                    break;
                case "Html":
                    formatProvider = new HtmlFormatProvider();
                    break;
                case "Txt":
                    formatProvider = new TxtFormatProvider();
                    break;
                case "Pdf":
                    formatProvider = new PdfFormatProvider();
                    break;
            }

            if (formatProvider == null)
            {
                return false;
            }

            SaveFileDialog dialog = new SaveFileDialog();
            dialog.Filter = String.Format("{0} files|*{1}|All files (*.*)|*.*",
                selectedFormat,
                formatProvider.SupportedExtensions.First());
            dialog.FilterIndex = 1;

            if (dialog.ShowDialog() == true)
            {
                using (var stream = dialog.OpenFile())
                {
                    formatProvider.Export(document, stream);
                }

                return true;
            }
            else
            {
                return false;
            }
        }
Esempio n. 2
1
 protected override void WriteToFile()
 {
     using (var pdfStream = File.Open(OutputFileLocation, FileMode.Create))
     {
         var htmlFormatProvider = new HtmlFormatProvider();
         htmlFormatProvider.Export(Document, pdfStream);
     }
 }
        private void Show(object obj)
        {
            RadFlowDocument document = this.CreateDocument();
            HtmlFormatProvider formatProvider = new HtmlFormatProvider();
            string html = formatProvider.Export(document);

            WebBrowser browser = new WebBrowser();
            browser.NavigateToString(html);

            Window window = new Window() { Width = 1000, Height = 350 };
            window.Content = browser;
            window.Show();
        }
        private void CreateDescription(IGlymaNode node, ref Paragraph paragraph)
        {
            //paragraph.Inlines.Add(new Span(FormattingSymbolLayoutBox.LINE_BREAK));

            if (node.NodeDescription.Type == "Iframe")
            {
                if (ShowDescriptionIcon)
                {
                    var descriptionIcon = new ImageInline(DescriptionIconStream, new Size(20, 15), "png");
                    paragraph.Inlines.Add(descriptionIcon);
                    paragraph.Inlines.Add(new Span("  "));
                }
                else
                {
                    paragraph.Inlines.Add(new Span("Link: ") { FontSize = 12 });
                }

                CreateLink(node.NodeDescription.Link, ref paragraph);
            }
            else
            {
                if (ShowDescriptionIcon)
                {
                    var descriptionIcon = new ImageInline(DescriptionIconStream, new Size(20, 15), "png");
                    paragraph.Inlines.Add(descriptionIcon);
                    paragraph.Inlines.Add(new Span("  "));
                }
                else
                {
                    paragraph.Inlines.Add(new Span("Description: ") { FontSize = 12 });
                }

                var htmlFormatProvider = new HtmlFormatProvider();
                var description = htmlFormatProvider.Import(node.NodeDescription.Description);
                foreach (var item in description.Sections)
                {
                    var section = item.CreateDeepCopy() as Section;
                    if (section != null)
                    {
                        foreach (var block in section.Blocks)
                        {
                            var para = block as Paragraph;
                            if (para != null)
                            {
                                foreach (Span span in para.EnumerateChildrenOfType<Span>())
                                {
                                    span.FontSize = 12;
                                }

                                foreach (var inline in para.Inlines)
                                {
                                    var theNewInLineItem = inline.CreateDeepCopy() as Inline;
                                    paragraph.Inlines.Add(theNewInLineItem);
                                }
                            }
                            else
                            {
                                CurrentBlockCollection.Add(block.CreateDeepCopy() as Block);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Get Supported providers for the import operation based on the file extension
        /// </summary>
        /// <param name="extension">the extension of the file we will import, used to discern the provider type</param>
        /// <returns>IFormatProvider<RadFlowDocument> that you can use to read that file and import it as an in-memory document you can convert to other formats</returns>
        IFormatProvider <RadFlowDocument> GetImportFormatProvider(string extension)
        {
            IFormatProvider <RadFlowDocument> fileFormatProvider;

            switch (extension)
            {
            case ".docx":
                fileFormatProvider = new DocxFormatProvider();
                break;

            case ".rtf":
                fileFormatProvider = new RtfFormatProvider();
                break;

            case ".html":
                fileFormatProvider = new HtmlFormatProvider();
                break;

            case ".txt":
                fileFormatProvider = new TxtFormatProvider();
                break;

            default:
                fileFormatProvider = null;
                break;
            }

            if (fileFormatProvider == null)
            {
                throw new NotSupportedException("The chosen file cannot be read with the supported providers.");
            }

            return(fileFormatProvider);
        }
Esempio n. 6
0
        private void KnowledgeChanged()
        {
            //Title = _knowledge.Title;
            var provider = new HtmlFormatProvider();

            boxEditor.Document = provider.Import(_knowledge.GetKnowledgeHtml());
        }
        private void PrepareDocument()
        {
            Patient patient = new PatientData().GetPatientById(_patientid);

            StringBuilder content = new StringBuilder();
            content.Append("<p>");
            content.Append("<b>Patient Name : </b>" + patient.FirstName.ToUpper() + " " + patient.LastName.ToUpper());
            content.Append("<br/>");
            content.Append("<b>Patient Id : </b>" + _patientid.ToString());
            content.Append("<br/>");
            content.Append("<b>Age : </b>" + Utility.GetAgeFromDob(patient.DOB).ToString());
            content.Append("<br/>");
            content.Append("<b>Address : </b>" + patient.Address.ToUpper());
            content.Append("<br/>");
            content.Append("<b>Hospital : </b>");
            content.Append("<br/>");
            content.Append("<b>IP Number : </b>");
            content.Append("<br/>");
            content.Append("<b>Date : </b>");
            content.Append("<br/>");
            content.Append("</p>");


            HtmlFormatProvider provider = new HtmlFormatProvider();
            Telerik.WinControls.RichTextBox.Model.RadDocument document = provider.Import(content.ToString());
            this.docPrintVisit.Document = document;

            this.docPrintVisit.InsertImage((Bitmap)Resources.letterhead);
            docPrintVisit.InsertLineBreak();
            docPrintVisit.InsertLineBreak();
        }
Esempio n. 8
0
        public ActionResult SaveEdit(int id, string titleUa, string titleEn, string body, string bodyEn, string detailUrl, string videoUrl, string pic)
        {
            string             bodyHtml     = HttpUtility.HtmlDecode(body);
            string             bodyHtmlEn   = HttpUtility.HtmlDecode(bodyEn);
            HtmlFormatProvider htmlProvider = new HtmlFormatProvider();
            RadFlowDocument    document     = htmlProvider.Import(bodyHtml);
            RadFlowDocument    documentEn   = htmlProvider.Import(bodyHtmlEn);

            using (Context db = new Context())
            {
                var news = db.Newses.FirstOrDefault(x => x.NewsId == id);
                if (news != null)
                {
                    news.Title     = titleUa;
                    news.TitleEn   = titleEn;
                    news.DateNews  = DateTime.Now;
                    news.Body      = htmlProvider.Export(document);
                    news.BodyEn    = htmlProvider.Export(documentEn);
                    news.DetailUrl = detailUrl;
                    news.Video     = videoUrl;
                    news.Picture   = pic;
                    db.SaveChanges();
                }
            }

            return(RedirectToAction("Index"));
        }
Esempio n. 9
0
        public ActionResult SaveEdit(int id, string bodyContentUA, string bodyContentEN, string fileNamePhoto, string mainName, string mainNameEn,
                                     string phone1, string phone2, string phone3, string email, string fbUrl, string googleUrl, string twUrl, string instUrl, string city, string cityEn)
        {
            string             bodyHtml     = HttpUtility.HtmlDecode(bodyContentUA);
            string             bodyHtmlEn   = HttpUtility.HtmlDecode(bodyContentEN);
            HtmlFormatProvider htmlProvider = new HtmlFormatProvider();
            RadFlowDocument    document     = htmlProvider.Import(bodyHtml);
            RadFlowDocument    documentEn   = htmlProvider.Import(bodyHtmlEn);
            var curMamber = context.TeamMembers.FirstOrDefault(x => x.Id == id);

            if (curMamber != null)
            {
                curMamber.City          = city;
                curMamber.CityEn        = cityEn;
                curMamber.Description   = htmlProvider.Export(document);
                curMamber.DescriptionEn = htmlProvider.Export(documentEn);
                curMamber.Email         = email;
                curMamber.Fb            = fbUrl;
                curMamber.Inst          = instUrl;
                curMamber.Google        = googleUrl;
                curMamber.Name          = mainName;
                curMamber.NameEn        = mainNameEn;
                curMamber.Phone1        = phone1;
                curMamber.Phone2        = phone2;
                curMamber.Phone3        = phone3;
                curMamber.Tw            = twUrl;
                curMamber.Photo         = fileNamePhoto;

                context.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
Esempio n. 10
0
        public ActionResult SaveNew(string bodyContentUA, string bodyContentEN, string fileNamePhoto, string mainName, string mainNameEn,
                                    string phone1, string phone2, string phone3, string email, string fbUrl, string googleUrl, string twUrl, string instUrl, string city, string cityEn)
        {
            string             bodyHtml     = HttpUtility.HtmlDecode(bodyContentUA);
            string             bodyHtmlEn   = HttpUtility.HtmlDecode(bodyContentEN);
            HtmlFormatProvider htmlProvider = new HtmlFormatProvider();
            RadFlowDocument    document     = htmlProvider.Import(bodyHtml);
            RadFlowDocument    documentEn   = htmlProvider.Import(bodyHtmlEn);

            using (Context db = new Context())
            {
                db.TeamMembers.Add(new TeamMember
                {
                    City          = city,
                    CityEn        = cityEn,
                    Description   = htmlProvider.Export(document),
                    DescriptionEn = htmlProvider.Export(documentEn),
                    Email         = email,
                    Fb            = fbUrl,
                    Inst          = instUrl,
                    Google        = googleUrl,
                    Name          = mainName,
                    NameEn        = mainNameEn,
                    Phone1        = phone1,
                    Phone2        = phone2,
                    Phone3        = phone3,
                    Tw            = twUrl,
                    Photo         = fileNamePhoto,
                });
                db.SaveChanges();
            }
            return(null);
        }
Esempio n. 11
0
        private static string OpenDocumentCore(Stream inputStream, DocumentType documentType)
        {
            var importProvider = CreateFormatProvider(documentType);
            var exportProvider = new HtmlFormatProvider();
            var flowDocument   = importProvider.Import(inputStream);

            //// Remove large left and hanging indentations of paragraphs in lists when importing from RTF
            foreach (Paragraph paragraph in flowDocument.EnumerateChildrenOfType <Paragraph>())
            {
                if (paragraph.ListId > -1)
                {
                    Telerik.Windows.Documents.Flow.Model.Lists.List list = flowDocument.Lists.GetList(paragraph.ListId);
                    if (paragraph.Indentation.HangingIndent == list.Levels[0].ParagraphProperties.HangingIndent.LocalValue)
                    {
                        paragraph.Indentation.HangingIndent = Paragraph.HangingIndentPropertyDefinition.DefaultValue.Value;
                        paragraph.Indentation.LeftIndent    = Paragraph.LeftIndentPropertyDefinition.DefaultValue.Value;
                    }

                    if (paragraph.Indentation.FirstLineIndent == list.Levels[0].ParagraphProperties.FirstLineIndent.LocalValue)
                    {
                        paragraph.Indentation.FirstLineIndent = Paragraph.FirstLineIndentPropertyDefinition.DefaultValue.Value;
                    }
                }
            }

            return(exportProvider.Export(flowDocument));
        }
Esempio n. 12
0
        private void ExportToHtml()
        {
            RadDocument document = GenerateRadDocument();
            var         provider = new HtmlFormatProvider();

            ShowPrintPreviewDialog(document, provider);
        }
Esempio n. 13
0
        /// <summary>
        /// Convert the HTML string to a file, download the generated file in the browser
        /// </summary>
        /// <param name="htmlContent">The HTML content to export</param>
        /// <param name="fileName">The FileName of the downloaded file, its extension is used to fetch the exprot provider</param>
        /// <returns>Returns true if the operation succeeded, false if there was an exception</returns>
        public async Task <bool> ExportAndDownloadHtmlContent(string htmlContent, string fileName)
        {
            try
            {
                // prepare a document with the HTML content that we can use for conversion
                HtmlFormatProvider provider = new HtmlFormatProvider();
                RadFlowDocument    document = provider.Import(htmlContent);

                // get the provider to export and then download the file
                string mimeType;
                IFormatProvider <RadFlowDocument> exportProvider = GetExportFormatProvider(fileName, out mimeType);
                byte[] exportFileBytes = null;
                using (MemoryStream ms = new MemoryStream())
                {
                    exportProvider.Export(document, ms);
                    exportFileBytes = ms.ToArray();
                }

                // download the file in the browser
                await FileDownloader.Save(_js, exportFileBytes, mimeType, fileName);
            }
            catch (Exception ex)
            {
                return(false);
            }
            return(true);
        }
Esempio n. 14
0
        /// <summary>
        /// Import a file from disk and convert it to an HTML string for use in the Editor
        /// </summary>
        /// <returns>An HTML string that is just the contents of the body tag so the editor can work with them. Returns null to denote an error.</returns>
        public string GetHtmlString()
        {
            try
            {
                // read the file - in this sample a hardcoded path
                string          path     = Path.Combine(Environment.WebRootPath, "JohnGrisham.docx");
                RadFlowDocument document = ReadFile(path);

                // convert the file to HTML
                HtmlFormatProvider provider = new HtmlFormatProvider();
                provider.ExportSettings.StylesExportMode    = StylesExportMode.Inline;
                provider.ExportSettings.DocumentExportLevel = DocumentExportLevel.Fragment;
                string html = provider.Export(document);

                // get only the <body> contents
                int    bodyStart = html.IndexOf("<body>") + "<body>".Length;
                int    bodyEnd   = html.IndexOf("</body>");
                string body      = html.Substring(bodyStart, bodyEnd - bodyStart);

                return(body);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Esempio n. 15
0
        public ActionResult Save(string titleUa, string titleEn, string body, string bodyEn, string detailUrl, string videoUrl, string pic)
        {
            string             bodyHtml     = HttpUtility.HtmlDecode(body);
            string             bodyHtmlEn   = HttpUtility.HtmlDecode(bodyEn);
            HtmlFormatProvider htmlProvider = new HtmlFormatProvider();
            RadFlowDocument    document     = htmlProvider.Import(bodyHtml);
            RadFlowDocument    documentEn   = htmlProvider.Import(bodyHtmlEn);

            using (Context db = new Context())
            {
                db.Newses.Add(new News
                {
                    Title     = titleUa,
                    TitleEn   = titleEn,
                    DateNews  = DateTime.Now,
                    Body      = htmlProvider.Export(document),
                    BodyEn    = htmlProvider.Export(documentEn),
                    DetailUrl = detailUrl,
                    Video     = videoUrl,
                    Picture   = pic
                });
                db.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
        private static void SaveDocumentCore(string htmlText, Stream outputStream, DocumentType documentType)
        {
            var importProvider = new HtmlFormatProvider();
            var exportProvider = CreateFormatProvider(documentType);
            var flowDocument   = importProvider.Import(htmlText);

            exportProvider.Export(flowDocument, outputStream);
        }
Esempio n. 17
0
 private void ExportToString()
 {
     #region radwordsprocessing-formats-and-conversion-html-htmlformatprovider_3
     RadFlowDocument    document = CreateRadFlowDocument();
     HtmlFormatProvider provider = new HtmlFormatProvider();
     string             html     = provider.Export(document);
     #endregion
 }
Esempio n. 18
0
 private void ImportFromString()
 {
     #region radwordsprocessing-formats-and-conversion-html-htmlformatprovider_1
     string             html     = "<p>hello world!</p>";
     HtmlFormatProvider provider = new HtmlFormatProvider();
     RadFlowDocument    document = provider.Import(html);
     #endregion
 }
        private static string OpenDocumentCore(Stream inputStream, DocumentType documentType)
        {
            var importProvider = CreateFormatProvider(documentType);
            var exportProvider = new HtmlFormatProvider();
            var flowDocument   = importProvider.Import(inputStream);

            return(exportProvider.Export(flowDocument));
        }
Esempio n. 20
0
        private void SaveDocument(RadFlowDocument document)
        {
            HtmlFormatProvider formatProvider = new HtmlFormatProvider();

            using (var stream = File.OpenWrite("Sample Document.html"))
            {
                formatProvider.Export(document, stream);
            }
        }
Esempio n. 21
0
        private void Save(string format)
        {
            if (this.document == null)
            {
                Console.WriteLine("Cannot save. A document is not loaded.");
                return;
            }

            IFormatProvider <RadFlowDocument> formatProvider = null;

            switch (format)
            {
            case "docx":
                formatProvider = new DocxFormatProvider();
                break;

            case "html":
                formatProvider = new HtmlFormatProvider();
                break;

            case "rtf":
                formatProvider = new RtfFormatProvider();
                break;

            case "txt":
                formatProvider = new TxtFormatProvider();
                break;

            case "pdf":
                formatProvider = new PdfFormatProvider();
                break;
            }

            if (formatProvider == null)
            {
                Console.WriteLine("Not supported document format.");
                return;
            }

            string path = "Converted." + format;

            using (FileStream stream = File.OpenWrite(path))
            {
                formatProvider.Export(this.document, stream);
            }

            Console.WriteLine("Document converted.");

            ProcessStartInfo psi = new ProcessStartInfo()
            {
                FileName        = path,
                UseShellExecute = true
            };

            Process.Start(psi);
        }
Esempio n. 22
0
 private void ImportFromFile()
 {
     #region radwordsprocessing-formats-and-conversion-html-htmlformatprovider_0
     using (Stream input = File.Create(@"Sample.html"))
     {
         HtmlFormatProvider provider = new HtmlFormatProvider();
         RadFlowDocument    document = provider.Import(input);
     }
     #endregion
 }
Esempio n. 23
0
        void EmailBodyContent_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            var mimePartVm = e.NewValue as MimePartVm;

            if (mimePartVm != null)
            {
                RadDocument content = null;
                var         plain   = true;
                if (!String.IsNullOrEmpty(mimePartVm.MIMEpart.ContentSubtype))
                {
                    if (mimePartVm.MIMEpart.ContentSubtype.Equals("html"))
                    {
                        content = new HtmlFormatProvider().Import(mimePartVm.RawContent);
                        plain   = false;
                    }
                    else if (mimePartVm.MIMEpart.ContentSubtype.Equals("rtf"))
                    {
                        content = new RtfFormatProvider().Import(mimePartVm.RawContent);
                        plain   = false;
                    }

                    /* else if (mimePartVm.Data.ContentSubtype.Equals("pdf"))
                     * {
                     *   content = new PdfFormatProvider().Import(mimePartVm.RawContent);
                     * }*/
                    else
                    {
                        content = new TxtFormatProvider().Import(mimePartVm.RawContent);
                        //content = new XamlFormatProvider().Import(mimePartVm.RawContent);
                    }
                }
                else
                {
                    // content = new XamlFormatProvider().Import(mimePartVm.RawContent);
                    //TxtFormatProvider formatProvider = new TxtFormatProvider();
                    content = new TxtFormatProvider().Import(mimePartVm.RawContent);
                    //content = new TxtDataProvider(mimePartVm.RawContent);
                }

                if (plain)
                {
                    foreach (var span in content.EnumerateChildrenOfType <Span>())
                    {
                        span.FontSize = 12;
                    }
                }

                content.LineSpacing = 1.1;
                content.ParagraphDefaultSpacingAfter  = 0;
                content.ParagraphDefaultSpacingBefore = 0;

                this.ContentTextBox.LineBreakingRuleLanguage = LineBreakingRuleLanguage.None;
                this.ContentTextBox.Document = content;
            }
        }
        private static RadDocument CreateDocument(RadGridView grid, PrintSettings settings)
        {
            RadDocument document = null;

            using (var stream = new MemoryStream())
            {
                EventHandler <GridViewElementExportingEventArgs> elementExporting = (s, e) =>
                {
                    if (e.Element == ExportElement.Table)
                    {
                        e.Attributes["border"] = "0";
                    }
                    else if (e.Element == ExportElement.HeaderRow)
                    {
                        if (settings.HeaderBackground != null)
                        {
                            e.Styles.Add("background-color", settings.HeaderBackground.ToString().Remove(1, 2));
                        }
                    }
                    else if (e.Element == ExportElement.GroupHeaderRow)
                    {
                        if (settings.GroupHeaderBackground != null)
                        {
                            e.Styles.Add("background-color", settings.GroupHeaderBackground.ToString().Remove(1, 2));
                        }
                    }
                    else if (e.Element == ExportElement.Row)
                    {
                        if (settings.RowBackground != null)
                        {
                            e.Styles.Add("background-color", settings.RowBackground.ToString().Remove(1, 2));
                        }
                    }
                };

                grid.ElementExporting += elementExporting;

                grid.Export(stream, new GridViewExportOptions()
                {
                    Format            = Telerik.Windows.Controls.ExportFormat.Html,
                    ShowColumnFooters = grid.ShowColumnFooters,
                    ShowColumnHeaders = grid.ShowColumnHeaders,
                    ShowGroupFooters  = grid.ShowGroupFooters
                });

                grid.ElementExporting -= elementExporting;

                stream.Position = 0;

                document = new HtmlFormatProvider().Import(stream);
            }

            return(document);
        }
Esempio n. 25
0
 private void ExportToFile()
 {
     #region radwordsprocessing-formats-and-conversion-html-htmlformatprovider_2
     HtmlFormatProvider provider = new HtmlFormatProvider();
     using (Stream output = File.Create("Sample.html"))
     {
         RadFlowDocument document = CreateRadFlowDocument();
         provider.Export(document, output);
     }
     #endregion
 }
        public void LoadHtml(string description)
        {
            var html = new HtmlAgilityPack.HtmlDocument();

            html.LoadHtml(description);

            var doc = HtmlFormatProvider.Import(description);

            SetupNewDocument(doc);
            RadRichTextBox.Document = doc;
        }
        private void SaveDocument(RadFlowDocument document, string selectedFormat)
        {
            string selectedFormatLower = selectedFormat.ToLower();

            IFormatProvider <RadFlowDocument> formatProvider = null;

            switch (selectedFormatLower)
            {
            case "docx":
                formatProvider = new DocxFormatProvider();
                break;

            case "rtf":
                formatProvider = new RtfFormatProvider();
                break;

            case "txt":
                formatProvider = new TxtFormatProvider();
                break;

            case "html":
                formatProvider = new HtmlFormatProvider();
                break;

            case "pdf":
                formatProvider = new PdfFormatProvider();
                break;
            }

            if (formatProvider == null)
            {
                Console.WriteLine("Uknown or not supported format.");
                return;
            }

            string path = "Sample document." + selectedFormat;

            using (FileStream stream = File.OpenWrite(path))
            {
                formatProvider.Export(document, stream);
            }

            Console.Write("Document generated.");

            ProcessStartInfo psi = new ProcessStartInfo()
            {
                FileName        = path,
                UseShellExecute = true
            };

            Process.Start(psi);
        }
        private void SaveDocument(RadFlowDocument document)
        {
            HtmlFormatProvider formatProvider = new HtmlFormatProvider();

            string path = "Sample Document.html";

            using (var stream = File.OpenWrite(path))
            {
                formatProvider.Export(document, stream);
            }

            Console.Write("Document generated.");
            Process.Start(path);
        }
Esempio n. 29
0
        public ActionResult ExportDocx(string content)
        {
            HtmlFormatProvider htmlProvider = new HtmlFormatProvider();
            RadFlowDocument    htmlDocument = htmlProvider.Import(content);

            DocxFormatProvider docxProvider = new DocxFormatProvider();

            using (Stream output = System.IO.File.OpenWrite(Server.MapPath("~/App_Data/Sample.docx")))
            {
                docxProvider.Export(htmlDocument, output);
            }

            return(new HttpStatusCodeResult(HttpStatusCode.OK));
        }
Esempio n. 30
0
        private void Initialize()
        {
            InitializeComponent();


            RadMenuInsertTableItem insertTableBoxItem = new RadMenuInsertTableItem();

            this.radDropDownButtonElementTables.Items.Insert(0, insertTableBoxItem);
            insertTableBoxItem.SelectionChanged += new EventHandler <TableSelectionChangedEventArgs>(OnInsertTableSelectionChanged);

            this.radMenuItemInsertTable.Click += new EventHandler(radMenuItemInsertTable_Click);

            this.radRibbonBar1.RibbonBarElement.ApplicationButtonElement.Text         = "File";
            this.radRibbonBar1.RibbonBarElement.ApplicationButtonElement.ForeColor    = Color.White;
            this.radRibbonBar1.RibbonBarElement.ApplicationButtonElement.DisplayStyle = DisplayStyle.Text;

            this.radDropDownListFontSize.DropDownStyle = RadDropDownStyle.DropDownList;
            this.radDropDownListFont.DropDownStyle     = RadDropDownStyle.DropDownList;

            //this.radPageView1.SelectedPage = this.radPageViewPageSaveAsWord;

            Stream             stream       = new FileStream(path, FileMode.Open);
            HtmlFormatProvider htmlProvider = new HtmlFormatProvider();
            RadDocument        document     = htmlProvider.Import(stream);

            this.AttachDocument(document);
            this.radRichTextBox1.Document      = document;
            this.radBtnPrintLayout.ToggleState = ToggleState.On;
            this.radRichTextBox1.CurrentEditingStyleChanged += new EventHandler(radRichTextBox1_CurrentEditingStyleChanged);


            this.BtnSaveAsHTML.Click  += new EventHandler(this.radBtnSave_Click);
            this.BtnSaveAsPDF.Click   += new EventHandler(this.radBtnSave_Click);
            this.BtnSaveAsRTF.Click   += new EventHandler(this.radBtnSave_Click);
            this.BtnSaveAsPLAIN.Click += new EventHandler(this.radBtnSave_Click);
            this.BtnSaveAsWORD.Click  += new EventHandler(this.radBtnSave_Click);
            this.BtnSaveAsXAML.Click  += new EventHandler(this.radBtnSave_Click);

            this.radDropDownListFont.DropDownAnimationEnabled     = false;
            this.radDropDownListFontSize.DropDownAnimationEnabled = false;



            /*AttachSignal();
             * this.closeTimer = new System.Windows.Forms.Timer();
             * this.closeTimer.Interval = 3000;
             * this.closeTimer.Tick += new EventHandler(closeTimer_Tick);
             * this.closeTimer.Start();*/
        }
Esempio n. 31
0
        /// <summary>
        /// Get Supported providers for the export operation based on the file name, also gets its MIME type as an out parameter
        /// </summary>
        /// <param name="fileName">the file name you wish to export, the provider is discerned based on its extensiom</param>
        /// <param name="mimeType">an out parameter with the MIME type for this file so you can download it</param>
        /// <returns>IFormatProvider<RadFlowDocument> that you can use to export the original document to a certain file format</returns>
        IFormatProvider <RadFlowDocument> GetExportFormatProvider(string fileName, out string mimeType)
        {
            // we get both the provider and the MIME type to use only one swtich-case
            IFormatProvider <RadFlowDocument> fileFormatProvider;
            string extension = Path.GetExtension(fileName);

            switch (extension)
            {
            case ".docx":
                fileFormatProvider = new DocxFormatProvider();
                mimeType           = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
                break;

            case ".rtf":
                fileFormatProvider = new RtfFormatProvider();
                mimeType           = "application/rtf";
                break;

            case ".html":
                fileFormatProvider = new HtmlFormatProvider();
                mimeType           = "text/html";
                break;

            case ".txt":
                fileFormatProvider = new TxtFormatProvider();
                mimeType           = "text/plain";
                break;

            case ".pdf":
                fileFormatProvider = new pdfProviderNamespace.PdfFormatProvider();
                mimeType           = "application/pdf";
                break;

            default:
                fileFormatProvider = null;
                mimeType           = string.Empty;
                break;
            }

            if (fileFormatProvider == null)
            {
                throw new NotSupportedException("The chosen format cannot be exported with the supported providers.");
            }

            return(fileFormatProvider);
        }
        public string GetRawText()
        {
            var description = HtmlFormatProvider.Export(RadRichTextBox.Document);

            //if (_descriptionWidth > 0)
            //{
            //    //custom sizing provided
            //    return string.Format(@"<div id=""GlymaNodeDescriptionDiv"" width=""{0}"" height=""{1}"" style=""width:{0}px;height:{1}px;"">{2}</div>", _descriptionWidth, _descriptionHeight, description);
            //}
            if (string.IsNullOrWhiteSpace(description))
            {
                //no content, return empty
                return(string.Empty);
            }
            return(description);
            ////no custom sizing but want to mark it up as coming from the RichTextEdit rather than the advanced
            //return string.Format(@"<div id=""GlymaNodeDescriptionDiv"">{0}</div>", description);
        }
Esempio n. 33
0
        private void Show(object obj)
        {
            RadFlowDocument    document       = this.CreateDocument();
            HtmlFormatProvider formatProvider = new HtmlFormatProvider();
            string             html           = formatProvider.Export(document);

            WebBrowser browser = new WebBrowser();

            browser.NavigateToString(html);

            Window window = new Window()
            {
                Width = 1000, Height = 350
            };

            window.Content = browser;
            window.Show();
        }
Esempio n. 34
0
        private void Save(string format)
        {
            if (this.document == null)
            {
                Console.WriteLine("Cannot save. A document is not loaded.");
                return;
            }

            IFormatProvider <RadFlowDocument> formatProvider = null;

            switch (format)
            {
            case "docx":
                formatProvider = new DocxFormatProvider();
                break;

            case "html":
                formatProvider = new HtmlFormatProvider();
                break;

            case "rtf":
                formatProvider = new RtfFormatProvider();
                break;

            case "txt":
                formatProvider = new TxtFormatProvider();
                break;

            case "pdf":
                formatProvider = new PdfFormatProvider();
                break;
            }
            if (formatProvider == null)
            {
                Console.WriteLine("Not supported document format.");
                return;
            }

            using (var stream = File.OpenWrite("Converted." + format))
            {
                formatProvider.Export(this.document, stream);
                Console.WriteLine("The document is converted and saved.");
            }
        }
Esempio n. 35
0
        private static RadDocument CreateDocument(RadGridView grid)
        {
            RadDocument document = null;

            using (var stream = new MemoryStream())
            {
                grid.Export(stream, new GridViewExportOptions()
                {
                    Format = ExportFormat.Html,
                    ShowColumnFooters = grid.ShowColumnFooters,
                    ShowColumnHeaders = grid.ShowColumnHeaders,
                    ShowGroupFooters = grid.ShowGroupFooters
                });

                stream.Position = 0;
                document = new HtmlFormatProvider().Import(stream);
            }

            return document;
        }
Esempio n. 36
0
 private void ExportToHtml()
 {
     RadDocument document = GenerateRadDocument();
     var provider = new HtmlFormatProvider();
     ShowPrintPreviewDialog(document, provider);
 }
        private DocumentFragment ImportPart(XElement root, string className)
        {
            XElement target = this.FindElementByClass(root, className);
            if (target == null)
            {
                return null;
            }

            RadDocument radDocument = new HtmlFormatProvider().Import(target.ToString());

            RemoveEmptySpans(radDocument);
            radDocument.Selection.SelectAll();

            return new DocumentFragment(radDocument.Selection);
        }
Esempio n. 38
0
        private Field GetField(string processSystemName, PropertyInfo property, IDynamicObject self, bool isGsUpdate, CultureInfo culture = null)
        {
            var containsNumbers = false;
            var temp = property.GetValue(self, null);

            if (typeof(DateTime?).IsAssignableFrom(property.PropertyType))
            {
                containsNumbers = true;
                var attrib = (DateTimeFormatAttribute[])property.GetCustomAttributes(typeof(DateTimeFormatAttribute), false);
                var displayType = attrib.Select(x => x.Value).FirstOrDefault();
                var propValue = (DateTime?)property.GetValue(self, null);
                if (propValue != null)
                {
                    switch (displayType)
                    {
                        case "Date":
                            temp = propValue.Value.ToString(Constants.DefaultShortDateFormat, CultureInfo.InvariantCulture);
                            break;
                        case "Time":
                            temp = propValue.Value.ToString(Constants.DefaultShortTimeFormat, CultureInfo.InvariantCulture);
                            break;
                        case "DateTime":
                            temp = propValue.Value.ToString(Constants.DefaultShortDateTimeFormat, CultureInfo.InvariantCulture);
                            break;
                        default:
                            throw new VeyronException("Not definited time : " + displayType);
                    }
                }
            }

            var crossRefAtrib = (CrossRefFieldAttribute[])property.GetCustomAttributes(typeof(CrossRefFieldAttribute), false);
            if (crossRefAtrib.Count() != 0)
            {
                var enumerable = temp as IEnumerable<object>;
                if (enumerable != null)
                {
                    var items = enumerable.ToArray();

                    var fieldName = crossRefAtrib.Select(x => x.RefFieldName).FirstOrDefault();
                    if (items.Any())
                    {
                        var firstItemType = items[0].GetType();
                        var fieldProperty = firstItemType.GetPropertyByName(fieldName);
                        if (fieldProperty != null)
                        {
                            var list = items.Select(item => (fieldProperty.GetValue(item, null) ?? string.Empty).ToString()).ToList();
                            temp = list.Any() ? list.Aggregate((a, b) => a + ", " + b) : null;
                        }
                    }
                    else
                    {
                        temp = string.Empty;
                    }
                }
                else
                {
                    if (!isGsUpdate)
                    {
                        var crossRefId = temp as int?;
                        if (crossRefId != null)
                        {
                            var crossRefValue = TheDynamicTypeManager.GetCrossReferenceItem(processSystemName, property.Name, (int)crossRefId);
                            if (crossRefValue != null)
                            {
                                temp = crossRefValue.__DisplayName;
                            }
                        }
                    }
                }
            }

            var fieldEditorAtribute = (FieldEditorAttribute[])property.GetCustomAttributes(typeof(FieldEditorAttribute), false);
            if (fieldEditorAtribute.Count() != 0)
            {
                var atribute = fieldEditorAtribute.FirstOrDefault();
                if (atribute.DataType == "Checkbox")
                {
                    var checkBoxValue = temp as bool?;

                    var isSwithTogle = (IsSwitchToggleAttribute[])property.GetCustomAttributes(typeof(IsSwitchToggleAttribute), false);
                    if (isSwithTogle.Count() != 0)
                    {
                        var switchTogleValue = (isSwithTogle.FirstOrDefault().Value as bool?).Value;
                        if (switchTogleValue)
                        {
                            if (!checkBoxValue.HasValue)
                            {
                                temp =
                                    ((UndefinedLabelAttribute[])property.GetCustomAttributes(typeof(UndefinedLabelAttribute), false))
                                        .FirstOrDefault().Value.ToString();
                            }
                            else if (checkBoxValue.Value)
                            {
                                temp =
                                    ((TrueLabelAttribute[])property.GetCustomAttributes(typeof(TrueLabelAttribute), false)).FirstOrDefault()
                                                                                                                           .Value.ToString();
                            }
                            else
                            {
                                temp =
                                    ((FalseLabelAttribute[])property.GetCustomAttributes(typeof(FalseLabelAttribute), false)).FirstOrDefault()
                                                                                                                             .Value.ToString();
                            }
                        }
                        else
                        {
                            if (!checkBoxValue.HasValue)
                            {
                                temp = null;
                            }
                            else if (checkBoxValue.Value)
                            {
                                temp = "True";
                            }
                            else
                            {
                                temp = "False";
                            }
                        }
                    }
                }

                if (atribute.DataType == "Approval")
                {
                    var result = temp as string;
                    var approval = temp as IApprovalEdit;
                    if (approval != null)
                    {
                        result = approval.ApprovalState;
                    }

                    temp = result.ToApprovalState().GetDisplayName();
                }

                if (atribute.DataType == "RichText")
                {
                    var richText = temp as string;

                    if (!string.IsNullOrEmpty(richText))
                    {
                        var htmlProvider = new HtmlFormatProvider();
                        var document = htmlProvider.Import(richText);

                        var textProvider = new TxtFormatProvider();
                        temp = textProvider.Export(document);
                    }
                }

                if (atribute.DataType == "FileProcess")
                {
                    var file = temp as IFileProcess;
                    if (file != null)
                    {
                        temp = file.OriginalFileName;
                    }
                }
            }

            string value = temp == null ? null : temp.ToString();
            if (!containsNumbers && IsNumber(value))
            {
                containsNumbers = true;
            }

            if (value == null || string.IsNullOrWhiteSpace(value))
            {
                return null;
            }

            var field = culture != null ? GetLocalizedFieldName(property.Name, culture) : property.Name;

            return new Field(field, value, Field.Store.YES, containsNumbers ? Field.Index.NOT_ANALYZED : Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS);
        }
Esempio n. 39
0
 private void PrepareDocument(string content)
 {
     HtmlFormatProvider provider = new HtmlFormatProvider();
     RadDocument document = provider.Import(content);
     this.docCertificate.Document = document;
 }
        private string ExportAnnotationRangeFragment(RadDocument document, string semanticRangeName)
        {
            RecipeRangeStart semanticRangestart = null;
            RecipeRangeEnd semanticRangeEnd = null;
            foreach (RecipeRangeStart rangeStart in document.GetAnnotationMarkersOfType<RecipeRangeStart>())
            {
                if (rangeStart.Name == semanticRangeName)
                {
                    semanticRangestart = rangeStart;
                    semanticRangeEnd = (RecipeRangeEnd)rangeStart.End;
                }
            }

            if (semanticRangestart != null && semanticRangeEnd != null)
            {
                DocumentPosition startPosition = new DocumentPosition(document);
                startPosition.MoveToInline((InlineLayoutBox)semanticRangestart.FirstLayoutBox, 0);

                DocumentPosition endPosition = new DocumentPosition(document);
                endPosition.MoveToInline((InlineLayoutBox)semanticRangeEnd.FirstLayoutBox, 0);

                DocumentSelection selection = new DocumentSelection(document);
                selection.SetSelectionStart(startPosition);
                selection.AddSelectionEnd(endPosition);

                DocumentFragment fragment = new DocumentFragment(selection);
                RadDocument fragmentDocument = fragment.ToDocument();

                HtmlFormatProvider htmlFormatProvider = new HtmlFormatProvider();
                htmlFormatProvider.ExportSettings = new HtmlExportSettings();
                htmlFormatProvider.ExportSettings.DocumentExportLevel = DocumentExportLevel.Fragment;
                htmlFormatProvider.ExportSettings.StylesExportMode = StylesExportMode.Inline;
                htmlFormatProvider.ExportSettings.StyleRepositoryExportMode = StyleRepositoryExportMode.DontExportStyles;

                return htmlFormatProvider.Export(fragmentDocument);
            }

            return string.Empty;
        }
Esempio n. 41
0
        public static RadDocument CreateDocument(RadGridView grid)
        {
            RadDocument document = null;

            using (var stream = new MemoryStream())
            {
                grid.ElementExporting += elementExporting;

                grid.Export(stream, new GridViewExportOptions()
                {
                    Format = ExportFormat.Html,
                    ShowColumnFooters = grid.ShowColumnFooters,
                    ShowColumnHeaders = grid.ShowColumnHeaders,
                    ShowGroupFooters = grid.ShowGroupFooters,
                    Culture = new CultureInfo("fr-FR"),
                    Items = grid.Items
                });

                grid.ElementExporting -= elementExporting;

                stream.Position = 0;

                HtmlFormatProvider provider = new HtmlFormatProvider();
                document = new HtmlFormatProvider().Import(stream);
                document.SectionDefaultPageMargin = new Telerik.Windows.Documents.Layout.Padding(20);
                document.LayoutMode = DocumentLayoutMode.Paged;
                document.Measure(RadDocument.MAX_DOCUMENT_SIZE);
                document.Arrange(new RectangleF(PointF.Empty, document.DesiredSize));
            }

            return document;
        }
Esempio n. 42
0
        private static RadDocument CreateDocument(GridViewDataControl grid)
        {
            RadDocument document;

            using (var stream = new MemoryStream())
            {
                EventHandler<GridViewElementExportingEventArgs> elementExporting = (s, e) =>
                {
                    if (e.Element == ExportElement.Table)
                    {
                        e.Attributes["border"] = "0";
                    }
                };

                grid.ElementExporting += elementExporting;

                grid.Export(stream, new GridViewExportOptions
                {
                    Format = ExportFormat.Html,
                    ShowColumnFooters = grid.ShowColumnFooters,
                    ShowColumnHeaders = grid.ShowColumnHeaders,
                    ShowGroupFooters = grid.ShowGroupFooters
                });

                grid.ElementExporting -= elementExporting;

                stream.Position = 0;

                document = new HtmlFormatProvider().Import(stream);

                foreach (Span span in document.EnumerateChildrenOfType<Span>())
                {
                    span.FontSize = 12;
                    span.FontFamily = new FontFamily("Arial");
                }
            }

            return document;
        }
Esempio n. 43
0
        private void LoadPrescription(int visitid)
        {

            Patient patient = new PatientData().GetPatientById(_patientid);

            StringBuilder content = new StringBuilder();
            content.Append("<p>");
            content.Append("<b>Patient Name : </b>" + patient.FirstName.ToUpper() + " " + patient.LastName.ToUpper());
            content.Append("<br/>");
            content.Append("<b>Patient Id : </b>" + _patientid.ToString());
            content.Append("<br/>");
            content.Append("<b>Age : </b>" + Utility.GetAgeFromDob(patient.DOB).ToString());
            content.Append("<br/>");
            content.Append("<b>Address : </b>" + patient.Address.ToUpper());
            content.Append("<br/>");
            content.Append("<b>Hospital : </b>");
            content.Append("<br/>");
            content.Append("<b>IP Number : </b>");
            content.Append("<br/>");
            content.Append("<b>Date : </b>");
            content.Append("<br/>");
            content.Append("</p>");

            VisitData db = new VisitData();

            PatientVisit visit = db.GetVisitById(visitid);
            if (visit != null)
            {
                content.Append("<p>");

                content.Append("<br/>");
                content.Append("<b>Presenting complaint and relevant history : </b>");
                content.Append("<br/>");
                content.Append(visit.ComplaintHistory);
                content.Append("<br/>");

                content.Append("<br/>");
                content.Append("<b>Clinical findings : </b>");
                content.Append("<br/>");
                content.Append(visit.ExaminationNotes);
                content.Append("<br/>");

                content = AddLabData(db.GetLabData(visitid), content);

                AddImagingData(db.GetImagingData(visitid), content);

                content.Append("<br/>");
                content.Append("<b>Diagnosis : </b>");
                content.Append("<br/>");
                content.Append(visit.Diagnosis);
                content.Append("<br/>");

                AddPrescriptionData(db.GetPrescriptionData(visitid), content);

                content.Append("<br/>");
                content.Append("<b>Other Advise : </b>");
                content.Append("<br/>");
                content.Append(visit.OtherAdvise);
                content.Append("<br/>");

                content.Append("<br/>");
                content.Append("<b>Follow Up Date : </b>");
                content.Append("<br/>");
                if (visit.IsFolowUpRequired)
                {
                    content.Append(visit.FollowUpDate.ToShortDateString());
                }
                content.Append("<br/>");

                content.Append("</p>");
            }

            HtmlFormatProvider provider = new HtmlFormatProvider();
            Telerik.WinControls.RichTextBox.Model.RadDocument document = provider.Import(content.ToString());
            this.docPrintVisit.Document = document;

            this.docPrintVisit.InsertImage((Bitmap)Resources.letterhead);
            docPrintVisit.InsertLineBreak();
            docPrintVisit.InsertLineBreak();
        }
Esempio n. 44
0
        private static RadDocument CreateDocument(GridViewDataControl grid, PrintSettings settings)
        {
            RadDocument document;

            using (var stream = new MemoryStream())
            {
                EventHandler<GridViewElementExportingEventArgs> elementExporting = (s, e) =>
                {
                    switch (e.Element)
                    {
                        case ExportElement.Table:
                            e.Attributes["border"] = "0";
                            break;
                        case ExportElement.HeaderRow:
                            e.Styles.Add("background-color", settings.HeaderBackground.ToString().Remove(1, 2));
                            break;
                        case ExportElement.GroupHeaderRow:
                            e.Styles.Add("background-color", settings.GroupHeaderBackground.ToString().Remove(1, 2));
                            break;
                        case ExportElement.Row:
                            e.Styles.Add("background-color", settings.RowBackground.ToString().Remove(1, 2));
                            break;
                    }
                };

                grid.ElementExporting += elementExporting;

                grid.Export(stream, new GridViewExportOptions
                    {
                        Format = Telerik.Windows.Controls.ExportFormat.Html,
                        ShowColumnFooters = grid.ShowColumnFooters,
                        ShowColumnHeaders = grid.ShowColumnHeaders,
                        ShowGroupFooters = grid.ShowGroupFooters
                    });

                grid.ElementExporting -= elementExporting;

                stream.Position = 0;

                document = new HtmlFormatProvider().Import(stream);
            }

            return document;
        }
Esempio n. 45
0
        private RadDocument CreateDocument(GridViewDataControl gridView)
        {
            RadDocument document;

            using (var memoryStream = new MemoryStream())
            {
                gridView.ElementExporting += ElementExporting;

                gridView.Export(memoryStream, new GridViewExportOptions
                        {
                            Format = GetFormat(TheExportOptionsViewModel.Value.ExportFileType),
                            Encoding = new UTF8Encoding(true),
                            ShowColumnFooters = gridView.IsGrouping ? gridView.AggregateResults.Count > 1 : gridView.AggregateResults.Count > 0,
                            ShowGroupFooters = gridView.IsGrouping && gridView.AggregateResults.Count > 1,
                            ShowColumnHeaders = true
                        });

                gridView.ElementExporting -= ElementExporting;

                memoryStream.Position = 0;
                document = new HtmlFormatProvider().Import(memoryStream);
                document.SectionDefaultPageOrientation = TheExportOptionsViewModel.Value.PageOrientation;
            }

            return document;
        }
Esempio n. 46
-1
        public static void SaveDocument(RadFlowDocument document, string selectedFormat)
        {
            HtmlFormatProvider formatProvider = new HtmlFormatProvider();

            SaveFileDialog dialog = new SaveFileDialog();
            dialog.Filter = String.Format("{0} files|*{1}|All files (*.*)|*.*",
                selectedFormat,
                formatProvider.SupportedExtensions.First());
            dialog.FilterIndex = 1;

            if (dialog.ShowDialog() == true)
            {
                using (var stream = dialog.OpenFile())
                {
                    formatProvider.Export(document, stream);
                }
            }
        }