Resource Base
Table of contents

DocumentManager Class

The Dynamsoft.DDV.documentManager instance will be created automatically as soon as DDV is initialized. Please refer to documentManager.

API Index

Methods

API Name Description
createDocument() Create an empty document.
deleteDocuments() Delete the specified document(s) by the document uid(s).
deleteAllDocuments() Delete all documents.
getDocument() Get the specified document object with the document uid.
getAllDocuments() Get all documents’ objects.
mergeDocuments() Merge specified documents to a new document.
copyPagesToDocument() Copy pages from a specified document to another document.
movePagesToDocument() Move pages from a specified document to another document.

Events

API Name Description
on() Bind a listener to the specified event.
off() Unbind event listener(s) from the specified event.

Integrated Events

Event Name Description
documentCreated Triggered when a new document is created.
documentDeleted Triggered when a document is deleted.

Methods

createDocument()

Create an empty document.

Syntax

createDocument(createDocumentOptions?: CreateDocumentOptions): IDocument;

Parameters

createDocumentOptions: The configuration used to create a document. Please refer to CreateDocumentOptions.

Return value

The object of the created document. Please refer to IDocument.

Code Snippet

const firstDoc = Dynamsoft.DDV.documentManager.createDocument({
    name: "first_document",
    author: "DDV",
    creationDate: "D:20230101085959",
    });

Exception

Error Code Error Message
-80100 XXX(API): XXX(ParameterName) is invalid.

deleteDocuments()

Delete the specified document(s) by the document uid(s).

Syntax

deleteDocuments(docUids: string[]): boolean;

Parameters

docUids: The array of document uids for the specified docunments.

Return Value

true: Successfully.

false: Failed.

Code Snippet

const firstDoc = Dynamsoft.DDV.documentManager.createDocument({
    name: "first_document",
    author: "DDV",
    creationDate: "D:20230101085959",
    });

const docUid = firstDoc.uid;

Dynamsoft.DDV.documentManager.deleteDocuments([docUid]);

Warning

Error Code Error Message API return value
-80100 XXX(API): XXX(ParameterName) is invalid. false
-80102 XXX(API): XXX(ParameterName) is missing. false
-80104 XXX(API): The specified document(s) do not exist. false

deleteAllDocuments()

Delete all documents.

Syntax

deleteAllDocuments(): boolean;

Return Value

true: Successfully.

false: Failed.

Code Snippet

Dynamsoft.DDV.documentManager.deleteAllDocuments();

getDocument()

Get the document object with the document uid.

Syntax

getDocument(docUid: string): IDocument;

Parameters

docUid: The docUid of the specified document.

Return Value

The object of the specified document. Please refer to IDocument.

Code Snippet

Dynamsoft.DDV.documentManager.getDocument("lnn0ll9o124");

Exception

Error Code Error Message
-80100 XXX(API): XXX(ParameterName) is invalid.
-80102 XXX(API): XXX(ParameterName) is missing.
-80104 XXX(API): The specified document(s) do not exist.

getAllDocuments()

Get all documents’ objects.

Syntax

getAllDocuments(): IDocument[];

Return Value

The array of all documents’ objects. Please refer to IDocument.

Code Snippet

Dynamsoft.DDV.documentManager.getAllDocuments();

Remark

  • If there is no document, returns [].

mergeDocuments()

Merge specified documents to a new document.

Syntax

mergeDocuments(docUids: string[], mergeDocumentOptions?: MergeDocumentOptions): IDocument;

Parameters

docUids: The array of specified documents’ uids.

mergeDocumentOptions: The merge document options. Please refer to MergeDocumentOptions.

Return Value

The object of the new document. Please refer to IDocument.

Code Snippet


const firstDoc = Dynamsoft.DDV.documentManager.createDocument({
    name: "first_document",
    author: "DDV",
    creationDate: "D:20230101085959",
    });

const source1 = {
    fileData: /*sampleBlob1*/;
};
await firstDoc.loadSource([source1]);

const secondDoc = Dynamsoft.DDV.documentManager.createDocument({
    name: "second_document",
    });

const source2 = {
    fileData: /*sampleBlob2*/;
};
await secondDoc.loadSource([source2]);

const docUid1 = firstDoc.uid; //"lnn0ll9o124"
const docUid2 = secondDoc.uid; //"lnn0iai110t"

const mergeOptions = {
    name: "mergedDoc", // Specify the name of the new document.
    author: "DDV", // Specify the author of the new document.
    creationDate: "D:20230101092020", // Specify the creation date. Note that the argument should be 'D:YYYYMMDDHHmmSS', like 'D:20230101085959'.
    deleteOriginal: true, // Whether to delete the original documents.
};

