Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2011-03-21
7
Medium Priority
?
853 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 

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 2000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Have you ever come up with a need of emailing only few pages of PDF file to one of yourfriend or colleague, instead of whole Adobe file? If yes, then surely you have face problems in doing that! Read this section as I have suggested multiple solutio…
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 fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

618 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