These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

How to Hide Acrobat When Running VBA Code

str2323
Registered: Feb 24 2009
Posts: 6
Answered

My project adds text to Acrobat fillable fields using VBA written in Access 2003. I take records from my Access database, and populate it into different Acrobat Forms based on the field name in the Acrobat Form. I am able to do this, but there is one problem.

The problem is that as the code runs through populating text in the Acrobat Forms, Acrobat opens up each form, and makes it visible to the user. It populates quick, but it is still visible. I want this to run in the background, or at least be minimized in the windows taskbar. The users should not not know which form the Application is updating. It should be hidden or invisible. That is the goal at least :)

I know which line in the code causes it to Maximize, but if I remove that line, I receive an error about No Document Currently Open in Acrobat Viewer.

Here is the snippet of the code I am using. Any help would be greatly appreciated.

Dim gApp As Acrobat.CAcroApp
Dim avdoc As Acrobat.CAcroAVDoc
Dim gPDDoc As Acrobat.CAcroPDDoc
Const DOC_FOLDER As String = "C:\Trial"
Dim x As Boolean

Set gApp = CreateObject("AcroExch.App")
Set gPDDoc = CreateObject("AcroExch.PDDoc")
Set avdoc = CreateObject("AcroExch.AVDoc")

'Hides Acrobat - So Far So Good
gApp.Hide

Dim FormApp As AFORMAUTLib.AFormApp
Dim AcroForm As AFORMAUTLib.Fields
Dim Field As AFORMAUTLib.Field

'Open PDF that I choose. Acrobat still has not flashed on my screen
x = avdoc.Open(DOC_FOLDER & "\trial.pdf", "temp")

'Acrobat Now Pops up on my screen. However, I get an error without this line
avdoc.Maximize(1)

'Hides it again, right after it opens. This creates the a flash
gApp.Hide

Set FormApp = CreateObject("AFormAut.App")

'If the Maximize line is not there, this is where I receive error about document viewer
For Each Field In FormApp.Fields
If Field.Name = "Sample_FieldName" Then
Field.Value = TextToUse
End If
Next

Please let me know if you can think of a way to keep Acrobat hidden. Thank you.

My Product Information:
Acrobat Standard 7.0.2, Windows
ascnd
Registered: Mar 6 2009
Posts: 2
Did you ever figure this out? I have the exact same problem and I have even posted your question on Experts-Exchange, but no one has fiqured it out.

http://www.experts-exchange.com/Microsoft/Development/MS_Access/Q_24194227.php

Let me know.

Thanks.
str2323
Registered: Feb 24 2009
Posts: 6
No, I am sorry. I still haven't figured out this problem. Its good to know someone else is looking, though. If you ever find the answer, please post it here to share.
ascnd
Registered: Mar 6 2009
Posts: 2
Good news I got a solution!!! Let me know how it works out. Also if you know how to align text to the top or bottom of a field then let me know. Remember this solution is posted at www.experts-exchange.com
http://www.experts-exchange.com/Microsoft/Development/MS_Access/Q_24194227.php#a23922359


REPLY khkremer 01:
khkremer:You don't have to use an AVDoc to do this. There are two documents - AVDoc and PDDoc. A PDDoc gets opened in the background, and therefore you would not see anything on your monitor. An AVDoc is a document that gets opened in the viewer, so it is visible. Every AVDoc has an associated PDDoc, but not every PDDoc is represented by an AVDoc (only those that are shown in the viewer).

With the PDDoc, you can then instantiate a JSO (JavaScript object) and use that to modify your form fields in the background. Here is a blog post that I wrote up about the JSO:
http://khk.net/wordpress/2009/03/11/acrobat-javascript-and-vb-walk-into-a-bar/

REPLY khkremer 02:
Sub Button1_Click()
Dim gApp As Acrobat.CAcroApp
Dim gPDDoc As Acrobat.CAcroPDDoc
Dim jso As Object

Set gApp = CreateObject("AcroExch.App")
Set gPDDoc = CreateObject("AcroExch.PDDoc")
If gPDDoc.Open("c:\temp\form.pdf") Then
Set jso = gPDDoc.GetJSObject
Dim field1 As Object
Set field1 = jso.getField("Text1")
field1.Value = "this is is a test"
jso.SaveAs ("c:\temp\form.pdf")
End If
End Sub

