|  Respuesta: Error al capturar impresion de un documento .net 2005 sql server.  
  ESTA ES LA SEGUNDA PARTE PQ NO PUDE COLOCAR TODO YA QUE SE PASA DEL RANGO DE LINEAS.  
 
 Private Sub Command3_Click(ByVal sender As System.Object, _
 ByVal e As System.EventArgs) Handles Command3.Click
 'Clear the text boxes to display the printer status.
 TextBox1.Text = ""
 TextBox2.Text = ""
 TextBox3.Text = ""
 End Sub
 
 Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) _
 Handles MyBase.Load
 'Initialize captions for the buttons.
 Command1.Text = "Empezar"
 Command2.Text = "Para"
 Command3.Text = "Actualizar"
 
 'Clear the text boxes to display the printer status.
 TextBox1.Text = ""
 TextBox2.Text = ""
 TextBox3.Text = ""
 
 Command1.Enabled = True
 'Disable the stop and clear buttons.
 Command2.Enabled = False
 Command3.Enabled = False
 
 'Set the timer interval to 500 milliseconds to examine the printer status.
 Timer1.Enabled = False
 Timer1.Interval = 500
 End Sub
 
 Private Sub Timer1_Tick(ByVal sender As System.Object, _
 ByVal e As System.EventArgs) Handles Timer1.Tick
 Dim PrinterStatus As String
 Dim JobStatus As String
 Dim ErrorInfo As String
 
 'Clear the text boxes to display the status.
 TextBox1.Text = ""
 TextBox2.Text = ""
 TextBox3.Text = ""
 
 'Call the CheckPrinter function.
 TextBox1.Text = CheckPrinter(PrinterStatus, JobStatus)
 TextBox2.Text = PrinterStatus
 TextBox3.Text = JobStatus
 End Sub
 
 Public Function CheckPrinter(ByRef PrinterStr As String, _
 ByRef JobStr As String) As String
 Dim hPrinter As IntPtr
 Dim ByteBuf As Long
 Dim BytesNeeded As Int32
 Dim PI2 As New PRINTER_INFO_2
 Dim intCount As Long
 Dim JI2(intCount) As JOB_INFO_2
 Dim PrinterInfo() As Byte
 Dim JobInfo() As Byte
 Dim result As Long
 Dim LastError As Long
 Dim PrinterName As String
 Dim tempStr As String
 Dim NumJI2 As Int32
 Dim pDefaults As PRINTER_DEFAULTS
 
 'Set a default return value if no errors occur.
 CheckPrinter = "Printer info retrieved!"
 
 Dim PD As New PrintDocument
 PrinterName = PD.PrinterSettings.PrinterName
 
 'Set the access security setting that you want.
 pDefaults.DesiredAccess = PRINTER_ACCESS_USE
 
 'Call the API to obtain a handle to the printer.
 'If an error occurs, display the error.
 result = WINAPI.OpenPrinter(PrinterName, hPrinter, pDefaults)
 If result = 0 Then
 
 CheckPrinter = "Cannot open printer " & PrinterName & _
 ", Error: " & Marshal.GetLastWin32Error()
 Exit Function
 End If
 
 'Initialize the BytesNeeded variable.
 BytesNeeded = 0
 
 'Clear the error object.
 Err.Clear()
 
 'Determine the buffer size that is required to obtain the printer information.
 result = WINAPI.GetPrinter(hPrinter, 2, 0&, 0, BytesNeeded)
 'Display the error message that you receive when you call the GetPrinter function,
 'and then close the printer handle.
 If Marshal.GetLastWin32Error() <> ERROR_INSUFFICIENT_BUFFER Then
 CheckPrinter = " > GetPrinter Failed on initial call! <"
 WINAPI.ClosePrinter(hPrinter)
 Exit Function
 End If
 ReDim PrinterInfo(BytesNeeded)
 ByteBuf = BytesNeeded
 
 'Call the GetPrinter function to obtain the status.
 result = WINAPI.GetPrinter(hPrinter, 2, PrinterInfo(0), ByteBuf, _
 BytesNeeded)
 
 'Check for any errors.
 If result = 0 Then
 'Get the error.
 LastError = Marshal.GetLastWin32Error()
 
 'Display the error message, and then close the printer handle.
 CheckPrinter = "Could not get Printer Status!  Error = " _
 & LastError
 WINAPI.ClosePrinter(hPrinter)
 Exit Function
 End If
 
 'Copy the contents of the printer status byte array into a
 'PRINTER_INFO_2 structure.
 PI2 = CType(DatatoDeserial(PrinterInfo, GetType(PRINTER_INFO_2), 1), PRINTER_INFO_2)
 PrinterStr = CheckPrinterStatus(PI2.Status)
 
 'Add the printer name, the driver, and the port to the text box.
 PrinterStr = PrinterStr & "Printer Name = " & _
 GetString(PI2.pPrinterName) & vbCrLf
 PrinterStr = PrinterStr & "Printer Driver Name = " & _
 GetString(PI2.pDriverName) & vbCrLf
 PrinterStr = PrinterStr & "Printer Port Name = " & _
 GetString(PI2.pPortName) & vbCrLf
 
 'Call the API to obtain the buffer size that is required.
 result = WINAPI.EnumJobs(hPrinter, 0, &HFFFFFFFF, 2, JobInfo, 0, BytesNeeded, NumJI2)
 If result = 0 Then
 'Display the error, and then close the printer handle.
 LastError = Marshal.GetLastWin32Error()
 CheckPrinter = " > EnumJobs Failed on initial call! <  Error = " _
 & LastError
 WINAPI.ClosePrinter(hPrinter)
 Exit Function
 End If
 
 'If no current jobs exist, display the message.
 If BytesNeeded = 0 Then
 JobStr = "No Print Jobs!"
 Else
 'Resize the byte array to hold information about the print jobs.
 ReDim JobInfo(BytesNeeded - 1)
 
 'Call the API to obtain the print job information.
 result = WINAPI.EnumJobs(hPrinter, 0, &HFFFFFFFF, 2, JobInfo, _
 BytesNeeded, BytesNeeded, NumJI2)
 
 'Check for errors.
 If result = 0 Then
 'Display the error, and then close the printer handle.
 LastError = Marshal.GetLastWin32Error()
 CheckPrinter = " > EnumJobs Failed on second call! <  Error = " _
 & LastError
 WINAPI.ClosePrinter(hPrinter)
 Exit Function
 End If
 ReDim JI2(NumJI2)
 
 'Copy the contents of print job info byte array into a
 'JOB_INFO_2 structure.
 Try
 For intCount = 0 To NumJI2 - 1 ' Loop through jobs and obtain the job information.
 Dim test As Object
 JI2(intCount) = CType(DatatoDeserial(JobInfo, _
 GetType(JOB_INFO_2), intCount + 1), JOB_INFO_2)
 
 JobStr = JobStr & "Job ID = " & JI2(intCount).PrinterJobId & _
 vbCrLf & "Total Pages = " & JI2(intCount).TotalPages & vbCrLf
 
 tempStr = ""
 'Check for a ready state.
 If JI2(intCount).pStatus = 0& Then   ' If pStatus is Null, check Status.
 If JI2(intCount).pStatus = 0 Then
 tempStr = tempStr & "Ready!  " & vbCrLf
 Else  'Check for the various print job states.
 If (JI2(intCount).pStatus And JOB_STATUS_SPOOLING) Then
 tempStr = tempStr & "Spooling  "
 End If
 
 If (JI2(intCount).pStatus And JOB_STATUS_OFFLINE) Then
 tempStr = tempStr & "Off line  "
 End If
 
 If (JI2(intCount).pStatus And JOB_STATUS_PAUSED) Then
 tempStr = tempStr & "Paused  "
 End If
 
 If (JI2(intCount).pStatus And JOB_STATUS_ERROR) Then
 tempStr = tempStr & "Error  "
 End If
 
 If (JI2(intCount).pStatus And JOB_STATUS_PAPEROUT) Then
 tempStr = tempStr & "Paper Out  "
 End If
 
 If (JI2(intCount).pStatus And JOB_STATUS_PRINTING) Then
 tempStr = tempStr & "Printing  "
 End If
 
 If (JI2(intCount).pStatus And JOB_STATUS_USER_INTERVENTION) Then
 tempStr = tempStr & "User Intervention Needed  "
 End If
 
 If Len(tempStr) = 0 Then
 tempStr = "Unknown Status of " & JI2(intCount).PrinterStatus
 End If
 End If
 Else
 
 tempStr = Pointer_to_String(JI2(intCount).pStatus)
 End If
 
 'Report the job status.
 JobStr = JobStr & tempStr & vbCrLf
 Next intCount
 Catch ex As Exception
 MessageBox.Show(ex.Message)
 End Try
 End If
 'Close the printer handle.
 WINAPI.ClosePrinter(hPrinter)
 End Function
 
 
 End Class[/code]
     |