Want to Set Timeout for Aspose.Slides Cloud Requests

Share on FacebookTweet about this on TwitterShare on LinkedIn

If we use third party services in our application, we have make to from a few to a lot of HTTP requests. And in consuming them, while making those HTTP requests, we should carefully set a timeout. Because if the server does not respond within this time for any reason, we cannot keep waiting for it to respond. If we do not have a timeout set, our entire system becomes stalled. Even if it is not fully stuck, the service is just too slow, that too could accumulate a lot of tasks on our queue.

A timeout saves us from a disaster and gives control over how to handle such issues. When a timeout is triggered, we can report an error, set a retry policy or move on as per our priority.

We have introduced a timeout feature in our new version of Aspose.Slides Cloud 19.6 along with many other important improvements and fixes. It will provide users more control on the API calls and plan their fall back policy accordingly. In subsequent paragraphs we will shed some light on the timeout feature of Aspose.Slides Cloud. For complete details of new improvement and fixes, please check the release notes of this version.

You can set timeout for any operation of Aspose.Slides using x-aspose-timeout header parameter, implemented in the current version. It can be used with any method and resource. It is an integer number specifying timeout (in seconds) for a request. It applies not to the overall Web request, but to the operation in Aspose.Slides on the server. An operation taking too long will be cancelled with an exception if it is taking too long. Please note Aspose.Slides Cloud timeout is counted only from the moment when the operation is started on the server.

Let us demonstrate how you can set a timeout of HTTP API request. We are using cURL command for the purpose, however, you can also use Aspose.Slides Cloud SDK of your choice. You need to set timeout property of configuration object. Please refer to the complete list of available SDKs to use Aspose.Slides Cloud API directly in your favorite platform.

Get JWT Authentication Token

Representation of a Presentation

Got a question or Bug? Please feel free to drop us a comment below or post a question in support forum. It helps us to continually improve and refine our API.

Still haven’t tried Aspose.Slides Cloud? The free trial is right here waiting for you to give it a try and explore the power of the Comparison REST API. All you need is to sign up with the aspose.cloud.

Posted in Aspose.Slides Cloud Product Family | Leave a comment

What’s New in Aspose.Imaging Cloud 19.6

Share on FacebookTweet about this on TwitterShare on LinkedIn

Our new release Aspose.Imaging Cloud 19.6 is already a fact. We have a number of new improvements and fixes in the new version, those make it more stable and reliable Cloud API of your choice, that empower you the manipulation of popular image formats with ease and authority. This release enriched our common ops functionality which is reflected in the common operations format support map for you to be able to save the processing results to even more formats. Please visit the release notes, for a complete list of improvement and fixes of this release.    

Updated GET requests

We always follow the best API practices of industry, as a step forward, we have deprecated GET requests those were able to create resources. We have removed the outPath parameter from GET request. So from now on you can only obtain the processed image in the response stream with GET requests, and saving it to storage is no longer allowed. If you still need to process the image from storage using GET request and save it to storage as well, then please upload the processed image explicitly by using the Storage API. Let’s show you, how you can achieve this using cURL commands in the new release.   

Get Authentication Token

Resize Image and Format Change

Upload Result File to Storage

SDK Updates

In this version we have improved the naming scheme of SDK methods. It is a breaking change. The main motive of this change is to make SDK methods naming simple and intuitive instead of previous bulky approach.

Now, the GET method name reflects simply the operation name. The POST requests which allow you to create resources start with Create and the ones that don’t, start with Extract. Please check some methods for understanding, for complete list, check release notes.

Old Method Names New Method Names
GetImageResize ResizeImage
PostImageResize CreateResizeImage
GetImagePorperties GetImageProperties
PostImageProperties ExtractImageProperties

Other changes are updation of Java SDK to eliminate the possible security vulnerability, improving SDK documentation and adding the common operations format support map to SDK READMEs.

Heads-Up about V4 API Version

We have plans to release new API v4.0 later this year. It is about re-structuring of API architecture to improve its availability and make it simpler. As per plan, it will not affect SDK methods naming much since the scheme introduced in the current release is designed to be mostly compatible with this change.

