Sigh_Man
asked on
pass text to a field in an Acrobat pdf form
Does anyone have sample code for passing text to a field on an Adobe Acrobat pdf form?
(WinForms in VB.Net).
TIA
(WinForms in VB.Net).
TIA
Have you started any kind of code?
Here is a project that I made sometime ago with Adobe Acrobat 5 that makes a report from dates with a access database and products a pdf with header info and column info.. All string fields and paths need to be changed to match
what you need.
'FORM 1
Imports Microsoft.VisualBasic
Class frmPDFDisplay
Inherits System.Windows.Forms.Form
Private dataList As New ArrayList
#Region "Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
bFirstPage = True
Me.Height = 175
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal Disposing As Boolean)
If Disposing Then
If Not components Is Nothing Then
components.Dispose()
End If
End If
MyBase.Dispose(Disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.ICon tainer
Public ToolTip1 As System.Windows.Forms.ToolT ip
Public WithEvents CmdCancel As System.Windows.Forms.Butto n
Public WithEvents CmdOK As System.Windows.Forms.Butto n
Public WithEvents lblFinish As System.Windows.Forms.Label
Public WithEvents LblEnd As System.Windows.Forms.Label
Public WithEvents LblStart As System.Windows.Forms.Label
Public WithEvents FraDate As System.Windows.Forms.Group Box
Public WithEvents PdfRpt As AxPdfLib.AxPdf
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents dtpStartDate As System.Windows.Forms.DateT imePicker
Friend WithEvents dtpEndDate As System.Windows.Forms.DateT imePicker
Friend WithEvents ErrorDate As System.Windows.Forms.Error Provider
<System.Diagnostics.Debugg erStepThro ugh()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Cont ainer
Dim resources As System.Resources.ResourceM anager = New System.Resources.ResourceM anager(Get Type(frmPD FDisplay))
Me.ToolTip1 = New System.Windows.Forms.ToolT ip(Me.comp onents)
Me.FraDate = New System.Windows.Forms.Group Box
Me.dtpEndDate = New System.Windows.Forms.DateT imePicker
Me.dtpStartDate = New System.Windows.Forms.DateT imePicker
Me.CmdCancel = New System.Windows.Forms.Butto n
Me.CmdOK = New System.Windows.Forms.Butto n
Me.lblFinish = New System.Windows.Forms.Label
Me.LblEnd = New System.Windows.Forms.Label
Me.LblStart = New System.Windows.Forms.Label
Me.PdfRpt = New AxPdfLib.AxPdf
Me.ErrorDate = New System.Windows.Forms.Error Provider
Me.FraDate.SuspendLayout()
CType(Me.PdfRpt, System.ComponentModel.ISup portInitia lize).Begi nInit()
Me.SuspendLayout()
'
'FraDate
'
Me.FraDate.BackColor = System.Drawing.SystemColor s.Control
Me.FraDate.Controls.Add(Me .dtpEndDat e)
Me.FraDate.Controls.Add(Me .dtpStartD ate)
Me.FraDate.Controls.Add(Me .CmdCancel )
Me.FraDate.Controls.Add(Me .CmdOK)
Me.FraDate.Controls.Add(Me .lblFinish )
Me.FraDate.Controls.Add(Me .LblEnd)
Me.FraDate.Controls.Add(Me .LblStart)
Me.FraDate.Font = New System.Drawing.Font("Arial ", 8.25!, System.Drawing.FontStyle.B old, System.Drawing.GraphicsUni t.Point, CType(0, Byte))
Me.FraDate.ForeColor = System.Drawing.SystemColor s.ControlT ext
Me.FraDate.Location = New System.Drawing.Point(6, 3)
Me.FraDate.Name = "FraDate"
Me.FraDate.RightToLeft = System.Windows.Forms.Right ToLeft.No
Me.FraDate.Size = New System.Drawing.Size(475, 130)
Me.FraDate.TabIndex = 1
Me.FraDate.TabStop = False
Me.FraDate.Text = "Select Dates"
'
'dtpEndDate
'
Me.dtpEndDate.Location = New System.Drawing.Point(240, 34)
Me.dtpEndDate.Name = "dtpEndDate"
Me.dtpEndDate.TabIndex = 10
Me.dtpEndDate.Value = New Date(2001, 4, 30, 13, 49, 0, 0)
'
'dtpStartDate
'
Me.dtpStartDate.Location = New System.Drawing.Point(15, 34)
Me.dtpStartDate.Name = "dtpStartDate"
Me.dtpStartDate.TabIndex = 9
Me.dtpStartDate.Value = New Date(2001, 2, 1, 13, 49, 0, 0)
'
'CmdCancel
'
Me.CmdCancel.BackColor = System.Drawing.SystemColor s.Control
Me.CmdCancel.Cursor = System.Windows.Forms.Curso rs.Default
Me.CmdCancel.Font = New System.Drawing.Font("Arial ", 8.25!, System.Drawing.FontStyle.B old, System.Drawing.GraphicsUni t.Point, CType(0, Byte))
Me.CmdCancel.ForeColor = System.Drawing.SystemColor s.ControlT ext
Me.CmdCancel.Location = New System.Drawing.Point(237, 63)
Me.CmdCancel.Name = "CmdCancel"
Me.CmdCancel.RightToLeft = System.Windows.Forms.Right ToLeft.No
Me.CmdCancel.Size = New System.Drawing.Size(115, 25)
Me.CmdCancel.TabIndex = 3
Me.CmdCancel.Text = "&Cancel"
'
'CmdOK
'
Me.CmdOK.BackColor = System.Drawing.SystemColor s.Control
Me.CmdOK.Cursor = System.Windows.Forms.Curso rs.Default
Me.CmdOK.Font = New System.Drawing.Font("Arial ", 8.25!, System.Drawing.FontStyle.B old, System.Drawing.GraphicsUni t.Point, CType(0, Byte))
Me.CmdOK.ForeColor = System.Drawing.SystemColor s.ControlT ext
Me.CmdOK.Location = New System.Drawing.Point(87, 63)
Me.CmdOK.Name = "CmdOK"
Me.CmdOK.RightToLeft = System.Windows.Forms.Right ToLeft.No
Me.CmdOK.Size = New System.Drawing.Size(121, 25)
Me.CmdOK.TabIndex = 2
Me.CmdOK.Text = "&Ok"
'
'lblFinish
'
Me.lblFinish.BackColor = System.Drawing.SystemColor s.Control
Me.lblFinish.Cursor = System.Windows.Forms.Curso rs.Default
Me.lblFinish.Font = New System.Drawing.Font("Arial ", 8.0!, System.Drawing.FontStyle.R egular, System.Drawing.GraphicsUni t.Point, CType(0, Byte))
Me.lblFinish.ForeColor = System.Drawing.SystemColor s.ControlT ext
Me.lblFinish.Location = New System.Drawing.Point(84, 96)
Me.lblFinish.Name = "lblFinish"
Me.lblFinish.RightToLeft = System.Windows.Forms.Right ToLeft.No
Me.lblFinish.Size = New System.Drawing.Size(292, 22)
Me.lblFinish.TabIndex = 8
'
'LblEnd
'
Me.LblEnd.BackColor = System.Drawing.SystemColor s.Control
Me.LblEnd.Cursor = System.Windows.Forms.Curso rs.Default
Me.LblEnd.Font = New System.Drawing.Font("Arial ", 9.75!, System.Drawing.FontStyle.B old, System.Drawing.GraphicsUni t.Point, CType(0, Byte))
Me.LblEnd.ForeColor = System.Drawing.SystemColor s.ControlT ext
Me.LblEnd.Location = New System.Drawing.Point(231, 15)
Me.LblEnd.Name = "LblEnd"
Me.LblEnd.RightToLeft = System.Windows.Forms.Right ToLeft.No
Me.LblEnd.Size = New System.Drawing.Size(178, 13)
Me.LblEnd.TabIndex = 7
Me.LblEnd.Text = "End Date:"
'
'LblStart
'
Me.LblStart.BackColor = System.Drawing.SystemColor s.Control
Me.LblStart.Cursor = System.Windows.Forms.Curso rs.Default
Me.LblStart.Font = New System.Drawing.Font("Arial ", 9.75!, System.Drawing.FontStyle.B old, System.Drawing.GraphicsUni t.Point, CType(0, Byte))
Me.LblStart.ForeColor = System.Drawing.SystemColor s.ControlT ext
Me.LblStart.Location = New System.Drawing.Point(9, 15)
Me.LblStart.Name = "LblStart"
Me.LblStart.RightToLeft = System.Windows.Forms.Right ToLeft.No
Me.LblStart.Size = New System.Drawing.Size(178, 13)
Me.LblStart.TabIndex = 6
Me.LblStart.Text = "Start Date:"
'
'PdfRpt
'
Me.PdfRpt.Enabled = True
Me.PdfRpt.Location = New System.Drawing.Point(9, 159)
Me.PdfRpt.Name = "PdfRpt"
Me.PdfRpt.OcxState = CType(resources.GetObject( "PdfRpt.Oc xState"), System.Windows.Forms.AxHos t.State)
Me.PdfRpt.Size = New System.Drawing.Size(100, 50)
Me.PdfRpt.TabIndex = 0
Me.PdfRpt.Visible = False
'
'ErrorDate
'
Me.ErrorDate.ContainerCont rol = Me
'
'frmPDFDisplay
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.BackColor = System.Drawing.SystemColor s.Control
Me.ClientSize = New System.Drawing.Size(487, 208)
Me.Controls.Add(Me.FraDate )
Me.Controls.Add(Me.PdfRpt)
Me.Cursor = System.Windows.Forms.Curso rs.Default
Me.Font = New System.Drawing.Font("Arial ", 8.0!, System.Drawing.FontStyle.R egular, System.Drawing.GraphicsUni t.Point, CType(0, Byte))
Me.Location = New System.Drawing.Point(4, 23)
Me.Name = "frmPDFDisplay"
Me.RightToLeft = System.Windows.Forms.Right ToLeft.No
Me.Text = "View PDF"
Me.FraDate.ResumeLayout(Fa lse)
CType(Me.PdfRpt, System.ComponentModel.ISup portInitia lize).EndI nit()
Me.ResumeLayout(False)
End Sub
#End Region
#Region "Click Events"
Private Sub CmdCancel_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles CmdCancel.Click
End
End Sub
Private Sub CmdOK_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles CmdOK.Click
sDBStartDate = dtpStartDate.Value.ToShort DateString
sDBEndDate = dtpEndDate.Value.ToShortDa teString
InitializeData()
CheckFiles()
FdfAcX = New FDFACXLib.FdfApp
FdfDoc = FdfAcX.FDFCreate
Me.lblFinish.Text = "Moving Data from " & sDBName & " per examier ...please wait"
Export_IDR_PDF()
ShowPDFView()
End Sub
#End Region
#Region "Pick Dates Controls"
Private Sub dtpStartDate_ValueChanged( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dtpStartDate.ValueChanged
If dtpStartDate.Value > Now Then
ErrorDate.SetError(dtpStar tDate, "Start Date Must be less than or equal to Todays Date")
bErrorDate = True
Else
ErrorDate.SetError(dtpStar tDate, "")
bErrorDate = False
End If
End Sub
Private Sub dtpStartDate_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEv entArgs) Handles dtpStartDate.KeyUp
If e.KeyCode = 9 Then
e.Handled = True
Me.dtpEndDate.Focus()
End If
End Sub
Private Sub dtpStartDate_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dtpStartDate.Leave
dtpStartDate.Format = DateTimePickerFormat.Custo m
dtpStartDate.CustomFormat = "MM'/'dd'/'yyyy" '"yyyy'-'MM'-'dd" 'Change format for SQL SERVER Dates
sDBStartDate = dtpStartDate.Text
dtpStartDate.Format = DateTimePickerFormat.Long
End Sub
Private Sub dtpEndDate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dtpEndDate.Click
If dtpEndDate.Value < dtpStartDate.Value Or dtpEndDate.Value > Now Then
ErrorDate.SetError(dtpEndD ate, "End Date Must be greater than or equal to Start Date or before todays date")
bErrorDate = True
Else
ErrorDate.SetError(dtpEndD ate, "")
bErrorDate = False
End If
End Sub
Private Sub dtpEndDate_ValueChanged(By Val sender As System.Object, ByVal e As System.EventArgs) Handles dtpEndDate.ValueChanged
If dtpEndDate.Value < dtpStartDate.Value Or dtpEndDate.Value > Now Then
ErrorDate.SetError(dtpEndD ate, "End Date Must be greater than or equal to Start Date or before todays date")
bErrorDate = True
Else
ErrorDate.SetError(dtpEndD ate, "")
bErrorDate = False
End If
End Sub
Private Sub dtpEndDate_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dtpEndDate.Leave
dtpEndDate.Format = DateTimePickerFormat.Custo m
dtpEndDate.CustomFormat = "MM'/'dd'/'yyyy" '"yyyy'-'MM'-'dd" 'Change format for SQL SERVER Dates
sDBEndDate = dtpEndDate.Text
dtpEndDate.Format = DateTimePickerFormat.Long
End Sub
#End Region
Private Sub InitializeData()
Cursor.Current = Cursors.WaitCursor
sDBName = "TaxTest.mdb" '<---- A standard access database
sTableName = "Tax"
OpenDBADOConnection()
Con = New OleDb.OleDbConnection("Pro vider=Micr osoft.Jet. OLEDB.4.0; Data Source=" & sDBName & ";password=" & sDBPass & ";")
sSql = ""
sSql = "SELECT *, as_of_date FROM " & sTableName & " "
sSql += "WHERE as_of_date BETWEEN #" & Trim(sDBStartDate) & "# And #" & Trim(sDBEndDate) & "# "
sSql += "ORDER BY as_of_date"
Try
ADOAdapter = New OleDb.OleDbDataAdapter(sSq l, Con) 'FOR ADO Access database
ADOAdapter.Fill(DS)
Catch Exp As Data.OleDb.OleDbException
MsgBox(Exp.Message, MsgBoxStyle.Critical, "Load Report Error")
Catch Exp As Exception
MsgBox(Exp.Message, MsgBoxStyle.Critical, "General Error")
End Try
Cursor.Current = Cursors.Default
End Sub
Private Sub LoadArrayList()
Dim i As Short
Dim z As Short
For i = 0 To DS.Tables(0).Rows.Count - 1
' Check to see if row is flagged as deleted.
If Not DS.Tables(0).Rows(i).RowSt ate = DataRowState.Deleted Then
' Get the product name for each record.
For z = 0 To DS.Tables(0).Columns.Count - 1
dataList.Add(DS.Tables(0). Rows(i)(z) .ToString( ))
Next
End If
Next i
End Sub
Private Sub frmPDFDisplay_Closed(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Closed
CheckFiles()
End Sub
Private Sub ShowPDFView()
SavePDF()
FraDate.Visible = False
'show PDF file here
With Me
.PdfRpt.Visible = True
.PdfRpt.setShowToolbar((Tr ue))
.PdfRpt.LoadFile(sPDFPath)
Cursor.Current = Cursors.Default
.Show()
End With
Me.WindowState = FormWindowState.Maximized
End Sub
Private Sub frmPDFDisplay_Resize(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Resize
PdfRpt.SetBounds(0, 0, Me.ClientRectangle.Width - 15, Me.ClientRectangle.Height - 15)
End Sub
Public Sub SavePDF()
Cursor.Current = Cursors.WaitCursor
sPDFPath = sAppPath & "Acrobat\IDR_ADJ.PDF"
lblFinish.Text = "Creating Summary Reports ... Please wait"
FdfDoc.FDFSaveToFile(sFDFP ath)
FdfDoc.FDFClose()
FdfDoc = Nothing
FdfAcX = Nothing
AcroExchAVDoc = CreateObject("AcroExch.AVD oc")
bOK = AcroExchAVDoc.Open(sFDFPat h, "")
AcroExchPDDoc = AcroExchAVDoc.GetPDDoc
' bOK = AcroExchPDDoc.Save(Acrobat .__MIDL___ MIDL_itf_a crobat_000 0_0005.PDS aveFull, sPDFPath)
bOK = AcroExchPDDoc.Save(1, sPDFPath)
AcroExchPDDoc.Close()
AcroExchAVDoc.Close(True)
Cursor.Current = Cursors.Default
End Sub
End Class
'MODULE
Imports PDFCode
Imports Microsoft.VisualBasic
Module modPDFCode
#Region " MY Global Vars "
'********* database Var's ************
Public sSql As String
Public sTableName As String
Public iCount As Short
Public myDataRow As DataRow
Public DS As New DataSet
Public ADOAdapter As OleDb.OleDbDataAdapter '(ADO)
'**** Server Connection Vars *********
Public sDBServer As String '<--- Server Name
Public sUSERid As String '<--- User Id
Public sDBName As String '<--- Database Name
Public sDBPass As String '<--- Password
Public Con As OleDb.OleDbConnection '<--- for Access
'******* Standard Var's *************
Public sAppPath As String = Application.StartupPath
Const sMasterPath As String = "C:\Visual Studio Projects\PDFcode\MasterTem p\"
Public bLogin As Boolean
Public sDBStartDate As String 'Start Date
Public sDBEndDate As String 'End Date
Public bErrorDate As Boolean 'Error Checker
'******** Common Paths ***********
Public sPath As String
Public sWorkPath As String
Public sSysPath As String
Public sZipPath As String
Public sDBasePath As String 'directory where customer data is."
'****** AcroBat Objects ********
'// You have to have these components in directory windows/system32---FDFACX. DLL, FDFTK.DLL
'// You have to register (e.i.- regsvr32 d:\windows\system32\FDFACX .DLL)
'// Files to reference FDFACX.DLL, PDF.OCX, ACROBAT.TLB(30kb)
Public bOK As Boolean
Public AcroApp As Acrobat.CAcroApp
Public AcroExchAVDoc As Acrobat.CAcroAVDoc
Public AcroExchPDDoc As Acrobat.CAcroPDDoc
Public FdfAcX As FDFACXLib.FdfApp
Public FdfDoc As FDFACXLib.FdfDoc
Public sFDFPath As String
Public sPDFPath As String
'**** Used in PDF Reports ******
Public sReportTitle As String
Public sActionField As String
Public sFieldHeader(4) As String
Public sEntityName As String
Public iPage As Short
Public bFirstPage As Boolean
Public bHit As Boolean
Public sField As String
Public fso As Scripting.FileSystemObject
#End Region
#Region " MY Server Connections "
Public Sub OpenDBADOConnection()
Try
Con = New OleDb.OleDbConnection("Pro vider=Micr osoft.Jet. OLEDB.4.0; Data Source=" & sDBName & ";password=" & sDBPass & ";")
Con.Open()
Con.Close()
Catch Ex As Exception
MsgBox("Exception: " & Ex.Message & " " & Ex.ToString, MsgBoxStyle.Critical)
Cursor.Current = Cursors.Default
End Try
End Sub
#End Region
Public Sub IDR_Headers()
Dim sdate As Date
'Var.. for the report headers
sEntityName = DS.Tables(0).Rows(0)(1).To String() 'RS.Fields(1).Value
sReportTitle = "Individual Document Requests"
sFieldHeader(0) = "IDR Number"
sFieldHeader(1) = "Issue"
sFieldHeader(2) = "Requested by/"
sFieldHeader(3) = "Initiated by"
sFieldHeader(4) = "Request Date"
sActionField = "Not Imported"
With FdfDoc
' print the header or Add new page after 21 entries
If bHit Then
.FDFAddTemplate(True, sMasterPath & "idr_adj.pdf", "idr_adj_pg", True)
bHit = False
iPage += 1
.FDFSetValue("page", CStr(iPage), True)
.FDFSetValue("adjustment_e ntity_nm", sEntityName, False)
.FDFSetValue("Title", sReportTitle, False)
.FDFSetValue("IDR_Issue_nu m", sFieldHeader(0), False)
.FDFSetValue("Issue", sFieldHeader(1), False)
.FDFSetValue("Pro_Req_by", sFieldHeader(2), False)
.FDFSetValue("Initiated_by ", sFieldHeader(3), False)
.FDFSetValue("Issue_Req_da te", sFieldHeader(4), False)
.FDFSetValue("Action", sActionField, False)
sdate = Now.ToShortDateString
.FDFSetValue("as_of_date", sdate, False)
iCount = 1
End If
End With
End Sub
Public Sub IDR_Main(ByVal i As Integer)
Dim sFieldName As String
With FdfDoc
'Main body of the report
Try
sField = IIf(DS.Tables(0).Rows(i)(" idr_reques t_prefix_t xt").ToStr ing() <> "", DS.Tables(0).Rows(i)("idr_ request_pr efix_txt") .ToString( ) & "-", " ")
sFieldName = DS.Tables(0).Rows(i)("idr_ request_nu m").ToStri ng
sFieldName = sFieldName.ToString.Format ("0000")
sField = sField & IIf(sFieldName <> "", sFieldName, " ")
sField = Space(20 - Len(sField)) & Trim(sField)
Catch e As InvalidCastException
Throw New StrongTypingException("Can not get value because it is DBNull.", e)
End Try
.FDFSetValue("field1." & (iCount), sField, False)
.FDFSetValue("field2." & (iCount), IIf(DS.Tables(0).Rows(i)(" idr_subjec t_nm").ToS tring <> "", DS.Tables(0).Rows(i)("idr_ subject_nm ").ToStrin g, " "), False)
.FDFSetValue("field3." & (iCount), IIf(DS.Tables(0).Rows(i)(" idr_reques ter_nm").T oString <> "", DS.Tables(0).Rows(i)("idr_ requester_ nm").ToStr ing, " "), False)
.FDFSetValue("field4." & (iCount), IIf(DS.Tables(0).Rows(i)(" idr_initia tor_nm").T oString <> "", DS.Tables(0).Rows(i)("idr_ initiator_ nm").ToStr ing, " "), False)
Try
.FDFSetValue("field5." & (iCount), IIf(CStr(DS.Tables(0).Rows (i)("reque st_dt").To String) <> "", CStr(DS.Tables(0).Rows(i)( "request_d t").ToStri ng), " "), False)
Catch e As InvalidCastException
.FDFSetValue("field5." & (iCount), " ", False)
End Try
iCount += 1
End With
End Sub
Public Sub Export_IDR_PDF()
Cursor.Current = Cursors.WaitCursor
Dim i As Short
If bFirstPage Then
iCount = 1
iPage = 0
bHit = True
bFirstPage = False
IDR_Headers()
End If
Application.DoEvents()
For i = 0 To DS.Tables(0).Rows.Count - 1
' Check to see if row is flagged as deleted.
If Not DS.Tables(0).Rows(i).RowSt ate = DataRowState.Deleted Then
If IsDBNull(DS.Tables(0).Rows (i)("idr_r equester_n m").ToStri ng) Then
Else
If iCount > 21 Then
bHit = True
IDR_Headers()
End If
IDR_Main(i)
End If
End If
Next i
End Sub
Public Sub CheckFiles()
Dim sPDFTempPath As String
fso = New Scripting.FileSystemObject
sAppPath = CurDir()
If sAppPath.Substring(sAppPat h.Length - 1, 1) <> "\" Then
sAppPath += "\"
End If
sFDFPath = sAppPath & "WorkFDF.fdf"
sPDFTempPath = sMasterPath & "temp.pdf"
'Delete all old temp files
With fso
If .FileExists(sPDFTempPath) Then .DeleteFile((sPDFTempPath) )
If .FileExists(sFDFPath) Then .DeleteFile((sFDFPath))
End With
'fso only looks for that one file, Dir looks for all files then deletes them
' If Dir(sWorkPath & "*.id") <> "" Then Kill (sWorkPath & "*.id")
' If Dir(sWorkPath & "*.xml") <> "" Then Kill (sWorkPath & "*.xml")
' If Dir(sWorkPath & "*.zip") <> "" Then Kill (sWorkPath & "*.zip")
End Sub
End Module
what you need.
'FORM 1
Imports Microsoft.VisualBasic
Class frmPDFDisplay
Inherits System.Windows.Forms.Form
Private dataList As New ArrayList
#Region "Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
bFirstPage = True
Me.Height = 175
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal Disposing As Boolean)
If Disposing Then
If Not components Is Nothing Then
components.Dispose()
End If
End If
MyBase.Dispose(Disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.ICon
Public ToolTip1 As System.Windows.Forms.ToolT
Public WithEvents CmdCancel As System.Windows.Forms.Butto
Public WithEvents CmdOK As System.Windows.Forms.Butto
Public WithEvents lblFinish As System.Windows.Forms.Label
Public WithEvents LblEnd As System.Windows.Forms.Label
Public WithEvents LblStart As System.Windows.Forms.Label
Public WithEvents FraDate As System.Windows.Forms.Group
Public WithEvents PdfRpt As AxPdfLib.AxPdf
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents dtpStartDate As System.Windows.Forms.DateT
Friend WithEvents dtpEndDate As System.Windows.Forms.DateT
Friend WithEvents ErrorDate As System.Windows.Forms.Error
<System.Diagnostics.Debugg
Me.components = New System.ComponentModel.Cont
Dim resources As System.Resources.ResourceM
Me.ToolTip1 = New System.Windows.Forms.ToolT
Me.FraDate = New System.Windows.Forms.Group
Me.dtpEndDate = New System.Windows.Forms.DateT
Me.dtpStartDate = New System.Windows.Forms.DateT
Me.CmdCancel = New System.Windows.Forms.Butto
Me.CmdOK = New System.Windows.Forms.Butto
Me.lblFinish = New System.Windows.Forms.Label
Me.LblEnd = New System.Windows.Forms.Label
Me.LblStart = New System.Windows.Forms.Label
Me.PdfRpt = New AxPdfLib.AxPdf
Me.ErrorDate = New System.Windows.Forms.Error
Me.FraDate.SuspendLayout()
CType(Me.PdfRpt, System.ComponentModel.ISup
Me.SuspendLayout()
'
'FraDate
'
Me.FraDate.BackColor = System.Drawing.SystemColor
Me.FraDate.Controls.Add(Me
Me.FraDate.Controls.Add(Me
Me.FraDate.Controls.Add(Me
Me.FraDate.Controls.Add(Me
Me.FraDate.Controls.Add(Me
Me.FraDate.Controls.Add(Me
Me.FraDate.Controls.Add(Me
Me.FraDate.Font = New System.Drawing.Font("Arial
Me.FraDate.ForeColor = System.Drawing.SystemColor
Me.FraDate.Location = New System.Drawing.Point(6, 3)
Me.FraDate.Name = "FraDate"
Me.FraDate.RightToLeft = System.Windows.Forms.Right
Me.FraDate.Size = New System.Drawing.Size(475, 130)
Me.FraDate.TabIndex = 1
Me.FraDate.TabStop = False
Me.FraDate.Text = "Select Dates"
'
'dtpEndDate
'
Me.dtpEndDate.Location = New System.Drawing.Point(240, 34)
Me.dtpEndDate.Name = "dtpEndDate"
Me.dtpEndDate.TabIndex = 10
Me.dtpEndDate.Value = New Date(2001, 4, 30, 13, 49, 0, 0)
'
'dtpStartDate
'
Me.dtpStartDate.Location = New System.Drawing.Point(15, 34)
Me.dtpStartDate.Name = "dtpStartDate"
Me.dtpStartDate.TabIndex = 9
Me.dtpStartDate.Value = New Date(2001, 2, 1, 13, 49, 0, 0)
'
'CmdCancel
'
Me.CmdCancel.BackColor = System.Drawing.SystemColor
Me.CmdCancel.Cursor = System.Windows.Forms.Curso
Me.CmdCancel.Font = New System.Drawing.Font("Arial
Me.CmdCancel.ForeColor = System.Drawing.SystemColor
Me.CmdCancel.Location = New System.Drawing.Point(237, 63)
Me.CmdCancel.Name = "CmdCancel"
Me.CmdCancel.RightToLeft = System.Windows.Forms.Right
Me.CmdCancel.Size = New System.Drawing.Size(115, 25)
Me.CmdCancel.TabIndex = 3
Me.CmdCancel.Text = "&Cancel"
'
'CmdOK
'
Me.CmdOK.BackColor = System.Drawing.SystemColor
Me.CmdOK.Cursor = System.Windows.Forms.Curso
Me.CmdOK.Font = New System.Drawing.Font("Arial
Me.CmdOK.ForeColor = System.Drawing.SystemColor
Me.CmdOK.Location = New System.Drawing.Point(87, 63)
Me.CmdOK.Name = "CmdOK"
Me.CmdOK.RightToLeft = System.Windows.Forms.Right
Me.CmdOK.Size = New System.Drawing.Size(121, 25)
Me.CmdOK.TabIndex = 2
Me.CmdOK.Text = "&Ok"
'
'lblFinish
'
Me.lblFinish.BackColor = System.Drawing.SystemColor
Me.lblFinish.Cursor = System.Windows.Forms.Curso
Me.lblFinish.Font = New System.Drawing.Font("Arial
Me.lblFinish.ForeColor = System.Drawing.SystemColor
Me.lblFinish.Location = New System.Drawing.Point(84, 96)
Me.lblFinish.Name = "lblFinish"
Me.lblFinish.RightToLeft = System.Windows.Forms.Right
Me.lblFinish.Size = New System.Drawing.Size(292, 22)
Me.lblFinish.TabIndex = 8
'
'LblEnd
'
Me.LblEnd.BackColor = System.Drawing.SystemColor
Me.LblEnd.Cursor = System.Windows.Forms.Curso
Me.LblEnd.Font = New System.Drawing.Font("Arial
Me.LblEnd.ForeColor = System.Drawing.SystemColor
Me.LblEnd.Location = New System.Drawing.Point(231, 15)
Me.LblEnd.Name = "LblEnd"
Me.LblEnd.RightToLeft = System.Windows.Forms.Right
Me.LblEnd.Size = New System.Drawing.Size(178, 13)
Me.LblEnd.TabIndex = 7
Me.LblEnd.Text = "End Date:"
'
'LblStart
'
Me.LblStart.BackColor = System.Drawing.SystemColor
Me.LblStart.Cursor = System.Windows.Forms.Curso
Me.LblStart.Font = New System.Drawing.Font("Arial
Me.LblStart.ForeColor = System.Drawing.SystemColor
Me.LblStart.Location = New System.Drawing.Point(9, 15)
Me.LblStart.Name = "LblStart"
Me.LblStart.RightToLeft = System.Windows.Forms.Right
Me.LblStart.Size = New System.Drawing.Size(178, 13)
Me.LblStart.TabIndex = 6
Me.LblStart.Text = "Start Date:"
'
'PdfRpt
'
Me.PdfRpt.Enabled = True
Me.PdfRpt.Location = New System.Drawing.Point(9, 159)
Me.PdfRpt.Name = "PdfRpt"
Me.PdfRpt.OcxState = CType(resources.GetObject(
Me.PdfRpt.Size = New System.Drawing.Size(100, 50)
Me.PdfRpt.TabIndex = 0
Me.PdfRpt.Visible = False
'
'ErrorDate
'
Me.ErrorDate.ContainerCont
'
'frmPDFDisplay
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.BackColor = System.Drawing.SystemColor
Me.ClientSize = New System.Drawing.Size(487, 208)
Me.Controls.Add(Me.FraDate
Me.Controls.Add(Me.PdfRpt)
Me.Cursor = System.Windows.Forms.Curso
Me.Font = New System.Drawing.Font("Arial
Me.Location = New System.Drawing.Point(4, 23)
Me.Name = "frmPDFDisplay"
Me.RightToLeft = System.Windows.Forms.Right
Me.Text = "View PDF"
Me.FraDate.ResumeLayout(Fa
CType(Me.PdfRpt, System.ComponentModel.ISup
Me.ResumeLayout(False)
End Sub
#End Region
#Region "Click Events"
Private Sub CmdCancel_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles CmdCancel.Click
End
End Sub
Private Sub CmdOK_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles CmdOK.Click
sDBStartDate = dtpStartDate.Value.ToShort
sDBEndDate = dtpEndDate.Value.ToShortDa
InitializeData()
CheckFiles()
FdfAcX = New FDFACXLib.FdfApp
FdfDoc = FdfAcX.FDFCreate
Me.lblFinish.Text = "Moving Data from " & sDBName & " per examier ...please wait"
Export_IDR_PDF()
ShowPDFView()
End Sub
#End Region
#Region "Pick Dates Controls"
Private Sub dtpStartDate_ValueChanged(
If dtpStartDate.Value > Now Then
ErrorDate.SetError(dtpStar
bErrorDate = True
Else
ErrorDate.SetError(dtpStar
bErrorDate = False
End If
End Sub
Private Sub dtpStartDate_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEv
If e.KeyCode = 9 Then
e.Handled = True
Me.dtpEndDate.Focus()
End If
End Sub
Private Sub dtpStartDate_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dtpStartDate.Leave
dtpStartDate.Format = DateTimePickerFormat.Custo
dtpStartDate.CustomFormat = "MM'/'dd'/'yyyy" '"yyyy'-'MM'-'dd" 'Change format for SQL SERVER Dates
sDBStartDate = dtpStartDate.Text
dtpStartDate.Format = DateTimePickerFormat.Long
End Sub
Private Sub dtpEndDate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dtpEndDate.Click
If dtpEndDate.Value < dtpStartDate.Value Or dtpEndDate.Value > Now Then
ErrorDate.SetError(dtpEndD
bErrorDate = True
Else
ErrorDate.SetError(dtpEndD
bErrorDate = False
End If
End Sub
Private Sub dtpEndDate_ValueChanged(By
If dtpEndDate.Value < dtpStartDate.Value Or dtpEndDate.Value > Now Then
ErrorDate.SetError(dtpEndD
bErrorDate = True
Else
ErrorDate.SetError(dtpEndD
bErrorDate = False
End If
End Sub
Private Sub dtpEndDate_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dtpEndDate.Leave
dtpEndDate.Format = DateTimePickerFormat.Custo
dtpEndDate.CustomFormat = "MM'/'dd'/'yyyy" '"yyyy'-'MM'-'dd" 'Change format for SQL SERVER Dates
sDBEndDate = dtpEndDate.Text
dtpEndDate.Format = DateTimePickerFormat.Long
End Sub
#End Region
Private Sub InitializeData()
Cursor.Current = Cursors.WaitCursor
sDBName = "TaxTest.mdb" '<---- A standard access database
sTableName = "Tax"
OpenDBADOConnection()
Con = New OleDb.OleDbConnection("Pro
sSql = ""
sSql = "SELECT *, as_of_date FROM " & sTableName & " "
sSql += "WHERE as_of_date BETWEEN #" & Trim(sDBStartDate) & "# And #" & Trim(sDBEndDate) & "# "
sSql += "ORDER BY as_of_date"
Try
ADOAdapter = New OleDb.OleDbDataAdapter(sSq
ADOAdapter.Fill(DS)
Catch Exp As Data.OleDb.OleDbException
MsgBox(Exp.Message, MsgBoxStyle.Critical, "Load Report Error")
Catch Exp As Exception
MsgBox(Exp.Message, MsgBoxStyle.Critical, "General Error")
End Try
Cursor.Current = Cursors.Default
End Sub
Private Sub LoadArrayList()
Dim i As Short
Dim z As Short
For i = 0 To DS.Tables(0).Rows.Count - 1
' Check to see if row is flagged as deleted.
If Not DS.Tables(0).Rows(i).RowSt
' Get the product name for each record.
For z = 0 To DS.Tables(0).Columns.Count
dataList.Add(DS.Tables(0).
Next
End If
Next i
End Sub
Private Sub frmPDFDisplay_Closed(ByVal
CheckFiles()
End Sub
Private Sub ShowPDFView()
SavePDF()
FraDate.Visible = False
'show PDF file here
With Me
.PdfRpt.Visible = True
.PdfRpt.setShowToolbar((Tr
.PdfRpt.LoadFile(sPDFPath)
Cursor.Current = Cursors.Default
.Show()
End With
Me.WindowState = FormWindowState.Maximized
End Sub
Private Sub frmPDFDisplay_Resize(ByVal
PdfRpt.SetBounds(0, 0, Me.ClientRectangle.Width - 15, Me.ClientRectangle.Height - 15)
End Sub
Public Sub SavePDF()
Cursor.Current = Cursors.WaitCursor
sPDFPath = sAppPath & "Acrobat\IDR_ADJ.PDF"
lblFinish.Text = "Creating Summary Reports ... Please wait"
FdfDoc.FDFSaveToFile(sFDFP
FdfDoc.FDFClose()
FdfDoc = Nothing
FdfAcX = Nothing
AcroExchAVDoc = CreateObject("AcroExch.AVD
bOK = AcroExchAVDoc.Open(sFDFPat
AcroExchPDDoc = AcroExchAVDoc.GetPDDoc
' bOK = AcroExchPDDoc.Save(Acrobat
bOK = AcroExchPDDoc.Save(1, sPDFPath)
AcroExchPDDoc.Close()
AcroExchAVDoc.Close(True)
Cursor.Current = Cursors.Default
End Sub
End Class
'MODULE
Imports PDFCode
Imports Microsoft.VisualBasic
Module modPDFCode
#Region " MY Global Vars "
'********* database Var's ************
Public sSql As String
Public sTableName As String
Public iCount As Short
Public myDataRow As DataRow
Public DS As New DataSet
Public ADOAdapter As OleDb.OleDbDataAdapter '(ADO)
'**** Server Connection Vars *********
Public sDBServer As String '<--- Server Name
Public sUSERid As String '<--- User Id
Public sDBName As String '<--- Database Name
Public sDBPass As String '<--- Password
Public Con As OleDb.OleDbConnection '<--- for Access
'******* Standard Var's *************
Public sAppPath As String = Application.StartupPath
Const sMasterPath As String = "C:\Visual Studio Projects\PDFcode\MasterTem
Public bLogin As Boolean
Public sDBStartDate As String 'Start Date
Public sDBEndDate As String 'End Date
Public bErrorDate As Boolean 'Error Checker
'******** Common Paths ***********
Public sPath As String
Public sWorkPath As String
Public sSysPath As String
Public sZipPath As String
Public sDBasePath As String 'directory where customer data is."
'****** AcroBat Objects ********
'// You have to have these components in directory windows/system32---FDFACX.
'// You have to register (e.i.- regsvr32 d:\windows\system32\FDFACX
'// Files to reference FDFACX.DLL, PDF.OCX, ACROBAT.TLB(30kb)
Public bOK As Boolean
Public AcroApp As Acrobat.CAcroApp
Public AcroExchAVDoc As Acrobat.CAcroAVDoc
Public AcroExchPDDoc As Acrobat.CAcroPDDoc
Public FdfAcX As FDFACXLib.FdfApp
Public FdfDoc As FDFACXLib.FdfDoc
Public sFDFPath As String
Public sPDFPath As String
'**** Used in PDF Reports ******
Public sReportTitle As String
Public sActionField As String
Public sFieldHeader(4) As String
Public sEntityName As String
Public iPage As Short
Public bFirstPage As Boolean
Public bHit As Boolean
Public sField As String
Public fso As Scripting.FileSystemObject
#End Region
#Region " MY Server Connections "
Public Sub OpenDBADOConnection()
Try
Con = New OleDb.OleDbConnection("Pro
Con.Open()
Con.Close()
Catch Ex As Exception
MsgBox("Exception: " & Ex.Message & " " & Ex.ToString, MsgBoxStyle.Critical)
Cursor.Current = Cursors.Default
End Try
End Sub
#End Region
Public Sub IDR_Headers()
Dim sdate As Date
'Var.. for the report headers
sEntityName = DS.Tables(0).Rows(0)(1).To
sReportTitle = "Individual Document Requests"
sFieldHeader(0) = "IDR Number"
sFieldHeader(1) = "Issue"
sFieldHeader(2) = "Requested by/"
sFieldHeader(3) = "Initiated by"
sFieldHeader(4) = "Request Date"
sActionField = "Not Imported"
With FdfDoc
' print the header or Add new page after 21 entries
If bHit Then
.FDFAddTemplate(True, sMasterPath & "idr_adj.pdf", "idr_adj_pg", True)
bHit = False
iPage += 1
.FDFSetValue("page", CStr(iPage), True)
.FDFSetValue("adjustment_e
.FDFSetValue("Title", sReportTitle, False)
.FDFSetValue("IDR_Issue_nu
.FDFSetValue("Issue", sFieldHeader(1), False)
.FDFSetValue("Pro_Req_by",
.FDFSetValue("Initiated_by
.FDFSetValue("Issue_Req_da
.FDFSetValue("Action", sActionField, False)
sdate = Now.ToShortDateString
.FDFSetValue("as_of_date",
iCount = 1
End If
End With
End Sub
Public Sub IDR_Main(ByVal i As Integer)
Dim sFieldName As String
With FdfDoc
'Main body of the report
Try
sField = IIf(DS.Tables(0).Rows(i)("
sFieldName = DS.Tables(0).Rows(i)("idr_
sFieldName = sFieldName.ToString.Format
sField = sField & IIf(sFieldName <> "", sFieldName, " ")
sField = Space(20 - Len(sField)) & Trim(sField)
Catch e As InvalidCastException
Throw New StrongTypingException("Can
End Try
.FDFSetValue("field1." & (iCount), sField, False)
.FDFSetValue("field2." & (iCount), IIf(DS.Tables(0).Rows(i)("
.FDFSetValue("field3." & (iCount), IIf(DS.Tables(0).Rows(i)("
.FDFSetValue("field4." & (iCount), IIf(DS.Tables(0).Rows(i)("
Try
.FDFSetValue("field5." & (iCount), IIf(CStr(DS.Tables(0).Rows
Catch e As InvalidCastException
.FDFSetValue("field5." & (iCount), " ", False)
End Try
iCount += 1
End With
End Sub
Public Sub Export_IDR_PDF()
Cursor.Current = Cursors.WaitCursor
Dim i As Short
If bFirstPage Then
iCount = 1
iPage = 0
bHit = True
bFirstPage = False
IDR_Headers()
End If
Application.DoEvents()
For i = 0 To DS.Tables(0).Rows.Count - 1
' Check to see if row is flagged as deleted.
If Not DS.Tables(0).Rows(i).RowSt
If IsDBNull(DS.Tables(0).Rows
Else
If iCount > 21 Then
bHit = True
IDR_Headers()
End If
IDR_Main(i)
End If
End If
Next i
End Sub
Public Sub CheckFiles()
Dim sPDFTempPath As String
fso = New Scripting.FileSystemObject
sAppPath = CurDir()
If sAppPath.Substring(sAppPat
sAppPath += "\"
End If
sFDFPath = sAppPath & "WorkFDF.fdf"
sPDFTempPath = sMasterPath & "temp.pdf"
'Delete all old temp files
With fso
If .FileExists(sPDFTempPath) Then .DeleteFile((sPDFTempPath)
If .FileExists(sFDFPath) Then .DeleteFile((sFDFPath))
End With
'fso only looks for that one file, Dir looks for all files then deletes them
' If Dir(sWorkPath & "*.id") <> "" Then Kill (sWorkPath & "*.id")
' If Dir(sWorkPath & "*.xml") <> "" Then Kill (sWorkPath & "*.xml")
' If Dir(sWorkPath & "*.zip") <> "" Then Kill (sWorkPath & "*.zip")
End Sub
End Module
ASKER
No I didn't have any code to begin with. I wanted some code to do the following:
1. Open Acrobat application
2. Load a certain form (this can be hard-coded for now; I will deal with forms selection later)
3. (For example) Insert the word "SMITH" into the SURNAME field contained on the Acrobat form that it just opened.
Formatting and cosmetic changes (eg font size etc) will come later - what I need at the moment is the basics outlined above. I have to disappear shortly but I will try the code later in the day.
If you could somehow highlight the relevant parts of your code required to perform the above steps that would be excellent, but if not - no problem!
Thanks again...
1. Open Acrobat application
2. Load a certain form (this can be hard-coded for now; I will deal with forms selection later)
3. (For example) Insert the word "SMITH" into the SURNAME field contained on the Acrobat form that it just opened.
Formatting and cosmetic changes (eg font size etc) will come later - what I need at the moment is the basics outlined above. I have to disappear shortly but I will try the code later in the day.
If you could somehow highlight the relevant parts of your code required to perform the above steps that would be excellent, but if not - no problem!
Thanks again...
ASKER
.....the form to be opened is a form already created by someone, so all I need to do is access the form and update the relevant field with the relevant info.
If you have a sample of the form you are working with would help.
I can cut up the code tomorrow as an example.
I can cut up the code tomorrow as an example.
ASKER
As an example:
www.irs.gov/pub/irs-pdf/fw9.pdf
How would you open up Acrobat and insert the name "John Smith" into the name field at the top of this form?
www.irs.gov/pub/irs-pdf/fw9.pdf
How would you open up Acrobat and insert the name "John Smith" into the name field at the top of this form?
do you have a full Adobe Acrobat software for editing?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
.....And yes, I have a full version of Acrobat for editting.
ASKER
I'll give this a go and get back to you shortly....... :D
ASKER
Sorry for the ridiculous delay...!!
Although I haven't had chance to try & test this fully, the code seems to be the pointer I need.
Many thanks... :D
Although I haven't had chance to try & test this fully, the code seems to be the pointer I need.
Many thanks... :D
ASKER
I have reached the stage where I have completed everything else and I need to get this working. More points are up for grabs on this issue -- see: https://www.experts-exchange.com/questions/21416380/Fill-fields-in-Adobe-Acrobat-form-pdf-fields.html
Thanks.
Thanks.