Commit c28883f1 authored by Sergey Luzyanin's avatar Sergey Luzyanin

watermark in builder

parent 657dab84
...@@ -1503,17 +1503,47 @@ ...@@ -1503,17 +1503,47 @@
//------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------
/** /**
* Insert watermark in the header of document * Insert watermark on each page of document
* @param {?string} } [sText="Watermark"] * @param {?string} } [sText="WATERMARK"]
* @param {?boolean} [bIsDiagonal=true] * @param {?boolean} [bIsDiagonal=true]
*/ */
ApiDocument.prototype.InsertWatermark = function(sText, bIsDiagonal){ ApiDocument.prototype.InsertWatermark = function(sText, bIsDiagonal){
var oSectPrMap = {};
var oApiSection = this.GetFinalSection(); if(this.Document.SectPr){
if(oApiSection){ oSectPrMap[this.Document.SectPr.Get_Id()] = this.Document.SectPr;
privateInsertWatermarkToContent(oApiSection.GetHeader("title", false), sText, bIsDiagonal); }
privateInsertWatermarkToContent(oApiSection.GetHeader("even", false), sText, bIsDiagonal); var oElement;
privateInsertWatermarkToContent(oApiSection.GetHeader("default", true), sText, bIsDiagonal); for(var i = 0; i < this.Document.Content.length; ++i){
oElement = this.Document.Content[i];
if(oElement instanceof Paragraph){
if(oElement.SectPr){
oSectPrMap[oElement.SectPr.Get_Id()] = oElement.SectPr;
}
}
}
var oHeadersMap = {};
var oApiSection, oHeader;
for(var sId in oSectPrMap){
if(oSectPrMap.hasOwnProperty(sId)){
oApiSection = new ApiSection(oSectPrMap[sId]);
oHeader = oApiSection.GetHeader("title", false);
if(oHeader){
oHeadersMap[oHeader.Document.Get_Id()] = oHeader;
}
oHeader = oApiSection.GetHeader("even", false);
if(oHeader){
oHeadersMap[oHeader.Document.Get_Id()] = oHeader;
}
oHeader = oApiSection.GetHeader("default", true);
if(oHeader){
oHeadersMap[oHeader.Document.Get_Id()] = oHeader;
}
}
}
for(var sId in oHeadersMap){
if(oHeadersMap.hasOwnProperty(sId)){
privateInsertWatermarkToContent(this.Document.Api, oHeadersMap[sId], sText, bIsDiagonal);
}
} }
}; };
/** /**
...@@ -4948,7 +4978,7 @@ ...@@ -4948,7 +4978,7 @@
} }
function private_CreateWatermark(sText, bDiagonal){ function private_CreateWatermark(sText, bDiagonal){
var sText2 = ((typeof (sText) === "string") && (sText.length > 0)) ? sText : "Watermark"; var sText2 = ((typeof (sText) === "string") && (sText.length > 0)) ? sText : "WATERMARK";
var sFontName2 = undefined; var sFontName2 = undefined;
var nFontSize2 = 2; var nFontSize2 = 2;
var oTextFill2 = AscFormat.CreateUnfilFromRGB(127, 127, 127); var oTextFill2 = AscFormat.CreateUnfilFromRGB(127, 127, 127);
...@@ -5034,7 +5064,7 @@ ...@@ -5034,7 +5064,7 @@
} }
function privateInsertWatermarkToContent(oContent, sText, bIsDiagonal){ function privateInsertWatermarkToContent(oApi, oContent, sText, bIsDiagonal){
if(oContent){ if(oContent){
var nElementsCount = oContent.GetElementsCount(); var nElementsCount = oContent.GetElementsCount();
for(var i = 0; i < nElementsCount; ++i){ for(var i = 0; i < nElementsCount; ++i){
...@@ -5045,7 +5075,7 @@ ...@@ -5045,7 +5075,7 @@
} }
} }
if(i === nElementsCount){ if(i === nElementsCount){
oElement = Api.CreateParagraph(); oElement = oApi.CreateParagraph();
oElement.AddDrawing(private_CreateWatermark(sText, bIsDiagonal)); oElement.AddDrawing(private_CreateWatermark(sText, bIsDiagonal));
oContent.Push(oElement); oContent.Push(oElement);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment