> ## Documentation Index
> Fetch the complete documentation index at: https://docs.abbyy.com/llms.txt
> Use this file to discover all available pages before exploring further.

# AddNewDocument

> AddNewDocument method in the ABBYY FlexiCapture web services API adds a new document from an image file into a batch and controls its assembly and position.

## What it does

Adds a new document from an image file into a batch.

To create a document without an image, leave the file parameter empty (file.Name = "", file.Bytes = new bytes \[0]).

A new document is created with the **excludeFromAutomaticAssembling** flag set to **true**. This flag indicates that the document has already been assembled, and the assembly settings specified for the batch type will not be applied to this document.

<Warning>
  Newly added documents become accessible only after their images are pre-processed. Use the [ProcessBatch](/flexi-capture/api/methods/process-batch) method to initiate batch processing after adding new documents.
</Warning>

<Note>
  When a new document is added into the batch, the Id field of the corresponding object must not be empty.
</Note>

If you are adding PDF documents and want the program to use the text stored in their text layer, make sure that the Use PDF text layer instead of OCR option is selected for the project in which the documents will be processed (you can find this option on the **Processing** tab of the **Page Properties** dialog box).

## Definition

```
int AddNewDocument( int sessionId, Document document, File file, bool excludeFromAutomaticAssembling, int previousItemId );
```

## Parameters

<table width="100%"><tbody><tr><td><p><strong>Name</strong></p></td><td><p><strong>Type</strong></p></td><td><p><strong>Description</strong></p></td></tr><tr><td><p>sessionId</p></td><td><p>int</p></td><td><p>The ID of the connection to the Application Server</p></td></tr><tr><td><p>document</p></td><td><p><a href="/flexi-capture/api/structures/document">Document</a></p></td><td><p>A description of the document that is being created</p></td></tr><tr><td><p>file</p></td><td><p><a href="/flexi-capture/api/structures/file">File</a></p></td><td><p>The file that contains the document image</p></td></tr><tr><td><p>excludeFromAutomaticAssembling</p></td><td><p>bool</p></td><td><p>A flag that shows whether the document is excluded from document assembly or not:</p><ul><li><strong>True</strong> - the document has already been assembled and is not included in document assembly;</li><li><strong>False</strong> - the document will be assembled according to the settings specified for the batch type.</li></ul></td></tr><tr><td><p>previousItemId</p></td><td><p>int</p></td><td><p>The ID explicitly specifying the position of the new document in the set:</p><ul><li><strong>-1</strong> - the new document will be added at the end of the set</li><li><strong>0</strong> - the new document will be added at the start of the set</li><li><strong>Document ID</strong> - the new document will be added after the document with this ID<br /><strong>Note: </strong> A document with this ID must exist.</li></ul></td></tr></tbody></table>

<Note>
  You can also use a [POST request](/flexi-capture/api/files/files) to add document image. For this, create a document with an empty file by this method (file.Name = "FileName", file.Bytes = new bytes \[0]). Then execute a POST request with the following parameters:
</Note>

* Action = Save
* objectType = 0
* objectId = documentId, where documentId document ID returned by the AddNewDocument method
* version = 0
* streamName = "C:\Temp\image.pdf", where image.pdf is a name of the file specified when calling the AddNewDocument method

## Returned value

| **Type** | **Description**                |
| -------- | ------------------------------ |
| int      | The ID of the created document |
