本文整理汇总了C#中DocumentBuilder.InsertBreak方法的典型用法代码示例。如果您正苦于以下问题:C# DocumentBuilder.InsertBreak方法的具体用法?C# DocumentBuilder.InsertBreak怎么用?C# DocumentBuilder.InsertBreak使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DocumentBuilder
的用法示例。
在下文中一共展示了DocumentBuilder.InsertBreak方法的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: 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");
}
示例3: ClearFormatting
public void ClearFormatting()
{
//ExStart
//ExFor:DocumentBuilder.PageSetup
//ExFor:DocumentBuilder.InsertBreak
//ExFor:DocumentBuilder.Document
//ExFor:PageSetup
//ExFor:PageSetup.Orientation
//ExFor:PageSetup.VerticalAlignment
//ExFor:PageSetup.ClearFormatting
//ExFor:Orientation
//ExFor:PageVerticalAlignment
//ExFor:BreakType
//ExSummary:Shows how to insert sections using DocumentBuilder, specify page setup for a section and reset page setup to defaults.
DocumentBuilder builder = new DocumentBuilder();
// Modify the first section in the document.
builder.PageSetup.Orientation = Orientation.Landscape;
builder.PageSetup.VerticalAlignment = PageVerticalAlignment.Center;
builder.Writeln("Section 1, landscape oriented and text vertically centered.");
// Start a new section and reset its formatting to defaults.
builder.InsertBreak(BreakType.SectionBreakNewPage);
builder.PageSetup.ClearFormatting();
builder.Writeln("Section 2, back to default Letter paper size, portrait orientation and top alignment.");
builder.Document.Save(MyDir + "PageSetup.ClearFormatting Out.doc");
//ExEnd
}
示例4: Protect
public void Protect()
{
//ExStart
//ExFor:Document.Protect(ProtectionType)
//ExFor:ProtectionType
//ExFor:Section.ProtectedForForms
//ExSummary:Protects a section so only editing in form fields is possible.
// Create a blank document
Document doc = new Document();
// Insert two sections with some text
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Writeln("Section 1. Unprotected.");
builder.InsertBreak(BreakType.SectionBreakContinuous);
builder.Writeln("Section 2. Protected.");
// Section protection only works when document protection is turned and only editing in form fields is allowed.
doc.Protect(ProtectionType.AllowOnlyFormFields);
// By default, all sections are protected, but we can selectively turn protection off.
doc.Sections[0].ProtectedForForms = false;
builder.Document.Save(MyDir + @"\Artifacts\Section.Protect.doc");
//ExEnd
}
示例5: CreateDocumentFillWithDummyText
/// <summary>
/// Create new document with text
/// </summary>
internal static Document CreateDocumentFillWithDummyText()
{
Document doc = new Document();
//Remove the previous changes of the document
doc.RemoveAllChildren();
//Set the document author
doc.BuiltInDocumentProperties.Author = "Test Author";
DocumentBuilder builder = new DocumentBuilder(doc);
//Insert new table with two rows and two cells
InsertTable(doc);
builder.Writeln("Hello World!");
// Continued on page 2 of the document content
builder.InsertBreak(BreakType.PageBreak);
//Insert TOC entries
InsertToc(doc);
return doc;
}
示例6: 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
}
示例7: Run
public static void Run()
{
// ExStart:DocumentBuilderInsertBreak
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_WorkingWithDocument();
// Initialize document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Writeln("This is page 1.");
builder.InsertBreak(BreakType.PageBreak);
builder.Writeln("This is page 2.");
builder.InsertBreak(BreakType.PageBreak);
builder.Writeln("This is page 3.");
dataDir = dataDir + "DocumentBuilderInsertBreak_out.doc";
doc.Save(dataDir);
// ExEnd:DocumentBuilderInsertBreak
Console.WriteLine("\nPage breaks inserted into a document using DocumentBuilder.\nFile saved at " + dataDir);
}
示例8: ConvertImageToPdf
/// <summary>
/// Converts an image to PDF using Aspose.Words for .NET.
/// </summary>
/// <param name="inputFileName">File name of input image file.</param>
/// <param name="outputFileName">Output PDF file name.</param>
public static void ConvertImageToPdf(string inputFileName, string outputFileName)
{
Console.WriteLine("Converting " + inputFileName + " to PDF ....");
// ExStart:ConvertImageToPdf
// Create Document and DocumentBuilder.
// The builder makes it simple to add content to the document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Read the image from file, ensure it is disposed.
using (Image image = Image.FromFile(inputFileName))
{
// Find which dimension the frames in this image represent. For example
// The frames of a BMP or TIFF are "page dimension" whereas frames of a GIF image are "time dimension".
FrameDimension dimension = new FrameDimension(image.FrameDimensionsList[0]);
// Get the number of frames in the image.
int framesCount = image.GetFrameCount(dimension);
// Loop through all frames.
for (int frameIdx = 0; frameIdx < framesCount; frameIdx++)
{
// Insert a section break before each new page, in case of a multi-frame TIFF.
if (frameIdx != 0)
builder.InsertBreak(BreakType.SectionBreakNewPage);
// Select active frame.
image.SelectActiveFrame(dimension, frameIdx);
// We want the size of the page to be the same as the size of the image.
// Convert pixels to points to size the page to the actual image size.
PageSetup ps = builder.PageSetup;
ps.PageWidth = ConvertUtil.PixelToPoint(image.Width, image.HorizontalResolution);
ps.PageHeight = ConvertUtil.PixelToPoint(image.Height, image.VerticalResolution);
// Insert the image into the document and position it at the top left corner of the page.
builder.InsertImage(
image,
RelativeHorizontalPosition.Page,
0,
RelativeVerticalPosition.Page,
0,
ps.PageWidth,
ps.PageHeight,
WrapType.None);
}
}
// Save the document to PDF.
doc.Save(outputFileName);
// ExEnd:ConvertImageToPdf
}
示例9: Convert
/// <summary>
/// Convert Excel workbook to Word document
/// </summary>
/// <param name="workbook">Input workbook</param>
/// <returns>Word document</returns>
internal Document Convert(Workbook workbook)
{
//Create new document
Document doc = new Document();
//Create an instance of the DocumentBuilder class
DocumentBuilder builder = new DocumentBuilder(doc);
//Every worksheet in Excel workbook is represented as section in Word document
foreach (Worksheet worksheet in workbook.Worksheets)
{
//Import PageSetup from Excel file to Word document
//Orientation can be Portrait or Landscape
builder.PageSetup.Orientation = ConvertPageOrientation(worksheet.PageSetup.Orientation);
//Paper size can be A4, A3, Letter, etc.
builder.PageSetup.PaperSize = ConvertPaperSize(worksheet.PageSetup.PaperSize);
//Import margins
builder.PageSetup.LeftMargin = ConvertUtil.InchToPoint(worksheet.PageSetup.LeftMarginInch); // 1cm = 28.35pt
builder.PageSetup.RightMargin = ConvertUtil.InchToPoint(worksheet.PageSetup.RightMarginInch);
builder.PageSetup.TopMargin = ConvertUtil.InchToPoint(worksheet.PageSetup.TopMarginInch);
builder.PageSetup.BottomMargin = ConvertUtil.InchToPoint(worksheet.PageSetup.BottomMarginInch);
//Get array of Word tables, every table in this array represents a part of Excel worksheet.
ArrayList partsArray = GetTablePartsArray(worksheet, doc);
//Insert all tables into the Word document
foreach (Table table in partsArray)
{
//Insert table
builder.CurrentSection.Body.AppendChild(table);
//Move coursore to document end
builder.MoveToDocumentEnd();
//Insert break if table is not last in the collection
if (!table.Equals(partsArray[partsArray.Count - 1]))
{
builder.InsertBreak(BreakType.SectionBreakNewPage);
}
}
//Insert break if current workseet is not last in the Excwl workbook
if (!worksheet.Equals(workbook.Worksheets[workbook.Worksheets.Count - 1]) && partsArray.Count != 0)
{
builder.InsertBreak(BreakType.SectionBreakNewPage);
}
}
return doc;
}
示例10: ConvertImageToPdf
/// <summary>
/// Converts an image to PDF using Aspose.Words for .NET.
/// </summary>
/// <param name="inputFileName">File name of input image file.</param>
/// <param name="outputFileName">Output PDF file name.</param>
public static void ConvertImageToPdf(string inputFileName, string outputFileName)
{
// Create Aspose.Words.Document and DocumentBuilder.
// The builder makes it simple to add content to the document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Read the image from file, ensure it is disposed.
using (Image image = Image.FromFile(inputFileName))
{
// Get the number of frames in the image.
int framesCount = image.GetFrameCount(FrameDimension.Page);
// Loop through all frames.
for (int frameIdx = 0; frameIdx < framesCount; frameIdx++)
{
// Insert a section break before each new page, in case of a multi-frame TIFF.
if (frameIdx != 0)
builder.InsertBreak(BreakType.SectionBreakNewPage);
// Select active frame.
image.SelectActiveFrame(FrameDimension.Page, frameIdx);
// We want the size of the page to be the same as the size of the image.
// Convert pixels to points to size the page to the actual image size.
PageSetup ps = builder.PageSetup;
ps.PageWidth = ConvertUtil.PixelToPoint(image.Width, image.HorizontalResolution);
ps.PageHeight = ConvertUtil.PixelToPoint(image.Height, image.VerticalResolution);
// Insert the image into the document and position it at the top left corner of the page.
builder.InsertImage(
image,
RelativeHorizontalPosition.Page,
0,
RelativeVerticalPosition.Page,
0,
ps.PageWidth,
ps.PageHeight,
WrapType.None);
}
}
// Save the document to PDF.
doc.Save(outputFileName);
}
示例11: 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
}
示例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: InsertSectionBreaks
/// <summary>
/// Inserts section breaks before the specified paragraphs.
/// </summary>
private void InsertSectionBreaks(ArrayList topicStartParas)
{
DocumentBuilder builder = new DocumentBuilder(mDoc);
foreach (Paragraph para in topicStartParas)
{
Section section = para.ParentSection;
// Insert section break if the paragraph is not at the beginning of a section already.
if (para != section.Body.FirstParagraph)
{
builder.MoveTo(para.FirstChild);
builder.InsertBreak(BreakType.SectionBreakNewPage);
// This is the paragraph that was inserted at the end of the now old section.
// We don't really need the extra paragraph, we just needed the section.
section.Body.LastParagraph.Remove();
}
}
}
示例14: RemovePageBreaks
//manage linebreaks problematic in Aspose.words - remove page break and insert a new sectionbreaknewpage
private static void RemovePageBreaks(Aspose.Words.Document doc)
{
DocumentBuilder builder = new DocumentBuilder(doc);
foreach (Paragraph par in doc.GetChildNodes(NodeType.Paragraph, true))
{
foreach (Run run in par.Runs)
{
//If run contains PageBreak then remove it and insert section break
if (run.Text.Contains("\f"))
{
builder.MoveTo(run);
builder.InsertBreak(BreakType.SectionBreakNewPage);
run.Remove();
break;
}
}
}
}
示例15: DocumentBuilderInsertBreak
public void DocumentBuilderInsertBreak()
{
//ExStart
//ExId:DocumentBuilderInsertBreak
//ExSummary:Shows how to insert page breaks into a document.
Aspose.Words.Document doc = new Aspose.Words.Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Writeln("This is page 1.");
builder.InsertBreak(BreakType.PageBreak);
builder.Writeln("This is page 2.");
builder.InsertBreak(BreakType.PageBreak);
builder.Writeln("This is page 3.");
//ExEnd
}