public FooterMapping(ConversionContext ctx, FooterPart part, CharacterRange ftr)
     : base(ctx, part)
 {
     _ftr = ftr;
 }
 public NumberingMapping(ConversionContext ctx, WordDocument parentDoc)
     : base(XmlWriter.Create(ctx.Docx.MainDocumentPart.NumberingDefinitionsPart.GetStream(), ctx.WriterSettings))
 {
     _ctx       = ctx;
     _parentDoc = parentDoc;
 }
        public static XmlDocument Convert(WordDocument doc, WordprocessingDocument docx)
        {
            ConversionContext context = new ConversionContext(doc);

            using (docx)
            {
                //Setup the writer
                XmlWriterSettings xws = new XmlWriterSettings();
                xws.OmitXmlDeclaration = false;
                xws.CloseOutput        = true;
                xws.Encoding           = Encoding.UTF8;
                xws.ConformanceLevel   = ConformanceLevel.Document;

                //Setup the context
                context.WriterSettings = xws;
                context.Docx           = docx;

                //convert the macros
                //if (docx.DocumentType == OpenXmlPackage.DocumentType.MacroEnabledDocument ||
                //    docx.DocumentType == OpenXmlPackage.DocumentType.MacroEnabledTemplate)
                //{
                //    doc.Convert(new MacroBinaryMapping(context));
                //    doc.Convert(new MacroDataMapping(context));
                //}

                //convert the command table
                //doc.CommandTable.Convert(new CommandTableMapping(context));

                //Write styles.xml
                // doc.Styles.Convert(new StyleSheetMapping(context, doc, docx.MainDocumentPart.StyleDefinitionsPart));

                //Write numbering.xml
                // doc.ListTable.Convert(new NumberingMapping(context, doc));

                //Write fontTable.xml
                //doc.FontTable.Convert(new FontTableMapping(context, docx.MainDocumentPart.FontTablePart));

                //write document.xml and the header and footers
                doc.Convert(new MainDocumentMapping(context, context.Docx.MainDocumentPart));

                //write the footnotes
                //doc.Convert(new FootnotesMapping(context));

                //write the endnotes
                //doc.Convert(new EndnotesMapping(context));

                //write the comments
                //doc.Convert(new CommentsMapping(context));

                //write settings.xml at last because of the rsid list
                //doc.DocumentProperties.Convert(new SettingsMapping(context, docx.MainDocumentPart.SettingsPart));

                //convert the glossary subdocument
                //if (doc.Glossary != null)
                //{
                //    doc.Glossary.Convert(new GlossaryMapping(context, context.Docx.MainDocumentPart.GlossaryPart));
                //    doc.Glossary.FontTable.Convert(new FontTableMapping(context, docx.MainDocumentPart.GlossaryPart.FontTablePart));
                //    //doc.Glossary.Styles.Convert(new StyleSheetMapping(context, doc.Glossary, docx.MainDocumentPart.GlossaryPart.StyleDefinitionsPart));

                //    //write settings.xml at last because of the rsid list
                //    doc.Glossary.DocumentProperties.Convert(new SettingsMapping(context, docx.MainDocumentPart.GlossaryPart.SettingsPart));
                //}
                XmlDocument xdoc = new XmlDocument();
                xdoc.Load(context.Docx.MainDocumentPart.GetStream());
                return(xdoc);
                //const string wordNamespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";

                //StringBuilder textBuilder = new StringBuilder();

                //NameTable nt = new NameTable();
                //XmlNamespaceManager nsManager = new XmlNamespaceManager(nt);
                //nsManager.AddNamespace("w", wordNamespace);

                //XmlNodeList parNodes = xdoc.SelectNodes("//w:p", nsManager);

                //foreach (XmlNode parNode in parNodes)
                //{
                //    XmlNodeList textNodes = parNode.SelectNodes(".//w:t", nsManager);

                //    foreach (System.Xml.XmlNode textNode in textNodes)
                //    {
                //        textBuilder.Append(textNode.InnerText);
                //    }
                //    textBuilder.Append(Environment.NewLine);
                //}
            }
        }
Example #4
0
 public StyleSheetMapping(ConversionContext ctx, WordDocument parentDoc, OpenXmlPart targetPart)
     : base(XmlWriter.Create(targetPart.GetStream(), ctx.WriterSettings))
 {
     _ctx       = ctx;
     _parentDoc = parentDoc;
 }
Example #5
0
 public EndnotesMapping(ConversionContext ctx)
     : base(ctx, ctx.Docx.MainDocumentPart.EndnotesPart)
 {
     _ctx = ctx;
 }
 public MainDocumentMapping(ConversionContext ctx, ContentPart targetPart)
     : base(ctx, targetPart)
 {
 }
Example #7
0
 public SettingsMapping(ConversionContext ctx, OpenXmlPart targetPart)
     : base(XmlWriter.Create(targetPart.GetStream(), ctx.WriterSettings))
 {
     _ctx = ctx;
 }
 public CommandTableMapping(ConversionContext ctx)
     : base(XmlWriter.Create(ctx.Docx.MainDocumentPart.CustomizationsPart.GetStream(), ctx.WriterSettings))
 {
     _ctx = ctx;
 }
Example #9
0
 public CommentsMapping(ConversionContext ctx)
     : base(ctx, ctx.Docx.MainDocumentPart.CommentsPart)
 {
     _ctx = ctx;
 }
 public HeaderMapping(ConversionContext ctx, HeaderPart part, CharacterRange hdr)
     : base(ctx, part)
 {
     _hdr = hdr;
 }
 public MacroDataMapping(ConversionContext ctx)
     : base(ctx, ctx.Docx.MainDocumentPart.VbaProjectPart.VbaDataPart)
 {
     _ctx = ctx;
 }
 public GlossaryMapping(ConversionContext ctx, ContentPart targetPart)
     : base(ctx, targetPart)
 {
 }
Example #13
0
 public TextboxMapping(ConversionContext ctx, ContentPart targetpart, XmlWriter writer)
     : base(ctx, targetpart, writer)
 {
     TextboxCount++;
     _textboxIndex = TextboxCount - 1;
 }