Try it Out and Share your Feedback

Still haven’t tried Aspose.Imaging Cloud? The free trial is right here waiting for you to give it a try and explore the power of the Aspose.Imaging Cloud REST API. All you need is to sign up with the aspose.cloud and visit our developer resources for a quick start:

Don’t forget to share your feedback, your feedback helps shape our roadmap because it is important to us to always deliver a product that satisfies your needs.

Posted in Aspose.Imaging Cloud Product Family | Tagged , , , , , | Leave a comment

Perform a Reverse Image Search

Share on FacebookTweet about this on TwitterShare on LinkedIn

The reverse image search is an analysis process when source image set containing at least one image is compared with several other images. As a result of this comparison, we get a list of most similar images according to the following conditions:

  • Degree of similarity
  • The minimal threshold of similarity
  • Algorithm of comparison

Aspose.Imaging Cloud provides REST APIs to help developers perform a reverse image search.

Use Cases

There may be a lot of use cases to apply reverse image search engine. The most common use cases are the following:

  • Search for image duplicates and remove the duplicates. This is the most common use of the library, and many customers need to sort out their photo libraries by finding similar photo images and leaving one or several shots while deleting the rest ones.
  • Search for content similar images. This feature is useful for digital writers who wish to find the most suitable content image to fill the article. Sometimes they may want to find a higher resolution image with the same content to put into article.
  • Search for inappropriate content. The engine may help find and identify images with inappropriate content and filter them out.
  • Search for digitally signed images.

Find Duplicate Images

With Aspose.Imaging REST API, we can find duplicate images in images storage. The steps to call this API are following:

1. Create ImagingApi Instance

Before creating ImagingApi instance, we need to create Aspose Cloud account and obtain our App Key and App SID. Getting Started article explains how to perform these steps.

2. Create Image Search

The method creates empty search context with certain settings. The search context state is stored in storage as a file (searchContextId).search. The important API parameters are:

  • String detector – features detector (default AKAZE)
  • String matchingAlgorithm – features matching algorithm (default RandomBinaryTree)

The API returns SearchContextStatus in response which indicates the current status of search context: Idle, ExtractingFeatures, MatchingFeatures or Searching.

3. Upload Image Set to Cloud Storage

Now, we upload the image set to cloud storage among whom we want to find duplicate images.

4. Add Images to Search Context

Now, we extract features of the above images and add them to search context.

5. Call Find Image Duplicates API

Finally, we call FindImageDuplicates API and pass following parameters:

  • searchContextId – search context id
  • similarityThreshold (required) – minimum similarity threshold

The API returns Duplicates(ImageDuplicates[]) array. The array contains property SearchResult[] DuplicateImages. The Search result contains two properties: string ImageId and float Similarity.

We may delete the search context as a last step.

Posted in Aspose.Total Cloud Product Family | Leave a comment

Export Spreadsheet to Markdown Format

Share on FacebookTweet about this on TwitterShare on LinkedIn

We are excited to announce new release Aspose.Cells Cloud 19.5. If you are working with the Markdown file format, then it is good news for you. From this release Aspose.Cells Cloud starts the support of Markdown file format.

Let’s show you how conveniently you can export your Spreadsheet documents to Markdown file format on any platform. You do not need any cumbersome coding for the purpose.

Let’s have a look at conversion code using cURL commands for REST API requests.   

Get Authentication Token

Upload source document to Storage

Export source document to Markdown File Format

In case you still haven’t met the API and haven’t worked with it, free trial is right here waiting for you to give it a try and explore the power of the Aspose.Cells Cloud REST API. All you need is to sign up with the aspose.cloud and visit our developer resources for a quick start:

Posted in Aspose.Cells Cloud Product Family | Leave a comment

Update Slide Animation with Aspose.Slides Cloud 19.5

Share on FacebookTweet about this on TwitterShare on LinkedIn

