2012-02-04 3 views
1

기본 시나리오는 프로그래밍 방식으로 웹 서버에있는 PDF 텍스트 필드를 작성해야한다는 것입니다. 필드는 CSV에 포함 된 데이터로 매핑되고 채워집니다. PDF는 브라우저 (예 : 브라우저 컨트롤 또는 ie/ff/chrome/etc)에서 열고 장소에서 편집해야합니다. 다운로드, 작성 및 업로드 할 수 없습니다 (제출 버튼을 사용하여 작성하고 제출해야하며, 버튼 제출 경로를 아무런 효력이 없도록 편집 해 보았습니다).프로그래밍 방식으로 브라우저 컨트롤에서 PDF 양식 필드 채우기

지금까지 양식에 웹 브라우저 컨트롤을 설치하고 웹 사이트로 이동하여 로그인하고 PDF 파일을로드했습니다. 웹 브라우저 컨트롤에서 열리는 PDF 파일과 어떻게 상호 작용합니까? 다양한 PDF 라이브러리를 살펴보면 주로 하드 드라이브에있는 닫힌 PDF 파일과 상호 작용하고 수정 한 다음 다시 저장하는 것으로 보입니다.

EDIT : 다른 솔루션에 대한 의견이 열려 있습니다. 그게 가능하다면,하지만 만약 그렇다면 - PDF 기반 자바 스크립트 내 컴퓨터에 내가 양식을 실행 알아? 다운로드하면 쉽게 할 수 있지만 웹 브라우저에서 PDFJS를 사용하는 방법을 찾지 못하는 것 같습니다.

답변

1

나는 당신이하고 싶은 일을하기가 쉽지 않을까 걱정됩니다. 먼저 WebBrowser 컨트롤에 포함 된 PDF 판독기의 창 핸들을 찾아야합니다. 여기에 예제 코드가 있습니다 :

Public Function GetPdfViewerHandle() As System.IntPtr 
    Dim tempHandle As System.IntPtr 
    '-------------------------------------- 
    ' get handle to pdf viewer 
    '-------------------------------------- 
    '-------------------------------------- 
    ' first check for the foxit reader 
    '-------------------------------------- 
    tempHandle = FindChildWindow(WebBrowser1.Handle, "AfxWnd42s", "Reader", 1, True) 
    If IntPtr.Zero.Equals(tempHandle) = True Then 
     '--------------------------------- 
     ' if not foxit, check for adobe 
     '--------------------------------- 
     tempHandle = FindChildWindow(WebBrowser1.Handle, "AVL_AVVIEW", "AVPageView", 1, True) 
    End If 

    Return tempHandle 

End Function 

Public Shared Function FindChildWindow(ByVal hParent As IntPtr, ByVal P_childClass As String, ByVal P_childTitle As String, ByVal P_count As Integer, ByVal p_recursive As Boolean) As IntPtr 
    Dim hChild As IntPtr 
    Dim className As String 
    Dim title As String 
    Dim cnt As Integer 
    Dim tempPtr As IntPtr 
    Dim Declare Function FindWindowExA Lib "user32.dll" (ByVal hWnd1 As IntPtr, ByVal hWnd2 As Int32, ByVal lpsz1 As String, ByVal lpsz2 As String) As IntPtr 

    cnt = 0 

    hChild = FindWindowExA(hParent, 0, Nothing, Nothing) 

    While hChild.ToInt32 > 0 

     If P_childClass Is Nothing Then 
      className = GetClassName(hChild) 
     Else 
      className = GetClassName(hChild) 
      If P_childClass.Length < className.Length Then 
       className = className.Substring(0, P_childClass.Length) 
      End If 
     End If 

     If P_childTitle Is Nothing Then 
      title = GetWindowText(hChild).Replace("&", "") 
     Else 
      title = GetWindowText(hChild).Replace("&", "") 

      If P_childTitle.Length < title.Length Then 
       title = title.Substring(0, P_childTitle.Length) 
      End If 
     End If 


     Debug.WriteLine("hwnd=" + Hex$(hChild.ToInt32) + ", className = " + className + ", title = " + title) 
     If (String.Compare(className, P_childClass, True) = 0 And String.Compare(title, P_childTitle, True) = 0) Or (P_childClass = Nothing And String.Compare(title, P_childTitle, True) = 0) Or (String.Compare(className, P_childClass, True) = 0 And P_childTitle = Nothing) Then 
      cnt += 1 
      If cnt >= P_count Then 
       Return hChild 
      End If 
     End If 

     If p_recursive = True Then 
      tempPtr = FindChildWindow(hChild, P_childClass, P_childTitle, 1, p_recursive) 
      If IntPtr.Zero.Equals(tempPtr) = False Then 
       Return tempPtr 
      End If 
     End If 

     hChild = FindWindowExA(hParent, hChild.ToInt32, Nothing, Nothing) 
    End While 

    Return Nothing 

    End Function 

일단 사용자가 창 핸들을 사용하면 양식 필드를 찾는 방법이 많이 있습니다. 당신이 일의 순서를 알고 있다면, 당신은 단순히 PDF 리더 핸들에 키 명령을 전송 시작하거나 Win32Api SendMessageW 대신 기능을 통해 그들에게 데이터를 입력 양식 필드의 핸들을 찾기 위해 스파이 ++를 사용할 수 있습니다

 Public Declare Function SendMessageA Lib "user32.dll" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer 

        asciiChar = CByte(Asc(data.Substring(0, 1))) 
       rc = SendMessageA(hwnd, WM_CHAR, asciiChar, 0)  

좋음, 운.

+0

폼의 레이아웃이 항상 동일해야하며 이미 텍스트 필드의 이름을 가지고 있습니다 (iText # 덕분에) – Cloud007

+0

감사합니다! 이것은 내가 필요한 것입니다. –

0

PDF의 버튼을 사용하여 데이터를 제출해야만 제출 된 트래픽을 검사하고 전송 된 것을 확인하면 VB.NET으로 복제 할 수 있으며 PDF 문서를로드 할 필요도 없습니다.

관련 문제