王老师您好,我找到一段代码,可以在PDF文件中插入水印文字,可以间接解决前面的那个问题。但是这个代码是在页面的顶端、中间或者底部插入水印,我想要在任意位置(指定位置)插入水印文字,不知道怎么修改这个代码,请您帮看看。
另外,这段代码插入中文显示不出,大概是字体设置的问题吧?怎么设置中文字体呢?- Sub addWaterMark()
- sTime = Timer
- '根据需要动态添加水印
- Dim pdApp As Acrobat.AcroApp
- Dim pdDoc As Acrobat.AcroPDDoc
- Dim pdPage As Acrobat.AcroPDPage
- Dim jso As Object
- Dim watermark As String, watermarkID As Integer, watermarkfile As String, watermarkpos As String
- Dim II As Integer
- Set pdApp = CreateObject("AcroExch.App")
- Set pdDoc = CreateObject("AcroExch.PDDoc")
-
- watermarkfile = "z:\11.pdf"
-
-
- pdDoc.Open (watermarkfile) '打开PDF文件
- Set jso = pdDoc.GetJSObject
-
- watermark = "Test 广西桂林市"
- watermarkID = 0
- watermarkpos = "Top" 'Center|bottom
- If watermarkpos = "Top" Then
-
- Call jso.addWaterMarkFromText(watermark, jso.app.Constants.Align.Right, jso.Font.Helv, 20, jso.Color.Black, watermarkID, watermarkID, True, True, True, jso.app.Constants.Align.Left, jso.app.Constants.Align.Top, 0, 0, False, 1, False, 0, 1)
- ElseIf watermarkpos = "Bottom" Then
- Call jso.addWaterMarkFromText(watermark, jso.app.Constants.Align.Right, jso.Font.Helv, 20, jso.Color.Black, watermarkID, watermarkID, True, True, True, jso.app.Constants.Align.Left, jso.app.Constants.Align.bottom, 0, 0, False, 1, False, 0, 1)
- Else
- Call jso.addWaterMarkFromText(watermark, jso.app.Constants.Align.Right, jso.Font.Helv, 20, jso.Color.Black, watermarkID, watermarkID, True, True, True, jso.app.Constants.Align.Left, jso.app.Constants.Align.Center, 0, 0, False, 1, False, 0, 1)
- End If
-
- pdDoc.Save 1, watermarkfile '保存文件,覆盖不提示
- pdDoc.Close '关闭文件
- Set pdDoc = Nothing
- Set pdApp = Nothing
- MsgBox "数据计算完毕!用时" & Round(Timer - sTime, 2) & "秒。" & Round((Timer - sTime) / 60, 4) & "分钟。"
- End Sub
复制代码 |