Skip to content

Commit

Permalink
Implementation of Aspose.Pdf Missing Features
Browse files Browse the repository at this point in the history
Convert PDF from Remote Server to other Formats
Sign PDF Documents
Update a Form Field in a PDF Document
Get all Text Items from a PDF Document
Get Text Format of a PDF Fragment
Replace Multiple Texts in a PDF
Replace Multiple Texts in a PDF Page
Replace Image in a PDF file using Local Image Stream
Get all Annotations from a PDF Page
Get all Bookmarks from a PDF
Get all Links from a PDF Page
Get all Attachments from a PDF
Get a Specific Attachment from a PDF
Get Attachment Count from a PDF
Working with Watermarks or Stamps
  • Loading branch information
assadvirgo committed Jun 2, 2015
1 parent 629a7dd commit 48e13cf
Show file tree
Hide file tree
Showing 2 changed files with 286 additions and 7 deletions.
291 changes: 285 additions & 6 deletions lib/aspose-pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,29 @@ AsposePdf.prototype.getAttachmentsCount = function(fileName,pageNumber,callback)
});
};

AsposePdf.prototype.getAttachments = function(fileName,pageNumber,callback){

fileName = typeof fileName !== 'undefined' ? fileName : '';
pageNumber = typeof pageNumber !== 'undefined' ? pageNumber : 1;

if(fileName === ''){
throw new Error('Filename not defined.');
}

var strURI = this.baseURI + 'pdf/' + fileName + '/pages/' + pageNumber + '/attachments';
var signedURI = Utils.Sign(strURI,this.appSID,this.appKey);

Utils.ProcessCommand('GET',signedURI,'',function(data){
if(typeof callback === 'function'){
if(data.Status === 'OK'){
callback.call(null,data.Attachments);
} else {
throw new Error(data.Message);
}
}
});
};

AsposePdf.prototype.getAttachment = function(fileName,pageNumber,attachmentIndex,callback){

fileName = typeof fileName !== 'undefined' ? fileName : '';
Expand Down Expand Up @@ -107,6 +130,29 @@ AsposePdf.prototype.getBookmarksCount = function(fileName,pageNumber,callback){
});
};

AsposePdf.prototype.getBookmarks = function(fileName,pageNumber,callback){

fileName = typeof fileName !== 'undefined' ? fileName : '';
pageNumber = typeof pageNumber !== 'undefined' ? pageNumber : 1;

if(fileName === ''){
throw new Error('Filename not defined.');
}

var strURI = this.baseURI + 'pdf/' + fileName + '/pages/' + pageNumber + '/bookmarks';
var signedURI = Utils.Sign(strURI,this.appSID,this.appKey);

Utils.ProcessCommand('GET',signedURI,'',function(data){
if(typeof callback === 'function'){
if(data.Status === 'OK'){
callback.call(null,data.Bookmarks);
} else {
throw new Error(data.Message);
}
}
});
};

AsposePdf.prototype.getChildBookmarksCount = function(fileName,parentBookmark,callback){

fileName = typeof fileName !== 'undefined' ? fileName : '';
Expand Down Expand Up @@ -203,6 +249,29 @@ AsposePdf.prototype.getAnnotationsCount = function(fileName,pageNumber,callback)
});
};

AsposePdf.prototype.getAnnotations = function(fileName,pageNumber,callback){

fileName = typeof fileName !== 'undefined' ? fileName : '';
pageNumber = typeof pageNumber !== 'undefined' ? pageNumber : 1;

if(fileName === ''){
throw new Error('Filename not defined.');
}

var strURI = this.baseURI + 'pdf/' + fileName + '/pages/' + pageNumber + '/annotations';
var signedURI = Utils.Sign(strURI,this.appSID,this.appKey);

Utils.ProcessCommand('GET',signedURI,'',function(data){
if(typeof callback === 'function'){
if(data.Status === 'OK'){
callback.call(null,data.Annotations);
} else {
throw new Error(data.Message);
}
}
});
};

AsposePdf.prototype.getAnnotation = function(fileName,pageNumber,annotationIndex,callback){

fileName = typeof fileName !== 'undefined' ? fileName : '';
Expand Down Expand Up @@ -275,6 +344,29 @@ AsposePdf.prototype.getLinksCount = function(fileName,pageNumber,callback){
});
};

