使用VBA将多个PDF合并为单个PDF

时间:2013-04-02 12:07:56

标签: vba ms-access pdf ms-access-2010

我正在制定一项要求,即我将14个PDF合并为单个PDF文件。我还想在合并后为每个页面添加页码。

任何人都知道如何使用VBA在PDF文件中添加页码?

我在MS-Access 2010 VBA中进行编码并生成PDF我正在使用Adobe Acrobat Standard。

1 个答案:

答案 0 :(得分:1)

Path = "F:\Target.pdf"
'Path = Wscript.Arguments.Item(0)

Set App = CreateObject("Acroexch.app") 
app.show
Set AVDoc = CreateObject("AcroExch.AVDoc") 
Set AForm = CreateObject("AFormAut.App") 'from AFormAPI


If AVDoc.Open(Path,"") Then 
  '//write JS-Code on a variable
  Ex = "  // Set Footer PageNo centered  "&vbLF _
  & "  var Box2Width = 50  "&vbLF _
  & "  for (var p = 0; p < this.numPages; p++)   "&vbLF _
  & "   {   "&vbLF _
  & "    var aRect = this.getPageBox(""Crop"",p);  "&vbLF _
  & "    var TotWidth = aRect[2] - aRect[0]  "&vbLF _
  & "     {  var bStart=((TotWidth/2)-(Box2Width/2)) " & vbLf _
  & "         var bEnd=((TotWidth/2)+(Box2Width/2)) + 5  "&vbLF _
  & "         var fp = this.addField(String(""xftPage""+p+1), ""text"", p, [bStart,45,bEnd,15]);   "&vbLF _
  & "         fp.value = ""Page: "" + String(p+1)+ ""/"" + this.numPages;  "&vbLF _
  & "         fp.textSize=9;  fp.readonly = true;  "&vbLF _
  & "         fp.alignment=""right"";  "&vbLF _
  & "     } "&vbLF _
  & "   }  "

'//Execute JS-Code
AForm.Fields.ExecuteThisJavaScript Ex

App.Exit

end if