Example #1
0
        public void ExportToWord(Docx.DocX doc)
        {
            // Skip encrypted scenes.
            var scenes = Scenes.Where(i => !i.IsEncrypted).OrderBy(i => i.SortIndex).ToList();

            if (scenes.Count > 0)
            {
                // Export chapter name.
                Xceed.Document.NET.Paragraph chapterHeader = doc.InsertParagraph();
                chapterHeader.StyleId = "Heading1";
                chapterHeader.Append(Model.Name);

                doc.InsertParagraph();
                doc.InsertParagraph();
                doc.InsertParagraph();

                for (int i = 0; i < scenes.Count; i++)
                {
                    SceneViewModel scene = scenes[i];
                    scene.ExportToWord(doc);
                    if (i < Scenes.Count - 1)
                    {
                        Xceed.Document.NET.Paragraph p = doc.InsertParagraph();
                        p.StyleId = "SceneBreak";
                        p.Append("\n*\t\t*\t\t*\n");
                    }
                }
                doc.Paragraphs.Last().InsertPageBreakAfterSelf();
            }
        }
Example #2
0
 private void CreateSixthParagraph(string developerReference)
 {
     Xceed.Document.NET.Paragraph developer =
         document.InsertParagraph("\t6. Разработчик: ").
         Font("Times New Roman").
         FontSize(12).
         Bold();
     developer.Append(developerReference).Font("Times New Roman").FontSize(12);
 }
Example #3
0
 private void CreateFifthParagraph(bool isExam, bool isTest)
 {
     Xceed.Document.NET.Paragraph controlForms =
         document.InsertParagraph("\t5. Форма контроля: ").
         Font("Times New Roman").
         FontSize(12).
         Bold();
     if (isTest && isExam)
     {
         controlForms.Append("зачёт/экзамен.").Font("Times New Roman").FontSize(12);
     }
     else if (isExam || !isExam && !isTest)
     {
         controlForms.Append("экзамен.").Font("Times New Roman").FontSize(12);
     }
     else if (isTest)
     {
         controlForms.Append("зачёт.").Font("Times New Roman").FontSize(12);
     }
 }
Example #4
0
 private void CreateSecondParagraph(int creditUnits)
 {
     Xceed.Document.NET.Paragraph disciplineScope =
         document.InsertParagraph("\t2. Объем дисциплины: ").
         Font("Times New Roman").
         FontSize(12).
         Bold();
     if (creditUnits != 0)
     {
         disciplineScope.Append(ChangeDeclination(creditUnits)).
         Font("Times New Roman").
         FontSize(12);
     }
 }
Example #5
0
        public void ExportToWord(Docx.DocX doc)
        {
            // Format title page of the document.
            Xceed.Document.NET.Paragraph p = doc.InsertParagraph();
            p.Append("\n\n" + Model.Name);
            p.StyleId = "Title";

            if (!string.IsNullOrWhiteSpace(Model.Subtitle))
            {
                p = doc.InsertParagraph();
                p.Append(Model.Subtitle);
                p.StyleId = "Subtitle";
            }
            if (!string.IsNullOrWhiteSpace(Model.Author))
            {
                p = doc.InsertParagraph();
                p.Append("\n\n" + Model.Author);
                p.StyleId = "Subtitle";
            }
            p.InsertPageBreakAfterSelf();

            // Insert copyright page.
            if (Model.FlowDocumentId.HasValue)
            {
                FlowDocument copyrightFd = new FlowDocument(Model.Connection);
                copyrightFd.id = Model.FlowDocumentId.Value;
                copyrightFd.Load();

                FlowDocumentViewModel copyrightVm = new FlowDocumentViewModel(copyrightFd, DialogOwner);

                foreach (WinDoc.Block block in copyrightVm.Document.Blocks)
                {
                    if (block is WinDoc.Paragraph)
                    {
                        FlowDocumentExporter.AddParagraph((WinDoc.Paragraph)block, doc);
                    }
                }

                p.InsertPageBreakAfterSelf();
            }

            // Insert eBook table of contents.

            // This doesn't make sense to me. Xceed's documentation says "A key-value dictionary where the key is a TableOfContentSwitches
            // and the value is the parameter of the switch."
            // I have no idea what the string values are supposed to be. Empty strings seem to work.
            Dictionary <Xceed.Document.NET.TableOfContentsSwitches, string> tocParams = new Dictionary <Xceed.Document.NET.TableOfContentsSwitches, string>();

            tocParams[Xceed.Document.NET.TableOfContentsSwitches.H] = ""; // TOC entries are clickable hyperlinks.
            tocParams[Xceed.Document.NET.TableOfContentsSwitches.N] = ""; // Omits page numbers.
            tocParams[Xceed.Document.NET.TableOfContentsSwitches.Z] = ""; // Hides tab leader and page numbers...?
            tocParams[Xceed.Document.NET.TableOfContentsSwitches.U] = ""; // Uses the applied paragraph outline level...?
            Xceed.Document.NET.TableOfContents toc = doc.InsertTableOfContents("Table of Contents", tocParams);
            doc.Paragraphs.Last().InsertPageBreakAfterSelf();

            for (int i = 0; i < Chapters.Count; i++)
            {
                ChapterViewModel chapter = Chapters[i];
                chapter.ExportToWord(doc);
            }
        }
        public static void AddInline(Inline inline, Xceed.Document.NET.Paragraph p, Xceed.Document.NET.Formatting inheritFormat = null)
        {
            if (inline is Run)
            {
                Run run = (Run)inline;
                Xceed.Document.NET.Formatting f = new Xceed.Document.NET.Formatting();
                Color c = (run.Foreground as SolidColorBrush).Color;
                f.FontColor  = System.Drawing.Color.FromArgb(c.A, c.R, c.G, c.B);
                f.FontFamily = new Xceed.Document.NET.Font(run.FontFamily.Source);
                if (run.FontWeight == FontWeights.Bold)
                {
                    f.Bold = true;
                }
                if (run.FontStyle == FontStyles.Italic)
                {
                    f.Italic = true;
                }
                foreach (var dec in run.TextDecorations)
                {
                    if (dec.Location == TextDecorationLocation.Underline)
                    {
                        f.UnderlineStyle = Xceed.Document.NET.UnderlineStyle.singleLine;
                        f.UnderlineColor = f.FontColor;
                    }
                }

                f.Size = run.FontSize;

                if (inheritFormat != null)
                {
                    f = inheritFormat;
                }

                p.Append(run.Text, f);
            }
            else if (inline is Span)
            {
                Span span = (Span)inline;

                Xceed.Document.NET.Formatting f = new Xceed.Document.NET.Formatting();
                Color c = (span.Foreground as SolidColorBrush).Color;
                f.FontColor  = System.Drawing.Color.FromArgb(c.A, c.R, c.G, c.B);
                f.FontFamily = new Xceed.Document.NET.Font(span.FontFamily.Source);
                if (span.FontWeight == FontWeights.Bold)
                {
                    f.Bold = true;
                }
                if (span.FontStyle == FontStyles.Italic)
                {
                    f.Italic = true;
                }
                foreach (var dec in span.TextDecorations)
                {
                    if (dec.Location == TextDecorationLocation.Underline)
                    {
                        f.UnderlineStyle = Xceed.Document.NET.UnderlineStyle.singleLine;
                        f.UnderlineColor = f.FontColor;
                    }
                }

                f.Size = span.FontSize;

                if (inheritFormat != null)
                {
                    f = inheritFormat;
                }

                foreach (var spanInline in span.Inlines)
                {
                    AddInline(spanInline, p, f);
                }
            }
        }