Member 13328069 Ответов: 0

Itextsharp работает с исходным кодом, но не на клиентской машине


Привет,
Мы пытаемся внедрить itextsharp для заполнения pdf-форм для нашего программного обеспечения.
У нас возникли проблемы с тем, что он работает нормально, если мы запустим его на той же машине, на которой мы создали исходный код.
но когда мы пробуем его на другой машине, он создает pdf-файл, но не заполняет его.

Что я уже пробовал:

Imports ADODB
Imports System.Text
Imports System.Runtime.InteropServices
Imports iTextSharp
Imports iTextSharp.text
Imports iTextSharp.text.pdf
Imports iTextSharp.text.xml
Imports System.IO

Public Class mainForm
    Private hWnd As Long = Me.Handle
    Private conn As New ADODB.Connection
    Private rs As New ADODB.Recordset
    Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated

        Dim bOk As Boolean : bOk = False
        conn.Provider = "Microsoft.Jet.OLEDB.4.0"
        conn.CursorLocation = CursorLocationEnum.adUseClient
        conn.Open(GetFullDataPath)
        Dim pdfMainForm As String = "C:\test\FORM1.TXT"
        Dim pdfFile As String = "c:\test\reg343.pdf"
        Dim pdfFileTo As String

        pdfMainForm = Environment.GetCommandLineArgs(1)
        pdfFile = Environment.GetCommandLineArgs(2)

        Dim frmTitle As String = pdfFile ' _left(pdfMainForm, Len(pdfMainForm) - 4) & Format(Now(), "_yyyy-mm-dd_HHMM") & ".pdf" '"testing"
        Dim fromSql As String = " FROM  Vendors AS Lender RIGHT JOIN (Customer AS Spouse RIGHT JOIN (Customer AS Cobuyer RIGHT JOIN (Vendors INNER JOIN (Sale INNER JOIN (Customer INNER JOIN (Vehicle INNER JOIN Deal ON Vehicle.recNum = Deal.carRecNum) ON Customer.RecNum = Deal.buyerRecNum) ON Sale.recNum = Deal.saleRecNum) ON Vendors.recNum = Vehicle.vendorRecNum) ON Cobuyer.RecNum = Deal.coBuyerRecNum) ON Spouse.RecNum = Deal.spouseRecNum) ON Lender.recNum = Deal.lenderRecNum"


        Dim formApp As PdfReader = New PdfReader(pdfFile)
        pdfFileTo = _left(pdfFile, Len(pdfFile) - 4) & Format(Now(), "_yyyy-mm-dd_HHMM") & ".pdf"
        Dim pdfStamper As New PdfStamper(formApp, New FileStream(pdfFileTo, FileMode.Create))

        Dim acroForm As AcroFields
        acroForm = pdfStamper.AcroFields
        Dim xList As String
        Dim sql As String
        Dim fldName As String
        xList = ""
        Dim field As New DictionaryEntry
        For Each field In acroForm.Fields
            fldName = GetDataPath("Forms Fields", field.Key.ToString(), "", pdfMainForm)
            If fldName <> "" Then
                xList = xList & fldName & ","
            End If
        Next

        sql = " SELECT " & xList & "Deal.recnum "
        sql = sql + fromSql
        sql = sql + " where Deal.recNum = " & Environment.GetCommandLineArgs(3)
        rs.Open(sql, conn, CursorTypeEnum.adOpenDynamic, LockTypeEnum.adLockOptimistic)
        If rs.RecordCount > 0 Then
            rs.MoveFirst()
            For Each field In acroForm.Fields
                fldName = GetDataPath("Forms Fields", field.Key.ToString(), "", pdfMainForm)
                If InStr(UCase(fldName), " AS ") > 0 Then
                    fldName = Trim(Mid(fldName, InStr(UCase(fldName), " AS ") + 4, Len(fldName) - InStr(UCase(fldName), " AS ") + 4))
                End If
                If fldName <> "" Then
                    'field.Value = rs.Fields(fldName).Value & ""
                    acroForm.SetField(field.Key.ToString(), rs.Fields(fldName).Value & "")
                End If
            Next
        End If
        xList = ""

        sql = " SELECT * from DealerTemp "
        If rs.State > 0 Then rs.Close()
        rs.Open(sql, conn, CursorTypeEnum.adOpenDynamic, LockTypeEnum.adLockOptimistic)
        If rs.RecordCount > 0 Then
            rs.MoveFirst()
            For Each field In acroForm.Fields
                fldName = GetDataPath("DealerTemp", field.Key.ToString(), "", pdfMainForm)
                If InStr(UCase(fldName), " AS ") > 0 Then
                    fldName = Trim(Mid(fldName, InStr(UCase(fldName), " AS ") + 4, Len(fldName) - InStr(UCase(fldName), " AS ") + 4))
                End If
                If fldName <> "" Then
                    '                    field.Value = rs.Fields(fldName).Value & ""
                    acroForm.SetField(field.Key.ToString(), rs.Fields(fldName).Value & "")
                End If
            Next
        End If
        '        pddoc = avDoc.GetPDDoc
        '        pddoc = avDoc.GetPDDoc
        '        bOk = pddoc.Save(1, _left(pdfFile, Len(pdfFile) - 4) & Format(Now(), "_yyyy-mm-dd_HHMM") & ".pdf")
        pdfStamper.FormFlattening = True
        pdfStamper.Close()
        SetFileAttributes(pdfFileTo, vbReadOnly)
        ShellExecute(hWnd, "Open", pdfFileTo, "", "", 0)
        End
    End Sub


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class

Richard MacCutchan

Вам нужно собрать больше деталей и добавить их к вашему вопросу. Мы не можем догадаться, что произойдет, когда вы попытаетесь запустить это.

0 Ответов