Exemplo n.º 1
0
        private void WriteHeaderAndFooter(DocxFile docx, DocxXmlWriter writer)
        {
            writer.WriteStartElement("sectPr");
            int idCounter = 1;

            if (docx.HasHeader)
            {
                string id = "rId" + idCounter;
                writer.WriteElement("headerReference", "id", id, "type", "default");

                this.CreateHeaderOrFooterPart(
                    DocxPackageWriter.HeaderPath,
                    Resources.HeaderContentType,
                    Resources.HeaderRelationshipType,
                    id, "hdr", docx.Header);

                idCounter++;
            }

            if (docx.HasFooter)
            {
                string id = "rId" + idCounter;
                writer.WriteElement("footerReference", "id", id, "type", "default");

                this.CreateHeaderOrFooterPart(
                    DocxPackageWriter.FooterPath,
                    Resources.FooterContentType,
                    Resources.FooterRelationshipType,
                    id, "ftr", docx.Footer);
            }
        }
Exemplo n.º 2
0
        private void WriteHeaderAndFooter(DocxFile docx, DocxXmlWriter writer)
        {
            writer.WriteStartElement("sectPr");
            int idCounter = 1;

            if (docx.HasHeader)
            {
                string id = "rId" + idCounter;
                writer.WriteElement("headerReference", "id", id, "type", "default");

                this.CreateHeaderOrFooterPart(
                    DocxPackageWriter.HeaderPath,
                    Resources.HeaderContentType,
                    Resources.HeaderRelationshipType,
                    id, "hdr", docx.Header);

                idCounter++;
            }

            if (docx.HasFooter)
            {
                string id = "rId" + idCounter;
                writer.WriteElement("footerReference", "id", id, "type", "default");

                this.CreateHeaderOrFooterPart(
                    DocxPackageWriter.FooterPath,
                    Resources.FooterContentType,
                    Resources.FooterRelationshipType,
                    id, "ftr", docx.Footer);
            }
        }
Exemplo n.º 3
0
        public void Write(DocxFile docx)
        {
            this.documentPart = this.CreatePart(
                new Uri(DocxPackageWriter.DocumentPath, UriKind.Relative),
                Resources.DocumentContentType);

            using (DocxXmlWriter writer = new DocxXmlWriter(this.documentPart.GetStream()))
            {
                writer.WriteStartDocument("document");
                writer.WriteStartElement("body");

                this.WriteAltChunks(docx.Body, writer, this.documentPart);

                if (docx.HasHeader || docx.HasHeader)
                {
                    this.WriteHeaderAndFooter(docx, writer);
                }

                writer.WriteEndDocument();
            }

            this.package.CreateRelationship(
                new Uri(DocxPackageWriter.DocumentPath.Substring(1), UriKind.Relative),
                TargetMode.Internal,
                Resources.DocumentRelationshipType, "rId1");
        }
Exemplo n.º 4
0
        private void CreateHeaderOrFooterPart(string partPath, string partContentType, string partRelationshipType, string id, string elementName, DocxContentBuilder chunks)
        {
            Uri         partUri = new Uri(partPath, UriKind.Relative);
            PackagePart part    = this.CreatePart(partUri, partContentType);

            using (DocxXmlWriter writer = new DocxXmlWriter(part.GetStream()))
            {
                writer.WriteStartDocument(elementName);
                this.WriteAltChunks(chunks, writer, part);
                writer.WriteEndDocument();
            }

            CreatePartRelationship(partUri, partRelationshipType, id, this.documentPart);
        }
Exemplo n.º 5
0
        private void WriteAltChunks(DocxContentBuilder chunks, DocxXmlWriter writer, PackagePart parentPart)
        {
            for (int chunkIndex = 0; chunkIndex < chunks.Count; chunkIndex++)
            {
                DocxChunk chunk = chunks[chunkIndex];
                this.altChunkCounter++;

                string altChunkId = DocxPackageWriter.AltChunkPartialId + altChunkCounter;
                writer.WriteElement("altChunk", "id", altChunkId);

                string altChunkPath = DocxPackageWriter.AltChunkPartialPath + altChunkCounter + chunk.Extension;
                this.CreateAltChunkPart(chunk, altChunkPath, altChunkId, parentPart);
            }
        }
Exemplo n.º 6
0
        public void Write(DocxFile docx)
        {
            this.documentPart = this.CreatePart(
                new Uri(DocxPackageWriter.DocumentPath, UriKind.Relative),
                Resources.DocumentContentType);

            using (DocxXmlWriter writer = new DocxXmlWriter(this.documentPart.GetStream()))
            {
                writer.WriteStartDocument("document");
                writer.WriteStartElement("body");

                this.WriteAltChunks(docx.Body, writer, this.documentPart);

                if (docx.HasHeader || docx.HasHeader)
                    this.WriteHeaderAndFooter(docx, writer);
                
                writer.WriteEndDocument();
            }

            this.package.CreateRelationship(
                new Uri(DocxPackageWriter.DocumentPath.Substring(1), UriKind.Relative),
                TargetMode.Internal,
                Resources.DocumentRelationshipType, "rId1");
        }
Exemplo n.º 7
0
        private void CreateHeaderOrFooterPart(string partPath, string partContentType, string partRelationshipType, string id, string elementName, DocxContentBuilder chunks)
        {
            Uri partUri = new Uri(partPath, UriKind.Relative);
            PackagePart part = this.CreatePart(partUri, partContentType);

            using (DocxXmlWriter writer = new DocxXmlWriter(part.GetStream()))
            {
                writer.WriteStartDocument(elementName);
                this.WriteAltChunks(chunks, writer, part);
                writer.WriteEndDocument();
            }

            CreatePartRelationship(partUri, partRelationshipType, id, this.documentPart);
        }
Exemplo n.º 8
0
        private void WriteAltChunks(DocxContentBuilder chunks, DocxXmlWriter writer, PackagePart parentPart)
        {
            for (int chunkIndex = 0; chunkIndex < chunks.Count; chunkIndex++)
            {
                DocxChunk chunk = chunks[chunkIndex];
                this.altChunkCounter++;

                string altChunkId = DocxPackageWriter.AltChunkPartialId + altChunkCounter;
                writer.WriteElement("altChunk", "id", altChunkId);

                string altChunkPath = DocxPackageWriter.AltChunkPartialPath + altChunkCounter + chunk.Extension;
                this.CreateAltChunkPart(chunk, altChunkPath, altChunkId, parentPart);
            }
        }