[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 860
  • Last Modified:

Text field placement on adobe PDF when generating with vb.net code

I am adding a text field in a PDF document with vb.net code that I borrowed from here.  It works fine but I am having issues with moving the Field around on the pdf.
Sub AddToPDF(ByVal FileLocation As String, ByVal FileDestination As String)
        Dim filepath As String
        Dim Filename As String
        filepath = FileLocation
        Dim sFileName() As String = Directory.GetFiles(filepath)

        Dim DocID As String
        'FileName = 
        'FileName = "C:\Testing\STRTILT20001841.pdf"

        For Each s As String In sFileName
            Filename = s
            DocID = Filename.PadRight(4, Filename)


            App = CreateObject("AcroExch.App")
            PDDoc = CreateObject("AcroExch.PDDoc")

            If PDDoc.Open(Filename) Then
                jso = PDDoc.GetJSObject

                'rect(0) = 2 * 72  ' x upper left
                'rect(1) = 1 * 72  ' y upper left
                'rect(2) = 300 * 72 ' x lower right
                'rect(3) = 0.5 * 72  ' y lower right

                'rect(0) = 100  ' x lower left
                'rect(1) = 100  ' y lower left
                'rect(2) = 300  ' x upper right
                'rect(3) = 200  ' y upper right

                rect(0) = 1 * 72  ' x upper left
                rect(1) = 0.5 * 72  ' y upper left
                rect(2) = 150 * 72 ' x lower right
                rect(3) = 0.25 * 72  ' y lower right

                ' add a form field
                field = jso.addField("myFormField", "text", 0, rect)
                field.Value = "Doc ID #     " & DocID

                jso.flattenPages()

                i = PDDoc.Save(PDSaveIncremental, Filename)

            End If

            PDDoc.Close()
        Next
    End Sub

Open in new window

0
thomashospital
Asked:
thomashospital
  • 4
  • 3
1 Solution
 
Karl Heinz KremerCommented:
You are mixing just providing a points value and calculating a points value based on a value specified in inches. That's not a problem in general, but can lead to mistakes like the one in the line where you have 150 * 72 - that's 72 inches. I assume that your field got placed correctly, and once you zoom out so that you can actually see 72" you'll see your field.
0
 
thomashospitalAuthor Commented:
I am placing a value in the PDF.  I can see it fine and it is the size I need.  The issue is its in the lower left at the bottom.  Lets say I needed it at the top of the PDF how would I do that.  I assumed the values that I am using now are just for the size of the actual field.  Could you explain more?
0
 
Karl Heinz KremerCommented:
You would get the size of the page's crop box and then based on that, determine where your box should go. I am not at my computer, so I cannot come up with a sample until I get back to the office.

What exactly are your problems? Do you think you know how it's supposed to work, but you are not getting the right results, or do you not even now how to specify the coordinates? You are working with the JavaScript bridge, so you need access to the Acrobat JavaScript scripting reference - do you have that document?
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
thomashospitalAuthor Commented:
I honestly do not know how to specify coordinates.  I would love an example.
0
 
Karl Heinz KremerCommented:
The coordinates are organized like this: upper-left x, upper-left y, lower-right x and lower-right y (in that order). Values are specified in points (72 points to an inch). So, if you want a button that is 10" up from the bottom of the page, 1 inch in from the left edge, 1/2 inch high and 2 inches wide, you would use the following:

                rect(0) = 1 * 72  ' x upper left
                rect(1) = 10 * 72  ' y upper left
                rect(2) = 3 * 72 ' x lower right - that is 1in plus 2in
                rect(3) = 9.5 * 72  ' y lower right - that is 10in - 0.5in

0
 
thomashospitalAuthor Commented:
When i do this it disappears from the PDF.  Cant find it in search either.
0
 
Karl Heinz KremerCommented:
Which version of Acrobat are you using? Could you provide a sample PDF file that has the "missing" form field added?
0

Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now