Printing Issue on x64 machine RRS feed

  • Question

  • User-290338403 posted


    I am using PrintDocument Class for Server Side Printing of a Server Report (.rdl)(Rendered as Byte() using ReportExecutionService2005 API) as;

    public function RenderReport(byval reportPath as String) as Byte()()



    execInfo = objReportExecutionService.LoadReport(reportPath, strHistoryID)

    deviceInfo = "<DeviceInfo>" + _

     "<OutputFormat>emf</OutputFormat>" + _

     " <PageWidth>12.5in</PageWidth>" + _

     " <PageHeight>11in</PageHeight>" + _

     " <MarginTop>0.25in</MarginTop>" + _

     " <MarginLeft>0.25in</MarginLeft>" + _

     " <MarginRight>0.25in</MarginRight>" + _

     " <MarginBottom>0.25in</MarginBottom>" + _


    firstPage = objReportExecutionService.Render("IMAGE", deviceInfo, extension, encoding, mimeType, warnings, streamIDs)


    End Function

     The Code Works fine when deployed on 32-bit OS Server but, when it is deployed on Windows Server 2008 x64 machine. It gives the Following Error when tried to Print:

    System.ComponentModel.Win32Exception (0x80004005): The handle is invalid     at System.Drawing.Printing.StandardPrintController.OnStartPrint(PrintDocument document, PrintEventArgs e)     at System.Windows.Forms.PrintControllerWithStatusDialog.OnStartPrint(PrintDocument document, PrintEventArgs e)     at System.Drawing.Printing.PrintController.Print(PrintDocument document)...

    The Code Which I used for Printing is as Follows;

    Public m_metafile As Metafile Nothing

    Public m_delegate As EnumerateMetafileProc = Nothing


    Dim objPageSettings As PageSettings = New PageSettings

    Dim objPrinterSettings As PrinterSettings = New PrinterSettings()

    Dim objPrintDocument As PrintDocument = New PrintDocument()

    dim bytRenderedReport as Byte()() = Nothing

    bytRenderedReport = RenderReport(reportPath) 'Path of the Report on Report Server


    AddHandler objPrintDocument.PrintPage, AddressOf objPrintDocument_PrintPage


    Private Sub objPrintDocument_PrintPage(ByVal sender As Object, ByVal ev As System.Drawing.Printing.PrintPageEventArgs)

    ev.HasMorePages =False

    'Draw the page

    ReportDrawPage(ev.Graphics, ev)

    ' If the next page is less than the last page, print another page.

    ev.HasMorePages = true

    End Sub

    Private Sub ReportDrawPage(ByVal g As Graphics, ByVal e As PrintPageEventArgs)

    Dim width As Integer

    Dim height As Integer

    Dim destRect As Rectangle = New Rectangle(e.PageBounds.Left - CInt(Math.Truncate(e.PageSettings.HardMarginX)), e.PageBounds.Top - CInt(Math.Truncate(e.PageSettings.HardMarginY)), e.PageBounds.Width, e.PageBounds.Height)

    SyncLock Me

    ' Set the metafile delegate.

    width = 1024

    height = 768

    m_delegate = New EnumerateMetafileProc(AddressOf MetafileCallback)

    g.EnumerateMetafile(m_metafile, destRect, m_delegate)

    m_delegate = Nothing

     End SyncLock

    End Sub


    Function MetafileCallback(ByVal recordType As EmfPlusRecordType, ByVal flags As Integer, ByVal dataSize As Integer, ByVal data As IntPtr, ByVal callbackData As PlayRecordCallback) As Boolean

    Dim dataArray As Byte() = Nothing

    If data <> IntPtr.Zero Then

    ' Copy the unmanaged record to a managed byte buffer that can be used by PlayRecord.

    dataArray = New Byte(dataSize - 1) {}

    Runtime.InteropServices.Marshal.Copy(data, dataArray, 0, dataSize)

    End If

    ' play the record.

    m_metafile.PlayRecord(recordType, flags, dataSize, dataArray)

    Return True

    End Function

    Please Help!!!

    Monday, August 1, 2011 12:21 PM

All replies