本文整理汇总了C#中DocumentBuilder.MoveToHeaderFooter方法的典型用法代码示例。如果您正苦于以下问题:C# DocumentBuilder.MoveToHeaderFooter方法的具体用法?C# DocumentBuilder.MoveToHeaderFooter怎么用?C# DocumentBuilder.MoveToHeaderFooter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DocumentBuilder
的用法示例。
在下文中一共展示了DocumentBuilder.MoveToHeaderFooter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DifferentHeaders
public void DifferentHeaders()
{
//ExStart
//ExFor:PageSetup.DifferentFirstPageHeaderFooter
//ExFor:PageSetup.OddAndEvenPagesHeaderFooter
//ExSummary:Creates headers and footers different for first, even and odd pages using DocumentBuilder.
DocumentBuilder builder = new DocumentBuilder();
PageSetup ps = builder.PageSetup;
ps.DifferentFirstPageHeaderFooter = true;
ps.OddAndEvenPagesHeaderFooter = true;
builder.MoveToHeaderFooter(HeaderFooterType.HeaderFirst);
builder.Writeln("First page header.");
builder.MoveToHeaderFooter(HeaderFooterType.HeaderEven);
builder.Writeln("Even pages header.");
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
builder.Writeln("Odd pages header.");
// Move back to the main story of the first section.
builder.MoveToSection(0);
builder.Writeln("Text page 1.");
builder.InsertBreak(BreakType.PageBreak);
builder.Writeln("Text page 2.");
builder.InsertBreak(BreakType.PageBreak);
builder.Writeln("Text page 3.");
builder.Document.Save(MyDir + @"\Artifacts\PageSetup.DifferentHeaders.doc");
//ExEnd
}
示例2: Main
static void Main(string[] args)
{
string mypath = "";
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Create the headers.
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
builder.Write("Header Text goes here...");
//add footer having current date
builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);
builder.InsertField("Date", "");
doc.UpdateFields();
doc.Save(mypath + "Insert Headers and Footers.doc");
}
示例3: Run
public static void Run()
{
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_WorkingWithFields();
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Insert a few page breaks (just for testing)
for (int i = 0; i < 5; i++)
builder.InsertBreak(BreakType.PageBreak);
// Move the DocumentBuilder cursor into the primary footer.
builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);
// We want to insert a field like this:
// { IF {PAGE} <> {NUMPAGES} "See Next Page" "Last Page" }
Field field = builder.InsertField(@"IF ");
builder.MoveTo(field.Separator);
builder.InsertField("PAGE");
builder.Write(" <> ");
builder.InsertField("NUMPAGES");
builder.Write(" \"See Next Page\" \"Last Page\" ");
// Finally update the outer field to recalcaluate the final value. Doing this will automatically update
// the inner fields at the same time.
field.Update();
doc.Save(dataDir + "InsertNestedFields Out.docx");
Console.WriteLine("\nInserted nested fields in the document successfully.\nFile saved at " + dataDir + "InsertNestedFields Out.docx");
}
示例4: Main
public static void Main()
{
// The path to the documents directory.
string dataDir = Path.GetFullPath("../../../Data/");
//ExStart
//ExFor:DocumentBuilder.InsertField(string)
//ExId:DocumentBuilderInsertNestedFields
//ExSummary:Demonstrates how to insert fields nested within another field using DocumentBuilder.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Insert a few page breaks (just for testing)
for (int i = 0; i < 5; i++)
builder.InsertBreak(BreakType.PageBreak);
// Move the DocumentBuilder cursor into the primary footer.
builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);
// We want to insert a field like this:
// { IF {PAGE} <> {NUMPAGES} "See Next Page" "Last Page" }
Field field = builder.InsertField(@"IF ");
builder.MoveTo(field.Separator);
builder.InsertField("PAGE");
builder.Write(" <> ");
builder.InsertField("NUMPAGES");
builder.Write(" \"See Next Page\" \"Last Page\" ");
// Finally update the outer field to recalcaluate the final value. Doing this will automatically update
// the inner fields at the same time.
field.Update();
doc.Save(dataDir + "InsertNestedFields Out.docx");
//ExEnd
}
示例5: ChangeHeader
public static void ChangeHeader(string documentPath)
{
Document doc = new Document(documentPath);
DocumentBuilder builder = new DocumentBuilder(doc);
// --- Create header ---
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
// Specify header title for the first page.
builder.Write("Aspose.Words Header");
// --- Create footer for pages other than first. ---
builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);
// Specify Footer text.
builder.Write("Aspose.Words Footer");
// Save the resulting document.
doc.Save(documentPath);
}
示例6: HeadersAndFooters
public void HeadersAndFooters()
{
//ExStart
//ExFor:DocumentBuilder.#ctor(Document)
//ExFor:DocumentBuilder.MoveToHeaderFooter
//ExFor:DocumentBuilder.MoveToSection
//ExFor:DocumentBuilder.InsertBreak
//ExFor:HeaderFooterType
//ExFor:PageSetup.DifferentFirstPageHeaderFooter
//ExFor:PageSetup.OddAndEvenPagesHeaderFooter
//ExFor:BreakType
//ExId:DocumentBuilderMoveToHeaderFooter
//ExSummary:Creates headers and footers in a document using DocumentBuilder.
// Create a blank document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Specify that we want headers and footers different for first, even and odd pages.
builder.PageSetup.DifferentFirstPageHeaderFooter = true;
builder.PageSetup.OddAndEvenPagesHeaderFooter = true;
// Create the headers.
builder.MoveToHeaderFooter(HeaderFooterType.HeaderFirst);
builder.Write("Header First");
builder.MoveToHeaderFooter(HeaderFooterType.HeaderEven);
builder.Write("Header Even");
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
builder.Write("Header Odd");
// Create three pages in the document.
builder.MoveToSection(0);
builder.Writeln("Page1");
builder.InsertBreak(BreakType.PageBreak);
builder.Writeln("Page2");
builder.InsertBreak(BreakType.PageBreak);
builder.Writeln("Page3");
doc.Save(MyDir + @"\Artifacts\DocumentBuilder.HeadersAndFooters.doc");
//ExEnd
}
示例7: InsertBarcodeIntoFooter
// ExStart:InsertBarcodeIntoFooter
private static void InsertBarcodeIntoFooter(DocumentBuilder builder, Section section, int pageId, HeaderFooterType footerType)
{
// Move to the footer type in the specific section.
builder.MoveToSection(section.Document.IndexOf(section));
builder.MoveToHeaderFooter(footerType);
// Insert the barcode, then move to the next line and insert the ID along with the page number.
// Use pageId if you need to insert a different barcode on each page. 0 = First page, 1 = Second page etc.
builder.InsertImage(System.Drawing.Image.FromFile( RunExamples.GetDataDir_WorkingWithImages() + "Barcode1.png"));
builder.Writeln();
builder.Write("1234567890");
builder.InsertField("PAGE");
// Create a right aligned tab at the right margin.
double tabPos = section.PageSetup.PageWidth - section.PageSetup.RightMargin - section.PageSetup.LeftMargin;
builder.CurrentParagraph.ParagraphFormat.TabStops.Add(new TabStop(tabPos, TabAlignment.Right, TabLeader.None));
// Move to the right hand side of the page and insert the page and page total.
builder.Write(ControlChar.Tab);
builder.InsertField("PAGE");
builder.Write(" of ");
builder.InsertField("NUMPAGES");
}
示例8: PageNumbering
public void PageNumbering()
{
//ExStart
//ExFor:PageSetup.RestartPageNumbering
//ExFor:PageSetup.PageStartingNumber
//ExFor:PageSetup.PageNumberStyle
//ExFor:DocumentBuilder.InsertField(string, string)
//ExSummary:Shows how to control page numbering per section.
// This document has two sections, but no page numbers yet.
Document doc = new Document(MyDir + "PageSetup.PageNumbering.doc");
// Use document builder to create a header with a page number field for the first section.
// The page number will look like "Page V".
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToSection(0);
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
builder.Write("Page ");
builder.InsertField("PAGE", "");
// Set first section page numbering.
Section section = doc.Sections[0];
section.PageSetup.RestartPageNumbering = true;
section.PageSetup.PageStartingNumber = 5;
section.PageSetup.PageNumberStyle = NumberStyle.UppercaseRoman;
// Create a header for the section section.
// The page number will look like " - 10 - ".
builder.MoveToSection(1);
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
builder.Write(" - ");
builder.InsertField("PAGE", "");
builder.Write(" - ");
// Set second section page numbering.
section = doc.Sections[1];
section.PageSetup.PageStartingNumber = 10;
section.PageSetup.RestartPageNumbering = true;
section.PageSetup.PageNumberStyle = NumberStyle.Arabic;
doc.Save(MyDir + "PageSetup.PageNumbering Out.doc");
//ExEnd
}
示例9: Primer
//ExStart
//ExId:HeaderFooterPrimer
//ExSummary:Maybe a bit complicated example, but demonstrates many things that can be done with headers/footers.
public void Primer()
{
Aspose.Words.Document doc = new Aspose.Words.Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Aspose.Words.Section currentSection = builder.CurrentSection;
Aspose.Words.PageSetup pageSetup = currentSection.PageSetup;
// Specify if we want headers/footers of the first page to be different from other pages.
// You can also use PageSetup.OddAndEvenPagesHeaderFooter property to specify
// different headers/footers for odd and even pages.
pageSetup.DifferentFirstPageHeaderFooter = true;
// --- Create header for the first page. ---
pageSetup.HeaderDistance = 20;
builder.MoveToHeaderFooter(HeaderFooterType.HeaderFirst);
builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
// Set font properties for header text.
builder.Font.Name = "Arial";
builder.Font.Bold = true;
builder.Font.Size = 14;
// Specify header title for the first page.
builder.Write("Aspose.Words Header/Footer Creation Primer - Title Page.");
// --- Create header for pages other than first. ---
pageSetup.HeaderDistance = 20;
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
// Insert absolutely positioned image into the top/left corner of the header.
// Distance from the top/left edges of the page is set to 10 points.
string imageFileName = ExDir + "Aspose.Words.gif";
builder.InsertImage(imageFileName, RelativeHorizontalPosition.Page, 10, RelativeVerticalPosition.Page, 10, 50, 50, WrapType.Through);
builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;
// Specify another header title for other pages.
builder.Write("Aspose.Words Header/Footer Creation Primer.");
// --- Create footer for pages other than first. ---
builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);
// We use table with two cells to make one part of the text on the line (with page numbering)
// to be aligned left, and the other part of the text (with copyright) to be aligned right.
builder.StartTable();
// Clear table borders.
builder.CellFormat.ClearFormatting();
builder.InsertCell();
// Set first cell to 1/3 of the page width.
builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(100 / 3);
// Insert page numbering text here.
// It uses PAGE and NUMPAGES fields to auto calculate current page number and total number of pages.
builder.Write("Page ");
builder.InsertField("PAGE", "");
builder.Write(" of ");
builder.InsertField("NUMPAGES", "");
// Align this text to the left.
builder.CurrentParagraph.ParagraphFormat.Alignment = ParagraphAlignment.Left;
builder.InsertCell();
// Set the second cell to 2/3 of the page width.
builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(100 * 2 / 3);
builder.Write("(C) 2001 Aspose Pty Ltd. All rights reserved.");
// Align this text to the right.
builder.CurrentParagraph.ParagraphFormat.Alignment = ParagraphAlignment.Right;
builder.EndRow();
builder.EndTable();
builder.MoveToDocumentEnd();
// Make page break to create a second page on which the primary headers/footers will be seen.
builder.InsertBreak(BreakType.PageBreak);
// Make section break to create a third page with different page orientation.
builder.InsertBreak(BreakType.SectionBreakNewPage);
// Get the new section and its page setup.
currentSection = builder.CurrentSection;
pageSetup = currentSection.PageSetup;
// Set page orientation of the new section to landscape.
pageSetup.Orientation = Orientation.Landscape;
// This section does not need different first page header/footer.
// We need only one title page in the document and the header/footer for this page
// has already been defined in the previous section
pageSetup.DifferentFirstPageHeaderFooter = false;
// This section displays headers/footers from the previous section by default.
// Call currentSection.HeadersFooters.LinkToPrevious(false) to cancel this.
// Page width is different for the new section and therefore we need to set
//.........这里部分代码省略.........
示例10: InsertWatermark
public void InsertWatermark()
{
//ExStart
//ExFor:HeaderFooterType
//ExFor:DocumentBuilder.MoveToHeaderFooter
//ExFor:PageSetup.PageWidth
//ExFor:PageSetup.PageHeight
//ExFor:DocumentBuilder.InsertImage(Image)
//ExFor:WrapType
//ExFor:RelativeHorizontalPosition
//ExFor:RelativeVerticalPosition
//ExSummary:Inserts a watermark image into a document using DocumentBuilder.
Aspose.Words.Document doc = new Aspose.Words.Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// The best place for the watermark image is in the header or footer so it is shown on every page.
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
Image image = Image.FromFile(ExDir + "Watermark.png");
// Insert a floating picture.
Shape shape = builder.InsertImage(image);
shape.WrapType = WrapType.None;
shape.BehindText = true;
shape.RelativeHorizontalPosition = RelativeHorizontalPosition.Page;
shape.RelativeVerticalPosition = RelativeVerticalPosition.Page;
// Calculate image left and top position so it appears in the centre of the page.
shape.Left = (builder.PageSetup.PageWidth - shape.Width) / 2;
shape.Top = (builder.PageSetup.PageHeight - shape.Height) / 2;
doc.Save(ExDir + "DocumentBuilder.InsertWatermark Out.doc");
//ExEnd
}
示例11: AddsHeadersToSection_WhenStartVisitingFromSection
public void AddsHeadersToSection_WhenStartVisitingFromSection()
{
var builder = new DocumentBuilder();
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
builder.MoveToHeaderFooter(HeaderFooterType.HeaderEven);
Section section = builder.Document.FirstSection;
var sectionProxy = new SectionProxy();
var firstHeaderProxy = A.Fake<HeaderProxy>();
var secondHeaderProxy = A.Fake<HeaderProxy>();
A.CallTo(() => this.proxyFactory.CreateSection()).Returns(sectionProxy);
A.CallTo(() => this.proxyFactory.CreateHeader("Primary")).Returns(firstHeaderProxy);
A.CallTo(() => this.proxyFactory.CreateHeader("Even")).Returns(secondHeaderProxy);
section.Accept(this.testee);
sectionProxy.Headers.Should().Contain(firstHeaderProxy)
.And.Contain(secondHeaderProxy);
}
示例12: HeadersAndFooters
public static void HeadersAndFooters(string dataDir)
{
// ExStart:DocumentBuilderHeadersAndFooters
// Create a blank document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Specify that we want headers and footers different for first, even and odd pages.
builder.PageSetup.DifferentFirstPageHeaderFooter = true;
builder.PageSetup.OddAndEvenPagesHeaderFooter = true;
// Create the headers.
builder.MoveToHeaderFooter(HeaderFooterType.HeaderFirst);
builder.Write("Header First");
builder.MoveToHeaderFooter(HeaderFooterType.HeaderEven);
builder.Write("Header Even");
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
builder.Write("Header Odd");
// Create three pages in the document.
builder.MoveToSection(0);
builder.Writeln("Page1");
builder.InsertBreak(BreakType.PageBreak);
builder.Writeln("Page2");
builder.InsertBreak(BreakType.PageBreak);
builder.Writeln("Page3");
dataDir = dataDir + "DocumentBuilder.HeadersAndFooters_out.doc";
doc.Save(dataDir);
// ExEnd:DocumentBuilderHeadersAndFooters
Console.WriteLine("\nHeaders and footers created successfully using DocumentBuilder.\nFile saved at " + dataDir);
}
示例13: DocumentBuilder
void IFieldMergingCallback.FieldMerging(FieldMergingArgs e)
{
var builder = new DocumentBuilder(e.Document);
if (e.Field.Start.GetAncestor(NodeType.HeaderFooter) != null)
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
builder.MoveToMergeField(e.FieldName);
var value = string.Empty;
if (e.FieldValue != null)
value = (string)e.FieldValue;
builder.InsertHtml(value);
e.Text = "";
}
示例14: MergeDocText_RepeatableInHeaderAndFooter
public void MergeDocText_RepeatableInHeaderAndFooter()
{
var doc = new Document();
var builder = new DocumentBuilder(doc);
builder.Write("{{ Name }}");
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
builder.Write("{{ each Items }}");
builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);
builder.Write("{{ end each }}");
doc.AssertXml(@"
<Document>
<Section>
<Body>
<Paragraph>
<Run>{{ Name }}</Run>
</Paragraph>
</Body>
<HeaderFooter headerfootertype='HeaderPrimary' islinkedtoprevious='False' storytype='PrimaryHeader'>
<Paragraph>
<Run>{{ each Items }}</Run>
</Paragraph>
</HeaderFooter>
<HeaderFooter headerfootertype='FooterPrimary' islinkedtoprevious='False' storytype='PrimaryFooter'>
<Paragraph>
<Run>{{ end each }}</Run>
</Paragraph>
</HeaderFooter>
</Section>
</Document>");
var data = new
{
Name = "Shopping List",
Items = new[] {
new {Name = "Milk" },
new {Name = "Eggs" },
new {Name = "Artisan Bread" }
},
};
doc.Merge(data);
doc.AssertXml(@"
<Document>
<Section>
<Body>
<Paragraph>
<Run>Milk</Run>
</Paragraph>
</Body>
</Section>
<Section>
<Body>
<Paragraph>
<Run>Eggs</Run>
</Paragraph>
</Body>
</Section>
<Section>
<Body>
<Paragraph>
<Run>Artisan Bread</Run>
</Paragraph>
</Body>
</Section>
</Document>");
}
示例15: GenerateOutPutDocument
protected void GenerateOutPutDocument(string outFileName)
{
//Open the template document
Document doc = new Document(Server.MapPath("~/App_Data/DocumentBuilderDemo.docx"));
//Once the builder is created, its cursor is positioned at the beginning of the document.
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
BarCodeBuilder barCode = CreateBarCode();
builder.InsertImage(barCode.BarCodeImage);
builder.MoveToDocumentStart();
System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath("~/Web/Images/spring-air-logo-header.jpg"));
builder.InsertImage(image);
builder.InsertParagraph();
builder.ParagraphFormat.ClearFormatting();
builder.Font.ClearFormatting();
builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
builder.ParagraphFormat.Shading.ForegroundPatternColor = System.Drawing.Color.White;
builder.ParagraphFormat.Shading.Texture = TextureIndex.TextureSolid;
builder.ParagraphFormat.LeftIndent = ConvertUtil.InchToPoint(0.3);
builder.ParagraphFormat.SpaceBefore = 12;
builder.ParagraphFormat.SpaceAfter = 12;
builder.Font.Name = "Arial";
builder.Font.Size = 9;
builder.Write("ELECTRONIC TICKET - PASSENGER ITINERARY/RECEIPT");
builder.InsertBreak(BreakType.LineBreak);
builder.Writeln("CUSTOMER COPY - Powered by ASPOSE");
builder.ParagraphFormat.ClearFormatting();
builder.InsertHtml("<hr>");
BuildBookingTable(builder);
builder.MoveToDocumentEnd();
builder.InsertBreak(BreakType.LineBreak);
builder.InsertHtml("<hr>");
builder.InsertParagraph();
builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
builder.InsertImage(barCode.BarCodeImage);
doc.Save(Response, outFileName, ContentDisposition.Inline, null);
Response.End();
}