Solved

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

Posted on 2011-03-21
7
807 Views
Last Modified: 2012-05-11
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
Comment
Question by:thomashospital
  • 4
  • 3
7 Comments
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 35188064
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
 

Author Comment

by:thomashospital
ID: 35188583
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
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 35194251
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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 

Author Comment

by:thomashospital
ID: 35197589
I honestly do not know how to specify coordinates.  I would love an example.
0
 
LVL 44

Accepted Solution

by:
Karl Heinz Kremer earned 500 total points
ID: 35227400
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
 

Author Comment

by:thomashospital
ID: 35232172
When i do this it disappears from the PDF.  Cant find it in search either.
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 35232232
Which version of Acrobat are you using? Could you provide a sample PDF file that has the "missing" form field added?
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

*Adobe Acrobat 9 was used for this article.  Particular steps may vary depending on software versions. Adobe Acrobat has many, many variables that my be utilized to customize your forms for clarity and ease of use. The Form Editing Tool will be y…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In this video, we show how to perform Bates Numbering/Stamping of PDF documents using Power PDF Advanced, the newest product from the Document Imaging division of Nuance Communications. There are two editions of Power PDF — Standard and Advanced. Th…
Sometimes we receive PDF files that are in the wrong orientation. They may be sideways or even upside down. This most commonly happens with scanned or faxed documents. It is possible to rotate the view of these PDFs with the free Adobe Reader produc…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question