AsposePdf.prototype.getLinks = function(fileName,pageNumber,callback){

fileName = typeof fileName !== 'undefined' ? fileName : '';
pageNumber = typeof pageNumber !== 'undefined' ? pageNumber : 1;

if(fileName === ''){
throw new Error('Filename not defined.');
}

var strURI = this.baseURI + 'pdf/' + fileName + '/pages/' + pageNumber + '/links';
var signedURI = Utils.Sign(strURI,this.appSID,this.appKey);

Utils.ProcessCommand('GET',signedURI,'',function(data){
if(typeof callback === 'function'){
if(data.Status === 'OK'){
callback.call(null,data.Links);
} else {
throw new Error(data.Message);
}
}
});
};

/* Text Editing Methods */

AsposePdf.prototype.replaceText = function(fileName,oldText,newText,regularExpression,pageNumber,callback){
Expand Down Expand Up @@ -328,6 +420,49 @@ AsposePdf.prototype.replaceText = function(fileName,oldText,newText,regularExpre
});
};

AsposePdf.prototype.replaceMultipleText = function(fileName,postData,pageNumber,callback){

fileName = typeof fileName !== 'undefined' ? fileName : '';
postData = typeof postData !== 'undefined' ? postData : '';
pageNumber = typeof pageNumber !== 'undefined' ? pageNumber : 0;

if(fileName === ''){
throw new Error('Filename not defined.');
}

if(postData === 0){
throw new Error('postData not defined.');
}

var strURI = this.baseURI + 'pdf/' + fileName;

if(pageNumber > 0){
strURI = strURI + '/pages/' + pageNumber + '/replaceTextList';
} else {
strURI = strURI + '/replaceTextList';
}

var signedURI = Utils.Sign(strURI,this.appSID,this.appKey);

var appSID = this.appSID;
var appKey = this.appKey;
var baseURI = this.baseURI;

Utils.ProcessCommand('POST',signedURI,postData,function(data){
var asposeStorage = new AsposeStorage({'appSID':appSID,'appKey':appKey,'baseURI':baseURI});
if(data.Status === 'OK'){
asposeStorage.getFile(fileName, '', function(data){

if(typeof callback === 'function'){
callback.call(null,data);
}
});
} else {
throw new Error(data.Message);
}
});
};

AsposePdf.prototype.getTextFormat = function(fileName,pageNumber,fragmentNumber,segmentNumber,callback){

fileName = typeof fileName !== 'undefined' ? fileName : '';
Expand All @@ -346,12 +481,17 @@ AsposePdf.prototype.getTextFormat = function(fileName,pageNumber,fragmentNumber,
if(fragmentNumber === 0){
throw new Error('fragment number not defined.');
}


if(segmentNumber === 0){
throw new Error('segment number not defined.');
}

var strURI = this.baseURI + 'pdf/' + fileName + '/pages/' + pageNumber + '/fragments/' + fragmentNumber + '/segments/' + segmentNumber + '/textformat';
var strURI = this.baseURI + 'pdf/' + fileName + '/pages/' + pageNumber + '/fragments/' + fragmentNumber;
if(fragmentNumber > 0)
{
strURI = strURI + '/segments/' + segmentNumber + '/textformat';
}
else
{
strURI = strURI + '/textformat';
}
var signedURI = Utils.Sign(strURI,this.appSID,this.appKey);

Utils.ProcessCommand('GET',signedURI,'',function(data){
Expand Down Expand Up @@ -612,6 +752,29 @@ AsposePdf.prototype.convert = function(fileName,imageFormat,callback){
});
};

AsposePdf.prototype.convertByUrl = function(url,saveFormat,callback){
url = typeof url !== 'undefined' ? url : '';
saveFormat = typeof saveFormat !== 'undefined' ? saveFormat : '';

if(url === ''){
throw new Error('url not defined.');
}

if(saveFormat === ''){
throw new Error('saveFormat missing.');
}


var strURI = this.baseURI + 'pdf/convert?url=' + url + '&format='+saveFormat;
var signedURI = Utils.Sign(strURI,this.appSID,this.appKey);

Utils.ProcessCommandContent('PUT',signedURI,'',function(data){
if(typeof callback === 'function'){
callback.call(null,data);
}
});
};

AsposePdf.prototype.convertToImage = function(fileName,pageNumber,imageFormat,callback){
fileName = typeof fileName !== 'undefined' ? fileName : '';
pageNumber = typeof pageNumber !== 'undefined' ? pageNumber : '';
Expand Down Expand Up @@ -1109,6 +1272,43 @@ AsposePdf.prototype.getFormFields = function(fileName,callback){
});
};

AsposePdf.prototype.updateFormField = function(fileName,fieldName,fieldType,fieldValue,callback){
fileName = typeof fileName !== 'undefined' ? fileName : '';
fieldName = typeof fieldName !== 'undefined' ? fieldName : '';
fieldType = typeof fieldType !== 'undefined' ? fieldType : '';
fieldValue = typeof fieldValue !== 'undefined' ? fieldValue : '';

if(fileName === ''){
throw new Error('filename not provided.');
}

if(fieldName === ''){
throw new Error('fieldName not provided.');
}

if(fieldType === ''){
throw new Error('fieldType not provided.');
}

if(fieldValue === ''){
throw new Error('fieldValue not provided.');
}

var strURI = this.baseURI + 'pdf/' + fileName + '/fields/' + fieldName;
var signedURI = Utils.Sign(strURI,this.appSID,this.appKey);

var json_data = {'Name':fieldName, 'Type':fieldType, 'Values':[fieldValue]};

Utils.ProcessCommand('PUT',signedURI,json_data,function(data){
if(typeof callback === 'function'){

if(data.Status === 'OK'){
callback.call(null,data.Field);
}
}
});
};

AsposePdf.prototype.getFormFieldCount = function(fileName,callback){
fileName = typeof fileName !== 'undefined' ? fileName : '';

Expand Down Expand Up @@ -1304,7 +1504,6 @@ AsposePdf.prototype.createFromTiff = function(pdfFilename,tiffFilename,callback)

};


AsposePdf.prototype.mergeDocuments = function(sourceFiles,targetFile,callback){
sourceFiles = typeof sourceFiles !== 'undefined' ? sourceFiles : '';
targetFile = typeof targetFile !== 'undefined' ? targetFile : '';
Expand Down Expand Up @@ -1396,4 +1595,84 @@ AsposePdf.prototype.getPageCount = function(fileName,callback){
});
};