Guys! We have a great news for you. Aspose.Slides Cloud 19.5 is released. It is not a routine monthly release, but with some major changes in the RESTful API that takes it to the next level of reliability and availability. In new release, we have implemented Aspose.Slides Cloud as Microservice and introduced new API Version V3. Along with this internal architectural change, we have introduced many other important features in this release that make the API first choice of developers for creation and manipulation of PowerPoint Presentations on any platform. Let me share some overview of newly added features/enhancements in subsequent sections. However, please check the detailed release notes of this version to get an idea about all the new features/enhancements and fixes made in this release.

What’s New

Following are some notable changes from the new release:

  • Introduction of API version 3.0, API version v1.1 will remain available
  • Introduction of JWT(JSON Web Token) authentication , now OAuth2 and URL signing authentication methods are obsolete
  • Storage API is now available as part of Slides API
    • File API – Methods for upload, download, copy, move, delete files in the cloud storage
    • Folder API – Methods for create, copy, move, delete folders in the cloud storage
    • Storage API – Methods for getting storage information
  • Animation API has been added. API offers a wide range of options for applying various types of animation effects on the shapes in the presentation
  • format query string parameter and saveAs resource are replaced by format path parameter. This applies to presentation, slide, notes slide, shape and image.Format in convert resource is also specified in path instead of query
  • All response objects have the following changes:
    • Code and Status properties are removed. Inspect HTTP response to retrieve them
    • The data properties are moved level up. Their properties are now root properties of response DTO. For example, Document in document response, Slides in slides response, Slide in slide response, ShapeList in shapes response etc.
  • Read more

Working with Animation      

Animations make presentations, eye catching and attractive for the viewers. We already support Animations in Aspose.Slides for .NET. Now we have introduced Animation feature in Aspose.Slides Cloud as well. You can apply a vast range of effects to the shapes. As every element on the slide including text, pictures, OLE Object, table, etc is considered as a shape, so it means we can apply animation effects on every element of a slide.

Animation method represents animation sequences of a slide. You can get animation info of any slide, update mainsequence and interactivesequence elements of a Slide with Aspose.Slides Cloud. Please check documentation for more details.

Here, we will show how easily you can apply animation to shapes in a slide using cURL for the REST API requests along some other new features of this release. There are other SDKs available to use Aspose.Slides Cloud API directly in your favorite platform.

Following steps are involved in this example:

  • Get JWT authentication code
  • Upload source file to storage
  • Update Slide Animation
  • Download updated source file

Get JWT authentication code

Upload source file to storage

We are uploading source file to default storage of aspose.cloud using new File API. However, you can also use 3rd party storage as well.

Update Slide Animation

We will update the slide animation of the source file from the storage as follows. We will create the main animation sequence with two effects and an interactive sequence. All existing animation will be removed.

Please note, while updating the slide animation, If mainSequence element is specified, all existing main sequence effects will be removed. Otherwise, they will remain unchanged.

And if interactiveSequences element is specified, all existing interactive sequences will be removed. Otherwise, they will remain unchanged.

Download File

File API is used to download files form storage. We will download updated slide with animation from storage to local drive.

Resources

To learn more about Aspose.Slides Cloud REST API, visit our developer resources:

Posted in Aspose.Slides Cloud Product Family | Leave a comment

MailMerge Feature Improvement in Aspose.Words Cloud 19.5

Share on FacebookTweet about this on TwitterShare on LinkedIn

Aspose.Words Cloud is a market leading REST API, for manipulation of Word files and report generation without dependency of Microsoft Word. Aspose.Words extended the standard Mail Merge feature of Microsoft Word and Mustache template to advance level, turning Aspose.Words API into a full-fledged reporting solution that allows you to generate even more complex documents such as reports, catalogs, inventories, and invoices.

We are pleased to announce Aspose.Words Cloud 19.5. Are you using Mail Merge and Mustache templates for reporting? In that case, you have to call two different APIs for Mail Merge and Mustache templates, “ExecuteMailMerge” and “ExecuteTemplate” methods respectively. But in Aspose.Words Cloud 19.5 release, we have simplified the reporting feature by replacing these methods with a single “MailMerge” method which can be used with both template types. Please check Mail Merge Documentation for more details to use the same method for both types of templates.

MailMerge Template