ASCND REPLY 01:
Your suggestion works perfectly! I would give you a big hug if you were here right now. I have attached my code in case anyone else needs this info.

By the way do you know how to align text in field so that it is at the top or bottom of the field? It defaults to center which does not look good on my form since it is a long field. I searched the JavaScript API SDK document and I only found "Alignment" field property which only horizontally aligns the text.

Public Function HIDDEN_PDFaddFormFields(sInputPDFpath As String, sOutputPDFpath As String, bPrintDocID As Boolean, dDocID As Double, ShowMsg As Integer)
Dim sErr As String
Dim bOpen As Boolean
Dim pgs As Long
Dim X As Long: Dim Y As Long
Dim bxHt As Integer
Dim bxLength As Integer: Dim bxTop As Integer: Dim bxLeft As Integer: Dim bxSpace As Integer
Dim ux As Integer, uy As Integer, lx As Integer, ly As Integer
Dim jso As Object
Dim gPDDoc As Object
Dim jFld As Object
Dim Rect(1 To 4) As Long
Dim Color(1 To 4) As String

On Error GoTo ErrorHandler

If Dir(sOutputPDFpath, vbNormal) <> "" Then Kill sOutputPDFpathColor(1) = "RGB": Color(2) = 1: Color(3) = 1: Color(4) = 1

Set gPDDoc = CreateObject("AcroExch.PDDoc")
bOpen = gPDDoc.Open(sInputPDFpath)
Set jso = gPDDoc.GetJSObject

pgs = jso.numPages

For X = 0 To pgs - 1
bxHt = 13: bxLength = 170: bxTop = 650: bxLeft = 90: bxSpace = bxHt + 0
For Y = 0 To 4
''' upper-left x, upper-left y, lower-right x and lower-right y.
ux = bxLeft: uy = bxTop - (Y * bxSpace): lx = ux + bxLength: ly = uy - bxHt
Rect(1) = ux: Rect(2) = uy: Rect(3) = lx: Rect(4) = ly
Set jFld = jso.addField("FldT" & Y & Right("0000" & X, 4), "text", X, Rect)
jFld.TextSize = 8
jFld.lineWidth = 1
jFld.ReadOnly = False
jFld.charLimit = 42
Next Y

bxHt = 75: bxLength = 80: bxTop = 496: bxLeft = 360: bxSpace = bxLength + 5
For Y = 0 To 1
ux = bxLeft - (Y * bxSpace): uy = bxTop: lx = ux + bxLength: ly = uy - bxHt
Rect(1) = ux: Rect(2) = uy: Rect(3) = lx: Rect(4) = ly
Set jFld = jso.addField("FldO" & Y & Right("0000" & X, 4), "text", X, Rect)
jFld.TextSize = 8
jFld.lineWidth = 1
jFld.ReadOnly = False
jFld.charLimit = 42
Next Y

If bPrintDocID Then 'add the document id
bxHt = 10: bxLength = 80: bxTop = 52: bxLeft = 661: bxSpace = bxLength + 5
ux = bxLeft - (Y * bxSpace): uy = bxTop: lx = ux + bxLength: ly = uy - bxHt
Rect(1) = ux: Rect(2) = uy: Rect(3) = lx: Rect(4) = ly
Set jFld = jso.addField("FldN" & Right("0000" & X, 4), "text", X, Rect)
jFld.TextSize = 7
jFld.MultiLine = True
jFld.Value = "Doc{ " & dDocID & "}"
jFld.lineWidth = 1
jFld.ReadOnly = True
jFld.FillColor = Color ''' or you could have used jso.color.white
jFld.Alignment = "right"
End If

Next

jso.SaveAs (sOutputPDFpath)

Do Until Dir(sOutputPDFpath) <> "": LoopExit Function
ErrorHandler:
sErr = Err.Number & " " & Err.Description
Select Case Err.Number
Case 0
Case Else
RecErr Err.Number, Err.Description, "HIDDEN_PDFaddFormFields ErrorHandler", sErr, ShowMsg
End Select
Err.Clear
End Function
str2323
Registered: Feb 24 2009
Posts: 6
Excellent. Thanks a lot for posting back here with that. I really appreciate it.