AsposePdf.prototype.addSignature = function(pdfFilename,pageNumber,postData,callback){
pdfFilename = typeof pdfFilename !== 'undefined' ? pdfFilename : '';
pageNumber = typeof pageNumber !== 'undefined' ? pageNumber : '';
postData = typeof postData !== 'undefined' ? postData : '';

if(pdfFilename === ''){
throw new Error('pdf filename not provided.');
}

if(postData === ''){
throw new Error('postData not provided.');
}

var strURI = this.baseURI + 'pdf/' + pdfFilename;
if(pageNumber != '')
{
strURI = strURI + '/pages/' + pageNumber;
}
strURI = strURI + '/sign';

var signedURI = Utils.Sign(strURI,this.appSID,this.appKey);

var appSID = this.appSID;
var appKey = this.appKey;
var baseURI = this.baseURI;

Utils.ProcessCommand('POST',signedURI,postData,function(data){
var asposeStorage = new AsposeStorage({'appSID':appSID,'appKey':appKey,'baseURI':baseURI});
if(data.Status === 'OK'){
asposeStorage.getFile(pdfFilename, '', function(data){
if(typeof callback === 'function'){
callback.call(null,data);
}
});
} else {
throw new Error(data.Status);
}
});

};

AsposePdf.prototype.addStamp = function(pdfFilename,pageNumber,postData,callback){
pdfFilename = typeof pdfFilename !== 'undefined' ? pdfFilename : '';
pageNumber = typeof pageNumber !== 'undefined' ? pageNumber : '';
postData = typeof postData !== 'undefined' ? postData : '';

if(pdfFilename === ''){
throw new Error('pdf filename not provided.');
}

if(pageNumber === ''){
throw new Error('pageNumber not provided.');
}

if(postData === ''){
throw new Error('postData not provided.');
}

var strURI = this.baseURI + 'pdf/' + pdfFilename + '/pages/' + pageNumber + '/stamp';
var signedURI = Utils.Sign(strURI,this.appSID,this.appKey);

var appSID = this.appSID;
var appKey = this.appKey;
var baseURI = this.baseURI;

Utils.ProcessCommand('PUT',signedURI,postData,function(data){
var asposeStorage = new AsposeStorage({'appSID':appSID,'appKey':appKey,'baseURI':baseURI});
if(data.Status === 'OK'){
asposeStorage.getFile(pdfFilename, '', function(data){
if(typeof callback === 'function'){
callback.call(null,data);
}
});
} else {
throw new Error(data.Status);
}
});

};

module.exports = AsposePdf;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "asposecloud",
"version": "1.6.0",
"version": "1.7.0",
"description": "Aspose Cloud SDK for NodeJS",
"main": "lib/aspose-cloud.js",
"scripts": {
Expand Down

0 comments on commit 48e13cf

Please sign in to comment.