Mustache Template

Another important change in new release is change of insertPageNumbers method to PageNumbers.

Resources

And if you have not already had a chance to try Aspose.Words Cloud REST API, simply start a free trial today. All you need is to sign up with the aspose.cloud. Once you have signed up, you are ready to try the powerful file processing features offered by aspose.cloud. Following are some useful resources of Aspose.Words Cloud you may need to accomplish your tasks.

Documentation

Web API Explorer

Examples and SDKs

Support Forum

Share Your Feedback

Feel free to drop us a comment sharing your thoughts about the new version of Aspose.Words Cloud REST API. Or let us know if you have any suggestions or if you need any particular features which you expect our REST API to have.

Posted in Aspose.Words Cloud Product Family | Tagged , , , , , | Leave a comment

Improved Aspose.Words Cloud V4 is Here!

Share on FacebookTweet about this on TwitterShare on LinkedIn

We’re excited to release new version of Aspose.Words Cloud REST API. Aspose.Words Cloud 19.4 includes lots of improvements related to features already supported by the API along with some breaking changes. Read on to see what’s new.

The major change in this release is introduction of V4 API version, it has more improved and optimized architecture. According to HTTP/1.1 specifications, we have changed PUT methods to POST and vice versa in this release. Now, all idempotent methods are PUT and non-idempotent methods are POST. In this release, we have included storage APIs in Aspose.Words Cloud REST API. Now you can perform different storage related operations directly, without using a separate Cloud API for the purpose. Learn more.

Breaking Changes

  • Introduced API version V4
  • Changed PUT to POST (and vice versa): from now on, all idempotent methods are PUT and non-idempotent ones are POST
  • “destFileName” parameter: now it contains absolute (instead of relative) path to save result file
  • Fixed serialization of “SourceFormat” property in “Document” response
  • “nodepath” parameter is always “path” type now
  • Removed “envelop” from all responses

New Features and Improvements

  • Storage APIs from now on are included in Aspose.Words Cloud REST API for a better user experience and unification
    • File API – Methods for upload, download, copy, move, delete files: input documents and rendering results, in the cloud storage
    • Folder API – Methods for create, copy, move, delete folders in the cloud storage
  • Improved recognition for multi-line headers and footers in PDF to Word Conversion API
  • Fixed an error in PDF to Word Conversion API while several documents are processed in parallel

How it Works

Here we demonstrate how easily you can convert a PDF document to DOCX using newest release. We will exhibit changes between V4 and V1 in this example for clear understanding by following these steps:

  • Get Access token for authentication
  • Upload Source PDF document to Storage
  • Convert PDF to DOCX

We are using cURL for consuming REST APIs in the example. You can use available SDKs to use the API directly in your favorite platform with ease.

Aspose.Words Cloud V1.1

Aspose.Words Cloud V4

Please note now V4 version only supports JWT(Json Web Token) for authentication, you cannot use URL signing and OAuth2 authentication methods with new version. Secondly, in V4 example, File API method of Aspose.Words Cloud is used to upload source file instead of Aspose.Storage Cloud API. And lastly but not least request type is changed to PUT in V4 instead of POST.

Share Your Feedback

Feel free to drop us a comment sharing your thoughts about the new version of Aspose.Words Cloud REST API. Or let us know if you have any suggestions or if you need any particular features which you expect our REST API to have.

And if you have not already had a chance to try our REST API, simply start a free trial today. All you need is to sign up with the aspose.cloud. Once you have signed up, you are ready to try the powerful file processing features offered by aspose.cloud.

Posted in Aspose.Words Cloud Product Family | Tagged , , , | Leave a comment

Introducing Aspose.Imaging Cloud V3

Share on FacebookTweet about this on TwitterShare on LinkedIn

Hello guys, at aspose, we always motivated to provide best solutions to our customers. We keep improving our APIs by fixing the reported issues and adding new features. We are pleased to share all new version of Aspose.Imaging Cloud 19.4. We have taken time since version 19.1 to migrate to the new architecture and enrich Aspose.Imaging Cloud 19.4 with improved performance and enhanced formats support. In this version, the major breaking change is the introduction of API V3 version. The V3 version API is a more simplified API, it has more optimized and refined internal architecture. This version made easy to work with cloud storage. Now you do not need to use a separate API for the purpose. The API includes methods for performing different storage related operations. Learn more.