//Merge these two docs
Dynamsoft.DDV.documentManager.mergeDocuments([docUid1, docUid2], mergeOptions);

//OR
Dynamsoft.DDV.documentManager.mergeDocuments(["lnn0ll9o124", "lnn0iai110t"], mergeOptions);

Exception

Error Code Error Message
-80100 XXX(API): XXX(ParameterName) is invalid.
-80102 XXX(API): XXX(ParameterName) is missing.
-80104 XXX(API): The specified document(s) do not exist.
-80201 docUid does not allow duplicate.

copyPagesToDocument()

Copy pages from a specified document to another document.

Syntax

copyPagesToDocument(sourceDocUid: string, targetDocUid: string, transferOptions?: TransferOptions): void;

Parameters

sourceDocUid: The uid of source document.

targetDocUid: The uid of target document.

transferOptions: The transfer options. Please refer to TransferOptions.

Code Snippet

// Copy the first and second pages of doc "lnn0ll9o124" to doc "lnn0iai110t" and put them before the first page.
const copyOptions = {
    sourceIndices: [0,1],
    insertBeforeIndex: 0,
};

Dynamsoft.DDV.documentManager.copyPagesToDocument("lnn0ll9o124", "lnn0iai110t", copyOptions);

Exception

Error Code Error Message
-80100 XXX(API): XXX(ParameterName) is invalid.
-80102 XXX(API): XXX(ParameterName) is missing.
-80104 XXX(API): The specified document(s) do not exist.

movePagesToDocument()

Move pages from a specified document to another document.

Syntax

movePagesToDocument(sourceDocUid: string, targetDocUid: string, transferOptions?: TransferOptions): void;

Parameters

sourceDocUid: The uid of source document.

targetDocUid: The uid of target document.

transferOptions: The transfer options. Please refer to TransferOptions.

Code Snippet

// Move the first and second pages of doc "lnn0ll9o124" to doc "lnn0iai110t" and put them before the first page.
const moveOptions = {
    sourceIndices: [0,1],
    insertBeforeIndex: 0,
}
Dynamsoft.DDV.documentManager.movePagesToDocument("lnn0ll9o124", "lnn0iai110t", moveOptions);

Exception

Error Code Error Message
-80100 XXX(API): XXX(ParameterName) is invalid.
-80102 XXX(API): XXX(ParameterName) is missing.
-80104 XXX(API): The specified document(s) do not exist.

Events

on()

Bind a listener to the specified event.

Syntax

on(eventName: EventName, listener:(event:EventObject)=>void): void;

Parameters

eventName: Specify the event name. It can be an integrated event name.

listener: Specify the listener.

Code Snippet

// Bind a listener to the integrated event documentCreated.
const eventFunc = (e)=>{
    console.log(e);
    console.log(e.docUid);
    console.log(e.docName);
};

Dynamsoft.DDV.documentManager.on("documentCreated", eventFunc);

Warning

Error Code Error Message
-80100 XXX(API): XXX(ParameterName) is invalid.
-80102 XXX(API): XXX(ParameterName) is missing.

off()

Unbind event listener(s) from the specified event.

Syntax

off(eventName: EventName, listener?:(event:EventObject)=>void): void;

Parameters

eventName: Specify the event name. It can be an integrated event name.

listener: Specify the listener. If no listener is specified, unbind all event listeners from the specified event

Code Snippet

const eventFunc = (e)=>{
    console.log(e);
    console.log(e.docUid);
    console.log(e.docName);
};

Dynamsoft.DDV.documentManager.on("documentCreated", eventFunc);

// Unbind the specified event listener.
Dynamsoft.DDV.documentManager.off("documentCreated", eventFunc);

Warning

Error Code Error Message
-80100 XXX(API): XXX(ParameterName) is invalid.
-80102 XXX(API): XXX(ParameterName) is missing.

Integrated Events

documentCreated

Triggered when a new document is created.

Callback

DocumentEvent: An EventObject.

Attributes

docUid: The docUid of the created document.

docName: The name of the created document.

documentDeleted

Triggered when a document is deleted.

Callback

DocumentEvent: An EventObject.

Attributes

docUid: The docUid of the deleted document.

docName: The name of the deleted document.

Is this page helpful?

YesYes NoNo

In this article:

latest version

    • Latest version
    Change +
    © 2003–2024 Dynamsoft. All rights reserved.
    Privacy Statement / Site Map / Home / Purchase / Support