"Serial" Aspose.words Insert document element using tutorial (ii)

Source: Internet
Author: User

1. Insert a discontinuity:

If you want to start a new row, column, paragraph, or page, call Documentbuilder.insertbreak.

Example


Insert a page break in the document:

Documentbuilder builder = new Documentbuilder ();D ocument doc = new Document ();D ocumentbuilder builder = new Documentbuilde R (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.");

Visual Basic

Dim doc As New Document () Dim builder As 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.")

2. Inserting an image


Documentbuilder provides several [{{Documentbuilder]. Insertimage}}) The multi-load collection method , which enables the insertion of an inline or floating image, if the image is an EMF or WMF metafile, it will be inserted into the document's metafile format, and all other images will be stored in PNG format.

Documentbuilder. the Insertimage method can use images from different sources:

    • Pass a string parameter ({{documentbuilder.insertimage}}) from file or URL by passing

    • Flow from one stream parameter ({{documentbuilder.insertimage}})

    • From an image object through an image parameter (documentbuilder.insertimage)

    • Pass a byte array parameter ({{documentbuilder.insertimage}}) from a byte array




(1) inserting an inline image

Example

How to insert an inline image at the cursor position of a document.

C#

Document doc = new document ();D ocumentbuilder builder = new Documentbuilder (doc); builder. Insertimage (MyDir + "watermark.png");

Visual Basic

Dim doc As New Document () Dim builder As New Documentbuilder (DOC) builder. Insertimage (MyDir & "Watermark.png")


(2) inserting a floating (absolute position) image

Example

How to insert a floating image from a file or URL:

C#

Document doc = new document ();D ocumentbuilder builder = new Documentbuilder (doc); builder.     Insertimage (MyDir + "Watermark.png", Relativehorizontalposition.margin, Relativeverticalposition.margin, 100, Wraptype.square);


Visual Basic

Dim doc As New Document () Dim builder As New Documentbuilder (DOC) builder. Insertimage (MyDir & "Watermark.png", Relativehorizontalposition.margin, Relativeverticalposition.margin, Wraptype.square, Max.


3. Insert a Bookmark

Inserting a book into the document, you need to do a few things:

    • Call [Documentbuilder. Startbookmark] Set the desired book signature by it

    • Inserting bookmark text using the Documentbuilder method

    • Call [Documentbuilder. Endbookmark] It sets the same name as the bookmark you previously set.

bookmarks can overlap and span any range. Create a valid tag you need to call Documentbuilder.startbookmark and Documentbuilder bookmarks , their tag names must be the same

Example

How to use Document Builder to insert a label in your documents:

C#

Document doc = new document ();
Documentbuilder builder = new Documentbuilder (DOC);
Builder. Startbookmark ("Finebookmark");
Builder. Writeln ("This is just a fine bookmark.");
Builder. Endbookmark ("Finebookmark"); Visual Basicdim Doc as New Document () Dim Builder as New Documentbuilder (DOC) builder. Startbookmark ("Finebookmark") builder. Writeln ("This is just a fine bookmark.") Builder. Endbookmark ("Finebookmark")

Aspose.words Latest version download

"Serial" Aspose.words Insert document element using tutorial (ii)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.