What’s New in Aspose.Imaging Cloud V3 Version

  • We have added support of CDR, CMX, DJVU and PDF formats, along with enhanced cross-format conversion for common operations. Please, look at the common operations format support map to see what you can achieve!
  • Image rendering quality for export, resize and rotate/flip operations became better
  • Resize operation performance for CDR, CMX, SVG, EMF and WMF vector formats has been improved
  • AI features subsystem has been reworked to improve both performance and stability
  • Advanced EMF and WMF processing APIs now allow to save the result in different formats
  • Several problematic APIs have been fixed
  • Storage APIs from now on are included in Imaging for a better user experience and unification
    • File API – Methods for upload, download, copy, move, delete files: input documents and rendering results, in the cloud storage
    • Folder API – Methods for create, copy, move, delete folders in the cloud storage
    • Storage API – Methods for getting storage information and file information

Breaking Changes

  • API V3 introduction
  • PNG, DNG, ODG and DICOM APIs has been removed since they were supporting only a simple conversion without any advanced processing parameters. Please, use Save As APIs for export operations regarding these formats from now on. It’s possible that some of the removed APIs will be added later in the future if applicable features are implemented
  • Legacy SaaSposeResponse response format has been removed

How it Works

If you are looking for an API to manipulate industry standard images in your application seamlessly. Then your search is over, Aspose.Imaging Cloud is the best option for the purpose. It provides REST APIs & SDKs for advanced processing and manipulation of various image formats, on major platforms via numerous languages.

Here we demonstrate how easily you can crop and convert an image instantly. We are using Aspose.Imaging Cloud SDK for .NET. There are other SDKs available to use the API directly in your favorite platform with ease

The GetImageCrop API accepts the position as well as the dimension values of the cropping rectangle, whereas the format of the cropped image relies on the value of the format parameter.

Following steps are involved in this example:

  • Upload source file to storage
  • Crop and convert the Image
  • Save response Stream to the local system

Share Your Feedback

Your feedback is important! Please feel free to drop us a comment sharing your thoughts about the new version of Aspose.Imaging Cloud REST API. It helps us to continually improve and refine our API.

Posted in Aspose.Imaging Cloud Product Family | Leave a comment

Perform Mail Merge in a Word Document

Share on FacebookTweet about this on TwitterShare on LinkedIn

Mail Merge is a feature of Microsoft Word for quickly and easily creating documents like letters, labels and envelopes. Aspose.Words Cloud takes the standard mail merge and advances it many steps ahead, turning it into a full-fledged reporting solution that allows you to generate even more complex documents such as reports, catalogues, inventories, and invoices. The advantages of the Aspose.Words Cloud reporting solution are:

  • Design reports in Microsoft Word using standard mail merge fields
  • Define regions in the document that grow such as detail rows of an order
  • Insert images during mail merge
  • Insert HTML during mail merge

Basic Steps

Steps to perform a mail merge are quite easy. First, you use Microsoft Word to create and design a Word document normally called a template. Note that the document does not have to be a Microsoft Word Template (.dot), it can be a normal .doc document. You insert some special fields called merge fields into the template in places where you want data from your data source to be later inserted. Then with Aspose.Words REST API you execute a mail merge operation. The mail merge operation will take data from your data source and merge it into the document.

You can also designate repeatable merge regions in the document or insert special merge fields that allow you to insert other content such as images. Depending on how you set up mail merge fields and repeatable regions inside the document, the document will grow to accommodate multiple records in your data source. If you do not use mail merge regions, then the mail merge will be similar to Microsoft Word mail merge and the whole document content will be repeated for each record in the data source. Using repeatable mail merge regions, you can designate portions inside a document that will be repeated for each record in the data source. For example, if you mark a table row as a repeatable region then this table row will be repeated, causing the table to dynamically grow to accommodate all of your data.

