3 Replies Latest reply on Dec 7, 2010 5:46 PM by dying veteran

    Adding a Text to existing PDF using VB

    MGacPLWAW

      Hi

       

      I've been struggling with this for some time. Maybe someone knows how to access the PDF document and add text box to an existing doc using VBA.

       

      I know it is quite easy to go to tools select Add or Edit Text Box from menu and then add text but I need to this to be done automatically.

       

      I was trying to do it via AcroEch.App ManuItemExecute but the AIC reference sends to API library to find the name of the menu item and I could not find the menu item for action add or edit text box.

       

      The problem doesn't seem to be complicated ... but for me it is.

       

      So again maybe someone knows how to do it.

       

      Regards

      MGac

        • 1. Re: Adding a Text to existing PDF using VB
          ReinhardF Level 3

          Hi,

           

          attached a VBS which uses add.field js-code to number pages.

          Load down the AcroJS.pdf help file and  look for the js code/example, which you can use.

          Write it on the vbs-variable EX and replace the given line EX = ... with that.

           

          HTH, Reinhard

           

           

           

           

          C:\AcroPageNumbers.vbs
          -------------------------------------------

           

          Path = "C:\Test.pdf"

          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))  "&vbLF _
            & "         var fp = this.addField(String(""xftPage""+p+1), ""text"", p, [bStart,30,bEnd,15]);   "&vbLF _
            & "         fp.value = ""Page: "" + String(p+1)+ ""/"" + this.numPages;  "&vbLF _
            & "         fp.textSize=6;  fp.readonly = true;  "&vbLF _
            & "         fp.alignment=""center"";  "&vbLF _
            & "     }  "&vbLF _
            & "   }  "
          '//Execute JS-Code
          AForm.Fields.ExecuteThisJavaScript Ex
          msgBox("Done")
          end if

          Set AVDoc = Nothing
          Set APP = Nothing

          • 2. Re: Adding a Text to existing PDF using VB
            MGacPLWAW Level 1

             

            Hi,

             

             

             

            thanks a lot this is what I needed.

             

             

             

            Now what's left is to modify the code and this is easy

             

            the most important is that you showed me the logic

             

             

             

            Again thanks

            • 3. Re: Adding a Text to existing PDF using VB
              dying veteran Level 1

              Hello Reinhard,

               

              do you get this email ?

               

              Roger