2014-03-05 3 views
0

나는 내 바퀴를 돌리고 있습니다. vb.net을 사용하는 asp.net 사이트가 있습니다. 인트라넷 SharePoint 페이지를 통해이 ASP.net 사이트에 연결됩니다. SSRS 보고서에서 pdf 파일을 생성하는 코드가 있습니다. 이제 같은 코드 줄에서 pdf 파일을 인쇄하고 싶습니다. 나는 이것이 작동하지만 운이 좋지 않다는 것을 알았습니다.버튼을 클릭하십시오. 서버에서 PDF 인쇄를 클릭하십시오.

''''PRINT REPORT 
    ''get default printer 
    Dim oPS As New System.Drawing.Printing.PrinterSettings 
    Dim defaultprintername As String = "" 
    Try 
     'Set my print ---- defaultprintername = "Dell 3330dn Laser Printer XL" 
     defaultprintername = oPS.PrinterName 
    Catch ex As System.Exception 
     defaultprintername = "" 
     SendAllLabel.Text = "ERROR - Could not set printer" 
    Finally 
     oPS = Nothing 
    End Try 

    Dim pathToExecutable As String = "AcroRd32.exe" 
    Dim starter As New ProcessStartInfo(pathToExecutable, "/t " + strReportOutput + " " + defaultprintername + "") 
    Dim Process As New Process() 
    Process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden 
    Process.StartInfo.UseShellExecute = True 
    Process.StartInfo.Verb = "print" 
    Process.StartInfo.CreateNoWindow = True 
    Process.StartInfo = starter 
    ''WILL NOT START BUT NO EXCEPTION 
    Try 
     Process.Start() 
     Process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden 
    Catch ex As System.Exception 
     SendAllLabel.Text = "ERROR - Could not set print job." 
    End Try 

    System.Threading.Thread.Sleep(30000) 

    Process.CloseMainWindow() 
    Dim iLoop As Int16 = 0 
    'check the process has exited or not 
    If Process.HasExited = False Then 
     Try 
      Process.Kill() 
     Catch ex As Exception 
      SendAllLabel.Text = "ERROR - Could not stop process." 
     End Try 
     'if not then loop for 100 time to try and close the process'with 10 seconds delay 
     While Not Process.HasExited 
      System.Threading.Thread.Sleep(10000) 
      Process.CloseMainWindow() 
      iLoop = CShort(iLoop + 1) 

      If iLoop >= 100 Then 


       Try 
        Process.Kill() 
       Catch ex As Exception 
        SendAllLabel.Text = "ERROR - Could not stop process." 
       End Try 
       Exit While 
      End If 
     End While 
    End If 

    Process.Close() 
    Process.Dispose() 
    Process = Nothing 
    starter = Nothing 

이 기능을 사용하려면 어떻게해야합니까? 이 코드를 참조하는 사이트가 많이 있지만 그 이상의 내용은 아닙니다. 권한을 부여해야합니까? 그렇다면 어떻게해야합니까? 서버가 Adobe Reader 10.0을 사용하고 대부분의 사용자가 Reader 11.0을 사용 중입니다.

하십시오 당신에게 내가 나이 전에 쓴

당신은 PDF를 생성 한 후 브라우저로 아래로 스트리밍 할 필요가
+0

ASP 코드로 인쇄하라는 메시지가 나타나면 클라이언트 컴퓨터가 아닌 서버에서 인쇄하도록 요청하는 것입니다. 맞습니까? – Steve

+0

새 웹 브라우저에서 PDF를 열면 인쇄 옵션이 제공됩니다. 이것으로 충분하겠습니까? – voddy

+0

서버의 기본 프린터는 클라이언트를 위해 이동해야하는 프린터입니다. – Schwimms

답변

0

, 여기에 뭔가를 감사드립니다.

Response.Clear() 
    Response.ClearHeaders() 
    Response.ClearContent() 

    Response.ContentType = "application/pdf" 

    ' IE & Acrobat seam to require "content-disposition" header being in the response. If you don't add it, the doc still works most of the time, but not always. 
    ' this makes a new window appear: 
    ' you can replace the filename with the actual filename 
    Response.AddHeader("content-disposition", "attachment; filename=something.PDF") 

    ' Create a new memory stream that will hold the pdf output 
    Dim memStream As New System.IO.MemoryStream() 

    ' Export the report to PDF: 
    ' put the pdf file into the memStream 
    ' the strpath variable should hold the full path and filename of the pdf file 
    ' for example dim strPath = "\\hw.net\files\2014dt140305.105459.pdf" 
    Dim bData As Byte() 
    Dim br As BinaryReader = New BinaryReader(System.IO.File.OpenRead(strPath)) 
    bData = br.ReadBytes(br.BaseStream.Length) 
    Dim memStream As MemoryStream = New MemoryStream(bData, 0, bData.Length) 

    ' Write the PDF stream out 
    Response.BinaryWrite(memStream.ToArray()) 

    ' Send all buffered content to the client 
    Response.End() 
+0

파일은 회사 공유 드라이브에 있습니다. \\ Hw \ files \ 2014dt140305.105459.pdf – Schwimms

+0

죄송합니다. 전체 링크가 아닙니다. \\ hw.net \ files \ 2014dt140305.105459.pdf – Schwimms

+0

I 'memorystream 객체에 pdf를 읽는 코드를 포함하도록 내 대답을 편집했습니다. –

관련 문제