Prepare a Document

Before you execute a mail merge, you need to prepare the document template. You should insert merge fields that will be replaced with values from your data source.

Inserting Merge Fields into a Document

To Insert Merge Fields into a Document:

  1. Open your document in Microsoft Word.
  2. In the document, click where you want to place a merge field.
  3. Open the Insert menu and select Field to open the Field dialog.
  4. From the Field names list, select MergeField.
  5. In the Field name text box, enter a name for the merge field and press OK.

Since a merge field is a regular Microsoft Word field, you can switch between displaying field codes and results in your document in Microsoft Word using the keyboard shortcut Alt+F9. Field codes appear between curly braces.

Simple Mail Merge

In order to prepare your template to perform a simple mail merge (without regions, similar to the classic mail merge available in Microsoft Word) you should just insert one or more merge fields in the places you want to be populated with data from the data source.

Let us take a look at the Dinner Invitation demo. It creates a letter for a list of clients defined in the data source. The template contains a number of merge fields that are populated from two data sources; in other words, two mail merges are performed one after the other. First, data from the first data source is merged into the template. This data source contains only one row because this is information about the inviter, so the whole document content is not repeated and only the appropriate fields are filled with data. Then the second mail merge operation is executed. The data source it uses contains information about the clients. The whole template is repeated for each data row and every repeated copy is populated with the corresponding client’s data.

As a result, we have a document that consists of five filled-in, complete, and personalized invitation letters (a fragment of the very first one is shown below):

As you can see, it is possible, and sometimes useful to perform more than one merge operation with the same template to add data in stages. You can insert NEXT fields in the Word document to cause the mail merge engine to select the next record from the data source and continue merging. When the engine encounters a NEXT field, it just selects the next record in the data source and continues merging without copying any content. This can be used when creating documents such as mailing labels.

The code to perform Simple Mail Merge is given below:

Mail Merge with Regions

If you want to dynamically grow portions inside the document, use mail merge with regions. To specify a mail merge region in the document you need to insert two mail merge fields to mark the beginning and end of the mail merge region. All document content that is included inside a mail merge region automatically will be repeated for every record in the data source.

To mark the beginning of a mail merge region, insert a MERGEFIELD with the name TableStart:MyTable, where MyTable corresponds to the tag or key in XML or JSON respectively. To mark the end of the mail merge region insert another MERGEFIELD with the name TableEnd:MyTable. Between these marking fields, place merge fields that correspond to the fields of your data source. These merge fields will be populated with data from the first row of the data source, then the whole region will be repeated, and the new fields will be populated with data from the second row, and so on.

Follow these simple rules when marking a region:

  • TableStart and TableEnd fields must be inside the same section in the document
  • If used inside a table, TableStart and TableEnd must be inside the same row in the table
  • Mail merge regions can be nested inside each other
  • Mail merge regions should be well formed (there is always a pair of matching TableStart and TableEnd with the same table name)

As an example, have a look at the Item Catalog demo. Here is a fragment of a region prepared for mail merge:

Note that both the marking fields TableStart:Item and TableEnd:Item are placed inside the same row of the Word table. After executing the mail merge, here is the result:

The code to perform Mail Merge with Regions is given below:

Mail Merge using ‘Mustache’ Template Syntax

This syntax allows you to create templates for use with mail merge that use plain text markers instead of merge fields. These markers look like this: {{ FieldName }}

Object.Attribute Syntax

You can easily merge attributes of fields using the following syntax:

  {{ Address.Street }}  

This will merge data from XML data which looks like this:

<Order> // <-- Current context is here.
<Number>23</Number>
<Address>
<Street>Nelson Street</Street>
<Suburb>Howick</Suburb>
<City>Auckland</City>
</Address>
<PhoneNumber>543 1234</PhoneNumber>
</Order>

Foreach Blocks

You can merge data from multiple records using the foreach tag. This is similar to mail merge regions with conventional merge fields. You can nest such blocks.

