NTKO OFFICE文档控件技术资料
NTKO OFFICE文档控件技术资料

NTKO OFFICE文档控件技术资料

如何在Word中增加图片水印?

//增加图片水印,参数url为绝对url
function addWaterMarkPic(URL)
{
        try
        {
                //TANGER_OCX_OBJ为控件对象
var ActiveDocument = TANGER_OCX_OBJ.ActiveDocument;
for (i=1;i<=ActiveDocument.Sections.Count ; i++){
                ActiveDocument.Sections(i).Range.Select();
                ActiveDocument.ActiveWindow.ActivePane.View.SeekView = 9; //wdSeekCurrentPageHeader
                var Selection = ActiveDocument.Application.Selection;
                //url只能为绝对url
                Selection.HeaderFooter.Shapes.AddPicture(URL,false,true).Select();
                Selection.ShapeRange.Name = “WordPictureWatermark1”;
                Selection.ShapeRange.PictureFormat.Brightness =0.8;
                Selection.ShapeRange.PictureFormat.Contrast =0.5;
                Selection.ShapeRange.LockAspectRatio = true;
                Selection.ShapeRange.Height = ActiveDocument.Application.CentimetersToPoints(4.42);
                Selection.ShapeRange.Width = ActiveDocument.Application.CentimetersToPoints(4.92);
                Selection.ShapeRange.WrapFormat.AllowOverlap = true;
                Selection.ShapeRange.WrapFormat.Side = 3;
                Selection.ShapeRange.WrapFormat.Type = 3;
                Selection.ShapeRange.RelativeHorizontalPosition =0;
                Selection.ShapeRange.RelativeVerticalPosition =0;
                Selection.ShapeRange.Left=-999995; //wdShapeCenter
                Selection.ShapeRange.Top=-999995; //wdShapeCenter
                ActiveDocument.ActiveWindow.ActivePane.View.SeekView = 0;//wdSeekMainDocument
      }
        }
        catch(err){
                alert(“addWaterMark errir:” + err.number + “:” + err.description);
        } 
}

//保护文档部分修改function protectDoc(){

var marks=obj.ActiveDocument.Bookmarks;//获取所有的书签
for(var i=1; i<=marks.Count; i++){
obj.ActiveDocument.Bookmarks(marks(i).Name).Range.Select();//选取书签区域保护
obj.ActiveDocument.Application.Selection.Editors.Add(-1);//增加可编辑区域
//NTKO START
obj.ActiveDocument.ActiveWindow.View.ShadeEditableRanges = true;
obj.ActiveDocument.ActiveWindow.View.ShowBookmarks = true;
//NTKO END
}
if(obj.ActiveDocument.ProtectionType==-1){
obj.ActiveDocument.Protect(3);//实现文档保护
}
}

//取消可编辑区域,保护文档,每个地方都不能修改
function unEditDoc(){
obj.ActiveDocument.DeleteAllEditableRanges(-1)
//增加可编辑区域
//NTKO START
obj.ActiveDocument.ActiveWindow.View.ShadeEditableRanges = false;
obj.ActiveDocument.ActiveWindow.View.ShowBookmarks = false;
//NTKO END
if(obj.ActiveDocument.ProtectionType==-1){
obj.ActiveDocument.Protect(3);//实现文档保护
}
}

Visits: 25

发表回复