IDocument
This interface that defines a document object.
Members
API Name | Description |
---|---|
name |
Return the name of current document. |
author |
Return the author of current document. |
creationDate |
Return the creation date of current document. |
uid |
Return the docUid of current document. |
pages |
Return the array of pageUids of current document. |
loadSource() |
Load file(s) to current document. |
getPageData() |
Get the data of specified page. |
updatePage() |
Update a page specified by the pageUid with the new data. |
setPageCustomData() |
Set the custom data to the specified page. |
getPageCustomData() |
Get the custom data of the specified page. |
deletePages() |
Delete the specified pages from current document. |
deleteAllPages() |
Delete all pages in current document. |
movePages() |
Move specified page(s) to the target position in current document. |
switchPage() |
Swap the position of two pages in current document. |
rename() |
Rename current document. |
saveToPng() |
Save specified page or current page in current document to a PNG file. |
saveToJpeg() |
Save specified page or current page in current document to a JPEG file. |
saveToTiff() |
Save specified page(s) or all pages in current document to a TIFF file. |
saveToPdf() |
Save specified page(s) or all pages in current document to a PDF file. |
print() |
Use the browser’s built-in print feature to print the specified image(s). |
name
Return the name of current document.
Syntax
readonly name: string;
Remark
- It can be set while creating the document by using
createDocument
. If it is not set, return the name which is auto generated.
author
Return the author of current document.
Syntax
readonly author: string;
Remark
- It can be set while creating the document by using
createDocument
. If it is not set, return''
.
creationDate
Return the creation date of current document.
Syntax
readonly creationDate: string;
Remark
- It can be set while creating the document by using
createDocument
. If it is not set, return the actual creation date of the document.
uid
Return the docUid of current document.
Syntax
readonly uid: string;
pages
Return the array of pageUids of current document.
Syntax
readonly pages: string[];
Remark
- Returns an array of pageUids.
Code Snippet
const firstDoc = Dynamsoft.DDV.documentManager.createDocument({
name: "first_document",
author: "DDV",
creationDate: "D:20230101085959",
});
const docName = firstDoc.name;
const docAuthor = firstDoc.author;
const docCreationDate = firstDoc.creationDate;
const docUid = firstDoc.uid;
const docPages = firstDoc.pages;
loadSource()
Load file(s) to current document.
Syntax
loadSource(fileData: Blob | Blob[], index?: number): Promise<string[]>;
loadSource(sources: Source | Source[], index?: number): Promise<string[]>;
Parameters
fileData
: The blob of the file to be loaded.
sources
: The target files, it could be a file or a file array. Please refer to Source
. Source
can be extended to PdfSource
.
index
: The position in the document where the file(s) will be loaded to. If not set, the loaded file(s) will be added from the end of the document.
Return Value
A Promise object which will be resolved with the page uids of the loaded pages when the file(s) are successfully loaded.
Code Snippet
const firstDoc = Dynamsoft.DDV.documentManager.createDocument({
name: "first_document",
author: "DDV",
creationDate: "D:20230101085959",
});
const source = {
fileData: /*sampleBlob*/;
};
await firstDoc.loadSource([source]);
Promise Exception
Error Code | Error Message |
---|---|
-80001 | License string is invalid. |
-80002 | XXX(LicenseModuleName) module license has expired. |
-80003 | XXX(LicenseModuleName) module license is missing. |
-80004 | XXX(LicenseModuleName) module license version does not match. |
-80005 | Domain does not match the domain bound to the XXX(LicenseModuleName) module license. |
-80050 | DDV.Core.init() has not been set up yet. |
-80051 | DDV.Core.init() has not been completed. |
-80100 | XXX(API): XXX(ParameterName) is invalid. |
-80102 | XXX(API): XXX(ParameterName) is missing. |
-80200 | File type is not supported. |
-80202 | Failed to read the PDF file becouse it’s encrypted and the correct password is not provided. |
getPageData()
Get the data of specified page.
Syntax
getPageData(pageUid: string): Promise<PageData>;
Parameters
pageUid
: The uid of the page.
Return Value
A Promise PageData
object.
Code Snippet
const pageData = await firstDoc.getPageData(firstDoc.pages[0]);
Promise Exception
Error Code | Error Message |
---|---|
-80100 | XXX(API): XXX(ParameterName) is invalid. |
-80102 | XXX(API): XXX(ParameterName) is missing. |
-80105 | XXX(API): The specified page(s) do not exist. |
updatePage()
Update a page specified by the pageUid with the new data.
Syntax
updatePage(pageUid: string, data: Blob, updatePageOptions?: UpdatePageOptions): Promise<boolean>;
Parameters
pageUid
: The uid of the page to be updated.
data
: The new blob.
updatePageOptions
: The options of the new updated page. Please refer to UpdatePageOptions
.
Return Value
A Promise object which will be resolved with a boolean value.
true
: Successfully.
false
: Failed.
Code Snippet
const updateFirstPage = {
fileIndex: 1, // using the second page of new file.
};
const fileData = /*sample blob*/,
await firstDoc.updatePage(firstDoc.pages[0], fileData, updateFirstPage);
Promise Exception
Error Code | Error Message |
---|---|
-80100 | XXX(API): XXX(ParameterName) is invalid. |
-80101 | IDocument.updatePage: updatePageOptions.fileIndex is out of range. |
-80102 | XXX(API): XXX(ParameterName) is missing. |
-80105 | XXX(API): The specified page(s) do not exist. |
setPageCustomData()
Set the custom data to the specified page.
Syntax
setPageCustomData(pageUid: string, data: any): Promise<boolean>;
Parameters
pageUid
: The uid of the page.
data
: The custom data to set.
Return Value
A Promise object which will be resolved with a boolean value.
true
: Successfully.
false
: Failed.
Code Snippet
const customData ={
hasBarcode: true; // sample custom data
};
await firstDoc.setPageCustomData(firstDoc.pages[0], customData);
Promise Exception
Error Code | Error Message |
---|---|
-80100 | XXX(API): XXX(ParameterName) is invalid. |
-80102 | XXX(API): XXX(ParameterName) is missing. |
-80105 | XXX(API): The specified page(s) do not exist. |
getPageCustomData()
Get the custom data of the specified page.
Syntax
getPageCustomData(pageUid: string): Promise<any>;
Parameters
pageUid
: The uid of the page.
Return Value
A Promise object which will be resolved with the custom data.
Code Snippet
const customdata = await firstDoc.getPageCutomData(firstDoc.pages[0]);
Promise Exception
Error Code | Error Message |
---|---|
-80100 | XXX(API): XXX(ParameterName) is invalid. |
-80102 | XXX(API): XXX(ParameterName) is missing. |
-80105 | XXX(API): The specified page(s) do not exist. |
deletePages()
Delete the specified pages from current document.
Syntax
deletePages(indices: number[]): boolean;
Parameters
indices
: The array of page indices which will be removed.
Return Value
true
: Successfully.
false
: Failed.
Code Snippet
// Delete the first and second page.
firstDoc.deletePages([0,1]);
Warning
Error Code | Error Message | API return value |
---|---|---|
-80100 | XXX(API): XXX(ParameterName) is invalid. | false |
-80102 | XXX(API): XXX(ParameterName) is missing. | false |
deleteAllPages()
Delete all pages in current document.
Syntax
deleteAllPages(): boolean;
Parameters
None.
Return Value
true
: Successfully.
false
: Failed.
Code Snippet
// Delete all pages from the doc.
firstDoc.deleteAllPages();
movePages()
Move specified page(s) to the target position in current document.
Syntax
movePages(indices: number[], insertBeforeIndex?: number): void;
Parameters
indices
: The array of page(s) indices to be moved.
insertBeforeIndex
: Moved pages will be placed before this index. If not set, the specified page(s) will be moved after the last page.
Code Snippet
// Move the second, fourth, sixth pages to the begining of the doc
// The moved pages are in (original sixth, fourth, second) order.
firstDoc.movePages([5,3,1], 0);
Exception
Error Code | Error Message |
---|---|
-80100 | XXX(API): XXX(ParameterName) is invalid. |
-80102 | XXX(API): XXX(ParameterName) is missing. |
switchPage()
Swap the position of two pages in current document.
Syntax
switchPage(oneIndex: number, anotherIndex: number): void;
Parameters
oneIndex
: The index of one page.
anotherIndex
: The index of another page.
Return Value
true
: Successfully.
false
: Failed.
Code Snippet
// Switch the third and sixth pages.
firstDoc.switchPage(2, 5);
Exception
Error Code | Error Message |
---|---|
-80100 | XXX(API): XXX(ParameterName) is invalid. |
-80101 | XXX(API): XXX(ParameterName) is out of range. |
-80102 | XXX(API): XXX(ParameterName) is missing. |
rename()
Rename current document.
Syntax
rename(name: string): boolean;
Parameters
name
: The new name of current document.
Return Value
true
: Successfully.
false
: Failed.
Code Snippet
const firstDoc = Dynamsoft.DDV.documentManager.createDocument({
name: "first_document",
author: "DDV",
creationDate: "D:20230101085959",
});
firstDoc.rename("my_doc");
Warning
Error Code | Error Message | API return value |
---|---|---|
-80100 | XXX(API): XXX(ParameterName) is invalid. | false |
-80102 | XXX(API): XXX(ParameterName) is missing. | false |
saveToPng()
Save specified page or current page in current document to a PNG file.
Syntax
saveToPng(index: number): Promise<Blob>;
Parameters
index
: Specify index of the page to be saved.
Return Values
A Promise object which will be resolved with Blob
of the saved image.
Code Snippet
// Save the first page to a PNG file.
const result = await firstDoc.saveToPng(0);
Promise Exception
Error Code | Error Message |
---|---|
-80001 | License string is invalid. |
-80002 | XXX(LicenseModuleName) module license has expired. |
-80003 | XXX(LicenseModuleName) module license is missing. |
-80004 | XXX(LicenseModuleName) module license version does not match. |
-80005 | Domain does not match the domain bound to the XXX(LicenseModuleName) module license. |
-80100 | XXX(API): XXX(ParameterName) is invalid. |
-80101 | XXX(API): XXX(ParameterName) is out of range. |
-80102 | XXX(API): XXX(ParameterName) is missing. |
saveToJpeg()
Save specified page or current page in current document to a JPEG file.
Syntax
saveToJpeg(index: number, saveJpegSettings?: SaveJpegSettings): Promise<Blob>;
Parameters
index
: Specify index of the page to be saved.
saveJpegSettings
: Specify the save settings. Please refer to SaveJpegSettings
.
Return Values
A Promise object which will be resolved with Blob
of the saved image.
Code Snippet
// Save the first page to a JPEG file with JPEG compression quality 100.
const settings = {
quality: 100,
};
const result = await firstDoc.saveToJpeg(0, settings);
Promise Exception
Error Code | Error Message |
---|---|
-80001 | License string is invalid. |
-80002 | XXX(LicenseModuleName) module license has expired. |
-80003 | XXX(LicenseModuleName) module license is missing. |
-80004 | XXX(LicenseModuleName) module license version does not match. |
-80005 | Domain does not match the domain bound to the XXX(LicenseModuleName) module license. |
-80100 | XXX(API): XXX(ParameterName) is invalid. |
-80101 | XXX(API): XXX(ParameterName) is out of range. |
-80102 | XXX(API): XXX(ParameterName) is missing. |
saveToTiff()
Save specified page(s) or all pages in current document to a TIFF file.
Syntax
saveToTiff(indices: number[], saveTiffSettings?: SaveTiffSettings): Promise<Blob>;
saveToTiff(saveTiffSettings?: SaveTiffSettings): Promise<Blob>;
Parameters
indices
: The array of page indices which will be saved. If not set, will save all pages to a TIFF file by default.
saveTiffSettings
: Specify the save settings. Please refer to SaveTiffSettings
.
Return Values
A Promise object which will be resolved with Blob
of the saved TIFF file.
Code Snippet
// Set custom tag
const customTag1 = {
id: 700,
content: "Created By Dynamsoft",
contentIsBase64: false,
}
// Set SaveTiffSettings
const tiffSettings = {
customTag: [customTag1],
compression: "tiff/auto",
}
// Save the fifth, sixth, seventh pages to a multi-page TIFF file with the specified tiff settings.
const result1 = await firstDoc.saveToTiff([4,5,6], tiffSettings);
// Save the whole document to a multi-page TIFF file with the specified tiff settings.
const result2 = await firstDoc.saveToTiff(tiffSettings);
Promise Exception
Error Code | Error Message |
---|---|
-80001 | License string is invalid. |
-80002 | XXX(LicenseModuleName) module license has expired. |
-80003 | XXX(LicenseModuleName) module license is missing. |
-80004 | XXX(LicenseModuleName) module license version does not match. |
-80005 | Domain does not match the domain bound to the XXX(LicenseModuleName) module license. |
-80100 | XXX(API): XXX(ParameterName) is invalid. |
-80305 | There is no image in the current document. |
saveToPdf()
Save specified page(s) or all pages in current document to a PDF file.
Syntax
saveToPdf(indices: number[], savePdfSettings?: SavePdfSettings): Promise<Blob>;
saveToPdf(savePdfSettings?: SavePdfSettings): Promise<Blob>;
Parameters
indices
: The array of page indices which will be saved.
savePdfSettings
: Specify the save settings. Please refer to SavePdfSettings
. If not set, will save all pages to a PDF file by default.
Return Values
A Promise object which will be resolved with Blob
of the saved PDF file.
Code Snippet
const pdfSettings = {
author: "Dynamsoft",
compression: "pdf/jpeg",
pageType: "page/a4",
creator: "DDV",
creationDate: "D:20230101085959",
keyWords: "samplepdf",
modifiedDate: "D:20230101090101",
producer: "Dynamsoft Document Viewer",
subject: "SamplePdf",
title: "SamplePdf",
version: "1.5",
quality: 90,
}
// Save the fifth, sixth, seventh pages to a multi-page PDF file with the specified pdf settings.
const result1 = await firstDoc.saveToPdf([4,5,6], pdfSettings);
// Save the whole document to a multi-page PDF file with the specified pdf settings.
const result2 = await firstDoc.saveToPdf(pdfSettings);
Promise Exception
Error Code | Error Message |
---|---|
-80001 | License string is invalid. |
-80002 | XXX(LicenseModuleName) module license has expired. |
-80003 | XXX(LicenseModuleName) module license is missing. |
-80004 | XXX(LicenseModuleName) module license version does not match. |
-80005 | Domain does not match the domain bound to the XXX(LicenseModuleName) module license. |
-80100 | XXX(API): XXX(ParameterName) is invalid. |
-80305 | There is no image in the current document. |
print()
Use the browser’s built-in print feature to print the specified image(s).
Syntax
print(indices?: number[]): void;
Parameters
indices
: The array of page indices which will be printed. If not set, will export all pages to the browser’s built-in print window.
Return Values
true
: Successfully.
false
: Failed.
Code Snippet
// To print the whole doc pages
firstDoc.print();
// To print the second and third pages
firstDoc.print([1,2]);
Exception
Error Code | Error Message |
---|---|
-80100 | XXX(API): XXX(ParameterName) is invalid. |
-80305 | There is no image in the current document. |