{{ #foreach Order }}
{{ Number }}
  {{ Address.Street }}
    {{ #foreach Item }}
      {{ Description }} {{ Cost}} {{ Total }}
     {{/foreach Item }}
{{ /foreach Order }}

You can also mix these fields and place them inside other Microsoft Word fields such as IF or Formula fields.

Conditional Block

You can use mail merge with IF statement using Aspose.Words Cloud. The IF block executes only if the Boolean expression associated with it is true. The syntax of IF is shown below.

{ IF "{{ GENDER }}" = “MALE” “true text” “false text” }

The code to perform Mail Merge using ‘Mustache’ Template is given below:

Insert HTML During Mail Merge

Both executeMailMerge and executeTemplate APIs provide support for inserting HTML on a merge field. You just need to make sure you escape HTML characters in data source string and use “format”=”html” attribute as shown below:

{   
"dataSourceList": {
"contractDS": {
"contractDescription": {
"format":"html",
"htmlText": "<b>Test me 1<br><br><i>Test me 2<br><br><u>Test me 2</u></i></b><br>"
}
}
}
}

Following code shows how to insert HTML during mail merge:

Insert Images During Mail Merge

You can also insert images on a merge field. Scale factor for images can be set using ‘%’, ‘px’ or ” (proportional scaling). The code to insert images during Mail Merge is given below:

Cloud SDKs

Although the above code is in .NET, Aspose.Words Cloud SDKs are available in five different languages: .NET, Java, Ruby, Python and Node.js. Therefore, you can conveniently call Mail Merge APIs in any of these languages.

Posted in Aspose.Words Cloud Product Family | Leave a comment

Insert Headers and Page Numbers in a Word Document

Share on FacebookTweet about this on TwitterShare on LinkedIn

The header is a section of the document that appears in the top margin and generally contains information such as the page number, date, and document name. With Aspose.Words REST APIs you can insert headers and page numbers in a Word document. By default, the headers are the same on each page but we can create different headers for odd and even pages.

This post aims to achieve the following layout of the document in which the header on the first page is different than the rest of the pages:

Before calling any Aspose REST API, we need to create Aspose Cloud account and obtain our App Key and App SID. Getting Started article explains how to perform these steps.

Moreover, we need to upload the sample document to the Cloud Storage as all the operations on the document will be performed in the Cloud:

Insert Header in a Word Document

PUT /words/{name}/{sectionPath}/headersfooters API adds headers in a document and its headerFooterType parameter can take one of the following six values:

ValueDescription
HeaderFirstHeader for the first page of the section.
HeaderPrimaryPrimary header, also used for odd numbered pages.
HeaderEvenHeader for even numbered pages.
FooterFirstFooter for the first page of the section.
FooterPrimaryPrimary footer, also used for odd numbered pages.
FooterEvenFooter for even numbered pages.

Please use HeaderFirst value to insert header in the first page:

and HeaderPrimary value to insert header in the rest of the pages:

Since the first header is different than the others, set DifferentFirstPageHeaderFooter parameter value to true as shown below:

So far empty paragraphs have been added to the headers of the document. In oder to add text to these headers we will use PUT /words/{name}/{paragraphPath}/runs API. The code shown below is adding “Aspose” text in the first header and “Cloud File Format APIs” text in all other headers:

Apply Formatting to a Header’s Text

Formatting can be applied to a header’s text using POST /words/{name}/{paragraphPath}/runs/{index}/font API. The API accepts fontDto object in its body, whose Resource Properties’ details are given in Update Font Properties of the Text article. The following code is setting font family of the header text to Verdana, text size to 14 and text colour to black.

After making the above API calls, the input document looks as follows:

Insert Page Numbers in a Word Document

POST /words/{name}/insertPageNumber API is used to insert page numbers in a Word document. The API accepts following JSON object in its body:

{
  "Format": "string",
  "Alignment": "string",
  "IsTop": true,
  "SetPageNumberOnFirstPage": true
}

Since we are adding page numbers in the header, we will set IsTop parameter’s value to true. However, to add page numbers in the footer, set the value to false.

Finally, we have added headers and page numbers to the document.

The complete code of this post is available on GitHub.

Posted in Aspose.Words Cloud Product Family | Leave a comment