Notes for using Aspose. NET

Source: Internet
Author: User

Description

We have changed the process to eliminate the dependency of the native Interactive Operation library on Microsoft wordsoftware. We useAsposeThe Library manages all processes in the memory and more effectively manages documents for two purposes:

  • Avoid installing Microsoft Word on a server for automation.

  • The libraries in the Code directly includeBetter performance.

At the same time, Aspose has a complete Microsoft Ofiice library and addsElasticityAndFunctionalityVery useful. Your mileage will change based on how you process documents that integrate their libraries, but they are fully functional and are an integral part of the provided product.

Use Code

1) set a license

The Aspose component requires you to load the license to the library to unlock its real functions.

You can apply for a temporary license on their website by creating a reference to the components you are interested in, indicating that the components you are interested in will become available at the final stage of the Reference)

Dim License As New Aspose.Words.License()Try    License.SetLicense("Aspose.Words.lic")Catch ' Make sure to trap and record any licensing issues hereEnd Try

Add a license to your library as a static resource, otherwise it will reside in the same folder as the application.


2) process your documents

Now, when your design is prone to deviations, we use hidden bookmarks to control the inner and outer sections of dynamic nodes.) If you use other methods, you will need to explore the functions of the library in depth.

The two main classes will be used in most of the processing processes: Aspose. Word. WordDocument and Aspose. Word. WordDocumentBuilder.

Dim oWordFile As System.IO.MemoryStreamDim oWordDocument As Aspose.Words.DocumentDim oWordDocumentBuilder As Aspose.Words.DocumentBuilder' oDocument represents an external resource extracted from a databaseoWordFile = New System.IO.MemoryStream(oDocument.Content, True)oWordDocument = New Aspose.Words.Document(oWordFile)oWordDocumentBuilder = New Aspose.Words.DocumentBuilder(oWordDocument)' Clean up, passed this point the MemoryStream is no longer requiredoWordFile.Dispose()oWordFile = Nothing

Now with this configuration, you are ready to spread your code to use the document. Aspose. word.. NET Object layer management documents such as XML documents), whether it is the legacy RTF, DDC1997/2003, or the new format docx, DOCM, etc ), to correctly modify or use existing data, you must pass through the object node tree.

3) several examples and notes on bookmarks

' Retrieve dataDim sValue As String = oWordDocument.Range.Bookmarks(sBookmarkName).Text' Change datasValue = “Test”oWordDocument.Range.Bookmarks(sBookmarkName).Text = sValue

This includes manipulating existing bookmarks.

Creating bookmarks is simple. You need to add two subnodes to the document architecture:

Dim oBookmarkStart As New Aspose.Words.BookmarkStart(oWordDocument, sNewName)Dim oBookmarkEnd As New Aspose.Words.BookmarkEnd(oWordDocument, sNewName)' oNodeStart and oNodeEnd represent content nodes already identified to become the' boundaries of the new bookmarkoNodeStart.AppendChild(oBookmarkStart)oNodeEnd.AppendChild(oBookmarkEnd)

The method for identifying the bookmarkdonefle boundary varies according to the way you manage documents. If you are building a document, you simply add it to the document content; if you use an existing template, you need a more complex solution to manage bookmarks.

The only thing you need to be aware of is that when any component in the cloned node document is a node and can also be cloned as its own tree, note that the cloned bookmarks still keep their original names. YouRequiredRename it. Otherwise, an exception occurs.

You can capture the above two nodes to change the bookmarks accordingly.

4) Save your changes

Although these instances are basic and contain I/O bookmarks, you will need to save the document using the appropriate XSaveOptions class. Note that using other storage methods provided (detected by the file extension) may be incorrect.

PDF saving items are described here:

' The options are up to you, this setup is for lighter filesoPDFOptions = New Aspose.Words.Saving.PdfSaveOptions()oPDFOptions.EmbedFullFonts = FalseoPDFOptions.ExportCustomPropertiesAsMetadata = FalseoPDFOptions.FontEmbeddingMode = Aspose.Words.Saving.PdfFontEmbeddingMode.EmbedNone' For Left to Right text support (Arabic, Hebrew, etc…)oWordDocument.FieldOptions.IsBidiTextSupportedOnUpdate = False' oNewMemoryStream being the target for the pushoWordDocument.Save(oNewMemoryStream, oPDFOptions)

Notes

In terms of performance, there is no need to illustrate that the document from a hard drive is already a great improvement. You do not need to rely on Microsoft Office to add more files, but the processing itself is shown relative to native. NET Interactive Operation library has a gain of 6:1.

Another note is about the performance of components. Cleaning is cumbersome and should be isolated to non-critical paths.

The object extraction layer greatly simplifies the document itself to be manipulated by code, excluding the appearance of the same quirks in the final structure of the document. Its complexity is determined by the Library itself.

Related Article

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.