Solved

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

Posted on 2011-03-21
7
793 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Power PDF (http://www.nuance.com/for-business/document-imaging-and-scanning/power-pdf-converter/index.htm) is the newest product from the Document Imaging division of Nuance Communications (http://www.nuance.com/). It is available in two editions — …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

932 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

12 Experts available now in Live!

Get 1:1 Help Now