acrobat 0.0.8 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,393 @@
1
+ Option Strict Off
2
+ Option Explicit On
3
+ Friend Class FormsAutomation
4
+ Inherits System.Windows.Forms.Form
5
+ #Region "Windows Form Designer generated code "
6
+ Public Sub New()
7
+ MyBase.New()
8
+ If m_vb6FormDefInstance Is Nothing Then
9
+ If m_InitializingDefInstance Then
10
+ m_vb6FormDefInstance = Me
11
+ Else
12
+ Try
13
+ 'For the start-up form, the first instance created is the default instance.
14
+ If System.Reflection.Assembly.GetExecutingAssembly.EntryPoint.DeclaringType Is Me.GetType Then
15
+ m_vb6FormDefInstance = Me
16
+ End If
17
+ Catch
18
+ End Try
19
+ End If
20
+ End If
21
+ 'This call is required by the Windows Form Designer.
22
+ InitializeComponent()
23
+ End Sub
24
+ 'Form overrides dispose to clean up the component list.
25
+ Protected Overloads Overrides Sub Dispose(ByVal Disposing As Boolean)
26
+ If Disposing Then
27
+ If Not components Is Nothing Then
28
+ components.Dispose()
29
+ End If
30
+ End If
31
+ MyBase.Dispose(Disposing)
32
+ End Sub
33
+ 'Required by the Windows Form Designer
34
+ Private components As System.ComponentModel.IContainer
35
+ Public ToolTip1 As System.Windows.Forms.ToolTip
36
+ Public WithEvents ExitButton As System.Windows.Forms.Button
37
+ Public WithEvents StatusBox As System.Windows.Forms.TextBox
38
+ Public WithEvents CreateFieldsButton As System.Windows.Forms.Button
39
+ Public WithEvents StatusLabel As System.Windows.Forms.Label
40
+ 'NOTE: The following procedure is required by the Windows Form Designer
41
+ 'It can be modified using the Windows Form Designer.
42
+ 'Do not modify it using the code editor.
43
+ <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
44
+ Me.components = New System.ComponentModel.Container
45
+ Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components)
46
+ Me.ExitButton = New System.Windows.Forms.Button
47
+ Me.StatusBox = New System.Windows.Forms.TextBox
48
+ Me.CreateFieldsButton = New System.Windows.Forms.Button
49
+ Me.StatusLabel = New System.Windows.Forms.Label
50
+ Me.SuspendLayout()
51
+ '
52
+ 'ExitButton
53
+ '
54
+ Me.ExitButton.BackColor = System.Drawing.SystemColors.Control
55
+ Me.ExitButton.Cursor = System.Windows.Forms.Cursors.Default
56
+ Me.ExitButton.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
57
+ Me.ExitButton.ForeColor = System.Drawing.SystemColors.ControlText
58
+ Me.ExitButton.Location = New System.Drawing.Point(152, 15)
59
+ Me.ExitButton.Name = "ExitButton"
60
+ Me.ExitButton.RightToLeft = System.Windows.Forms.RightToLeft.No
61
+ Me.ExitButton.Size = New System.Drawing.Size(113, 25)
62
+ Me.ExitButton.TabIndex = 3
63
+ Me.ExitButton.Text = "Exit"
64
+ Me.ExitButton.UseVisualStyleBackColor = False
65
+ '
66
+ 'StatusBox
67
+ '
68
+ Me.StatusBox.AcceptsReturn = True
69
+ Me.StatusBox.BackColor = System.Drawing.SystemColors.ButtonFace
70
+ Me.StatusBox.Cursor = System.Windows.Forms.Cursors.IBeam
71
+ Me.StatusBox.Enabled = False
72
+ Me.StatusBox.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
73
+ Me.StatusBox.ForeColor = System.Drawing.SystemColors.WindowText
74
+ Me.StatusBox.Location = New System.Drawing.Point(64, 56)
75
+ Me.StatusBox.MaxLength = 0
76
+ Me.StatusBox.Name = "StatusBox"
77
+ Me.StatusBox.ReadOnly = True
78
+ Me.StatusBox.RightToLeft = System.Windows.Forms.RightToLeft.No
79
+ Me.StatusBox.Size = New System.Drawing.Size(200, 19)
80
+ Me.StatusBox.TabIndex = 1
81
+ '
82
+ 'CreateFieldsButton
83
+ '
84
+ Me.CreateFieldsButton.BackColor = System.Drawing.SystemColors.Control
85
+ Me.CreateFieldsButton.Cursor = System.Windows.Forms.Cursors.Default
86
+ Me.CreateFieldsButton.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
87
+ Me.CreateFieldsButton.ForeColor = System.Drawing.SystemColors.ControlText
88
+ Me.CreateFieldsButton.Location = New System.Drawing.Point(16, 15)
89
+ Me.CreateFieldsButton.Name = "CreateFieldsButton"
90
+ Me.CreateFieldsButton.RightToLeft = System.Windows.Forms.RightToLeft.No
91
+ Me.CreateFieldsButton.Size = New System.Drawing.Size(113, 25)
92
+ Me.CreateFieldsButton.TabIndex = 0
93
+ Me.CreateFieldsButton.Text = "Create Fields"
94
+ Me.CreateFieldsButton.UseVisualStyleBackColor = False
95
+ '
96
+ 'StatusLabel
97
+ '
98
+ Me.StatusLabel.BackColor = System.Drawing.SystemColors.Control
99
+ Me.StatusLabel.Cursor = System.Windows.Forms.Cursors.Default
100
+ Me.StatusLabel.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
101
+ Me.StatusLabel.ForeColor = System.Drawing.SystemColors.ControlText
102
+ Me.StatusLabel.Location = New System.Drawing.Point(16, 58)
103
+ Me.StatusLabel.Name = "StatusLabel"
104
+ Me.StatusLabel.RightToLeft = System.Windows.Forms.RightToLeft.No
105
+ Me.StatusLabel.Size = New System.Drawing.Size(40, 17)
106
+ Me.StatusLabel.TabIndex = 2
107
+ Me.StatusLabel.Text = "Status:"
108
+ '
109
+ 'FormsAutomation
110
+ '
111
+ Me.AcceptButton = Me.ExitButton
112
+ Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
113
+ Me.BackColor = System.Drawing.SystemColors.Control
114
+ Me.ClientSize = New System.Drawing.Size(281, 89)
115
+ Me.Controls.Add(Me.ExitButton)
116
+ Me.Controls.Add(Me.StatusBox)
117
+ Me.Controls.Add(Me.CreateFieldsButton)
118
+ Me.Controls.Add(Me.StatusLabel)
119
+ Me.Cursor = System.Windows.Forms.Cursors.Default
120
+ Me.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
121
+ Me.Location = New System.Drawing.Point(11, 30)
122
+ Me.MaximizeBox = False
123
+ Me.Name = "FormsAutomation"
124
+ Me.RightToLeft = System.Windows.Forms.RightToLeft.No
125
+ Me.Text = "Acrobat Forms Automation Demo"
126
+ Me.ResumeLayout(False)
127
+
128
+ End Sub
129
+ #End Region
130
+ #Region "Upgrade Support "
131
+ Private Shared m_vb6FormDefInstance As FormsAutomation
132
+ Private Shared m_InitializingDefInstance As Boolean
133
+ Public Shared Property DefInstance() As FormsAutomation
134
+ Get
135
+ If m_vb6FormDefInstance Is Nothing OrElse m_vb6FormDefInstance.IsDisposed Then
136
+ m_InitializingDefInstance = True
137
+ m_vb6FormDefInstance = New FormsAutomation()
138
+ m_InitializingDefInstance = False
139
+ End If
140
+ DefInstance = m_vb6FormDefInstance
141
+ End Get
142
+ Set
143
+ m_vb6FormDefInstance = Value
144
+ End Set
145
+ End Property
146
+ #End Region
147
+
148
+ ' ADOBE SYSTEMS INCORPORATED
149
+ ' Copyright (C) 1994-2003 Adobe Systems Incorporated
150
+ ' All rights reserved.
151
+ '
152
+ ' NOTICE: Adobe permits you to use, modify, and distribute this file
153
+ ' in accordance with the terms of the Adobe license agreement
154
+ ' accompanying it. If you have received this file from a source other
155
+ ' than Adobe, then your use, modification, or distribution of it
156
+ ' requires the prior written permission of Adobe.
157
+ '
158
+ ' -------------------------------------------------------------------
159
+ '
160
+ ' FormsAutomation.vbp
161
+ '
162
+ ' - The application shows how to add Text boxes, combo boxes, radio
163
+ ' buttons and action buttons to a PDF. In this case, the PDF is
164
+ ' empty and we are adding form fields to it.
165
+ '
166
+ ' - To run the sample:
167
+ '
168
+ ' Run the sample and click on the Create Fields button. The
169
+ ' sample will open the IAC\TestFiles\FormsAutomation.pdf file
170
+ ' in Acrobat and add form fields to it.
171
+
172
+
173
+ Dim formApp As AFORMAUTLib.AFormApp
174
+ Dim acroForm As AFORMAUTLib.Fields
175
+ Dim field As AFORMAUTLib.Field
176
+ Dim bOK As Boolean
177
+ Dim avDoc As Acrobat.CAcroAVDoc
178
+ Dim pdDoc As Acrobat.CAcroPDDoc
179
+ Dim radiobuttonArray(5) As String
180
+
181
+ Private Sub CreateFieldsButton_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles CreateFieldsButton.Click
182
+
183
+ 'Set the mouse icon to display an hourglass
184
+ System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor
185
+
186
+ 'Disable the create fields button
187
+ CreateFieldsButton.Enabled = False
188
+
189
+ 'Update the status box
190
+ StatusBox.Text = "Opening PDF Document..."
191
+
192
+ ' Open the sample PDF file
193
+ avDoc = CreateObject("AcroExch.AVDoc")
194
+ Dim file As String = System.Windows.Forms.Application.StartupPath & "\..\..\..\..\TestFiles\FormsAutomation.pdf"
195
+
196
+ bOK = avDoc.Open(file, "Forms Automation Demo")
197
+
198
+ 'If everything was OK opening the PDF, we now instantiate the Forms
199
+ 'Automation object.
200
+ If (bOK) Then
201
+ formApp = CreateObject("AFormAut.App")
202
+ acroForm = formApp.Fields
203
+ Else
204
+ System.Runtime.InteropServices.Marshal.ReleaseComObject(avDoc)
205
+ avDoc = Nothing
206
+ MsgBox("Failed to open PDF Document. Aborting...")
207
+ End
208
+ End If
209
+
210
+ 'Update the status box
211
+ StatusBox.Text = "Creating Form Fields..."
212
+
213
+ 'Add a Text Field to the PDF
214
+ ' Fields.Add takes seven parameters:
215
+ ' FieldName is the The fully-qualified name of the field.
216
+ ' FieldType is the field type for the newly created field. Valid types are:
217
+ ' "text", "button", "combobox", "listbox", "checkbox", "radiobutton".
218
+ ' You must spell the field type names exactly as shown, including
219
+ ' use the quotation marks.
220
+ ' PageNum is the zero-based page number to add the field to.
221
+ ' Left A float for the left most position of the rectangle placement.
222
+ ' Top A float for the top of the rectangle placement.
223
+ ' Right A float for the right most position of the rectangle placement.
224
+ ' Bottom A float for the bottom of the rectangle placement.
225
+ field = acroForm.Add("Name", "text", 0, 100, 650, 450, 675)
226
+
227
+ 'Next use Field.SetBorderColor to set the color of the fields borders in
228
+ 'Gray scale, Transparent, RGB or CMYK color. All values are floating point numbers
229
+ 'between 0 and 1. In the example below, we are using RGB color space. So the last
230
+ 'parameter is set to "0"
231
+ field.SetBorderColor("RGB", 0.7, 0.5, 0.3, 0)
232
+
233
+ 'Field.TextSize sets the font size of the field. You can also use Field.TextFont
234
+ 'to use a specific font. See the Acrobat Forms API Reference for more information
235
+ 'on various font names.
236
+ field.TextSize = CShort("12")
237
+ 'field.TextFont = "Times-Roman"
238
+
239
+ 'You can use Field.DefaultValue to set the default value of a field.
240
+ field.DefaultValue = "Enter your full name here"
241
+
242
+ 'Create a date field formatted to be "mm/dd/yyyy". The SetJavaScriptAction
243
+ 'method sets the keystoke and format properties to the proper date format
244
+ 'using JavaScript
245
+ field = acroForm.Add("Creation Date", "text", 0, 375, 680, 450, 715)
246
+ field.SetBorderColor("RGB", 0.7, 0.5, 0.3, 0)
247
+ field.TextSize = CShort("12")
248
+ field.DefaultValue = "01/01/2000"
249
+ field.SetJavaScriptAction("keystroke", "AFDate_KeystrokeEx(""mm/dd/yyyy"");")
250
+ field.SetJavaScriptAction("format", "AFDate_FormatEx(""mm/dd/yyyy"");")
251
+
252
+ 'Now add a few more fields for address, city, state, zip code. The zip code
253
+ 'field introduces a new functionality - using JavaScript to format the
254
+ 'field values.
255
+ field = acroForm.Add("Address", "text", 0, 100, 620, 450, 645)
256
+ field.SetBorderColor("RGB", 0.7, 0.5, 0.3, 0)
257
+ field.TextSize = CShort("12")
258
+ field.DefaultValue = "Enter your address here"
259
+
260
+ field = acroForm.Add("City", "text", 0, 100, 590, 345, 615)
261
+ field.SetBorderColor("RGB", 0.7, 0.5, 0.3, 0)
262
+ field.TextSize = CShort("12")
263
+ field.DefaultValue = "Enter your City"
264
+
265
+ field = acroForm.Add("State", "text", 0, 350, 590, 375, 615)
266
+ field.SetBorderColor("RGB", 0.7, 0.5, 0.3, 0)
267
+ field.TextSize = CShort("12")
268
+ field.DefaultValue = "CA"
269
+
270
+ field = acroForm.Add("Zip", "text", 0, 385, 590, 450, 615)
271
+ field.SetBorderColor("RGB", 0.7, 0.5, 0.3, 0)
272
+ field.TextSize = CShort("12")
273
+ field.DefaultValue = "99999"
274
+ field.SetJavaScriptAction("keystroke", "AFSpecial_Keystroke(0);")
275
+ field.SetJavaScriptAction("format", "AFSpecial_Format(0);")
276
+
277
+ 'To create a series of radio buttons. Create the field, then call
278
+ 'Fields.Add again to create the children
279
+ field = acroForm.Add("Radio", "radiobutton", 0, 150, 500, 165, 515)
280
+ field.SetBorderColor("RGB", 0.75, 0.55, 0.35, 0)
281
+
282
+ field = acroForm.Add("Radio", "radiobutton", 0, 180, 500, 195, 515)
283
+ field.SetBorderColor("RGB", 0.75, 0.55, 0.35, 0)
284
+
285
+ field = acroForm.Add("Radio", "radiobutton", 0, 210, 500, 225, 515)
286
+ field.SetBorderColor("RGB", 0.75, 0.55, 0.35, 0)
287
+
288
+ field = acroForm.Add("Radio", "radiobutton", 0, 240, 500, 255, 515)
289
+ field.SetBorderColor("RGB", 0.75, 0.55, 0.35, 0)
290
+
291
+ field = acroForm.Add("Radio", "radiobutton", 0, 270, 500, 285, 515)
292
+ field.SetBorderColor("RGB", 0.75, 0.55, 0.35, 0)
293
+
294
+ 'Build an array then call SetExportValues
295
+ radiobuttonArray(0) = "Red"
296
+ radiobuttonArray(1) = "Green"
297
+ radiobuttonArray(2) = "Blue"
298
+ radiobuttonArray(3) = "Yellow"
299
+ radiobuttonArray(4) = "Black"
300
+ radiobuttonArray(5) = "White"
301
+ field.SetExportValues(radiobuttonArray)
302
+
303
+ 'Create a list box. This section of code will create a list box on the
304
+ 'PDF and populate the list box with items.
305
+ field = acroForm.Add("My Combo Box", "combobox", 0, 100, 450, 380, 475)
306
+ field.SetBorderColor("RGB", 0.75, 0.55, 0.35, 0)
307
+ field.TextSize = CShort("12")
308
+
309
+ 'Now that the list box is complete, let's build two arrays that
310
+ 'will be used to populate the list box.
311
+ 'First is an array of items that will be displayed to the user
312
+ Dim arrayOfItems(4) As String
313
+ arrayOfItems(0) = "[Choose an item from the list]"
314
+ arrayOfItems(1) = "Bird"
315
+ arrayOfItems(2) = "Cat"
316
+ arrayOfItems(3) = "Dog"
317
+ arrayOfItems(4) = "Gold Fish"
318
+
319
+ 'Then the exported value that will come back in the FDF
320
+ Dim arrayOfExportValues(4) As String
321
+ arrayOfExportValues(0) = "X"
322
+ arrayOfExportValues(1) = "a"
323
+ arrayOfExportValues(2) = "b"
324
+ arrayOfExportValues(3) = "c"
325
+ arrayOfExportValues(4) = "d"
326
+
327
+ 'Next, use the PopulateListOrComboBox method to add values into the
328
+ 'combo box
329
+ field.PopulateListOrComboBox(arrayOfItems, arrayOfExportValues)
330
+
331
+ 'Now, create a new submit button for the user to click on. Set the border
332
+ 'style, the button caption, the color of the background. Field.Highlight sets
333
+ 'the property of the button to look like it was pushed in.
334
+ field = acroForm.Add("Submit Button", "button", 0, 100, 50, 150, 100)
335
+ field.BorderStyle = "beveled"
336
+ field.SetButtonCaption("N", "Submit")
337
+ field.SetBackgroundColor("G", 0.85, 0.85, 0, 0)
338
+ field.Highlight = "push"
339
+
340
+ 'Set the SubmitForm action to point to a web server.
341
+ field.SetSubmitFormAction("up", "http://your-webserver.com/cgi-bin/myscript", 0)
342
+
343
+ 'Create a reset button just in case users want to change there minds a
344
+ 'reset all the fields on the newly created PDF.
345
+ field = acroForm.Add("Reset Button", "button", 0, 175, 50, 225, 100)
346
+ field.BorderStyle = "beveled"
347
+ field.SetButtonCaption("N", "Reset")
348
+ field.SetBackgroundColor("G", 0.85, 0.85, 0, 0)
349
+ field.Highlight = "push"
350
+ 'Set the ResetForm action for the button.
351
+ field.SetResetFormAction("up", 0)
352
+
353
+ 'Update the Status box.
354
+ StatusBox.Text = "Fields have been added successfully."
355
+
356
+ 'This section converts a AVDoc to a PDDoc. Then we use PDDoc.Save to
357
+ 'save the PDF since there isn't a viewer level method to save an AVDoc.
358
+
359
+ 'These lines are commented out to provide user feedback
360
+ 'If present, no doc is visible and original form is changed
361
+ 'so it isn't obvious what the sample did, and it doesn't work
362
+ 'twice in a row.
363
+ 'It's best to have Acrobat open and visible to see form creation
364
+ '''''''''
365
+ 'Set pdDoc = avDoc.GetPDDoc
366
+ 'bOK = pdDoc.Save(1, "C:\FormsAutomation.pdf")
367
+ 'If bOK = False Then
368
+ 'MsgBox "Unable to Save the PDF file"
369
+ 'End If
370
+
371
+ ' Close the AVDoc
372
+ 'avDoc.Close (False)
373
+ '''''''''
374
+ 'End provide User Feedback
375
+
376
+ CleanUp:
377
+ 'Change the mouse pointer to display normal cursor and enable the Exit button
378
+ System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default
379
+
380
+ 'Enable the create fields button
381
+ CreateFieldsButton.Enabled = True
382
+ End Sub
383
+
384
+ Private Sub ExitButton_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles ExitButton.Click
385
+ ' End the program
386
+ End
387
+
388
+ End Sub
389
+
390
+ Private Sub FormsAutomation_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
391
+ StatusBox.Text = "Click Create Fields Button..."
392
+ End Sub
393
+ End Class
data/vba/overlay.vba ADDED
@@ -0,0 +1,40 @@
1
+ Private Function ApplyBackgroundToPDF(BasePDF As String, BackgroundPDF As String)
2
+ Dim pdDoc As Acrobat.CAcroPDDoc
3
+ Dim pdTemplate As Acrobat.CAcroPDDoc
4
+ Dim template As Variant
5
+ Dim lngPage As Long
6
+
7
+ 'Open base document
8
+ Set pdDoc = CreateObject("AcroExch.PDDoc")
9
+ pdDoc.Open BasePDF
10
+ DoEvents
11
+
12
+ 'Open background document
13
+ Set pdTemplate = CreateObject("AcroExch.PDDoc")
14
+ pdTemplate.Open BackgroundPDF
15
+ DoEvents
16
+
17
+ 'Add background document to base document
18
+ pdDoc.InsertPages pdDoc.GetNumPages - 1, pdTemplate, 0, 1, 0
19
+
20
+ 'Create a template from the inserted background document
21
+ Set template = pdDoc.GetJSObject.CreateTemplate("background", pdDoc.GetNumPages - 1)
22
+
23
+ 'Place the template as a background to all pages
24
+ For lngPage = 0 To pdDoc.GetNumPages - 2
25
+ template.Spawn lngPage, True, True
26
+ Next
27
+
28
+ 'Delete last page (used for template creation purposes only)
29
+ pdDoc.DeletePages pdDoc.GetNumPages - 1, pdDoc.GetNumPages - 1
30
+
31
+ 'Save
32
+ pdDoc.Save 1, BasePDF
33
+
34
+ 'Close & Destroy Objects
35
+ pdDoc.Close
36
+ Set pdDoc = Nothing
37
+
38
+ pdTemplate.Close
39
+ Set pdTemplate = Nothing
40
+ End Function