Solved

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

Posted on 2011-03-21
7
785 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Update 21-May-2015: I temporarily removed the source code and the code snippets to make major changes to the program. Regards, Joe A recent question here at Experts Exchange piqued my interest, so I decided to provide a thorough solution and publ…
PaperPort is a popular document imaging/management product from Nuance Communications (http://www.nuance.com/). It is in widespread use by both individuals (http://www.nuance.com/for-individuals/by-product/paperport/index.htm) and businesses (http:/…
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…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

759 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now