How to print report in black and white?

Stimulsoft Reports.WEB discussion
a.ebbini
Posts: 101
Joined: Thu Jun 05, 2014 8:10 am
Location: Jordan

How to print report in black and white?

Post by a.ebbini »

Hello Support Team,
How to apply black and white on export or print only and showing it throw report viewer with colors?
Because the report after will be cached after preview, i try to apply black and white ExportReportResponse,PrintReport but it dosen't work.

Code: Select all

    Private Sub RV_ExportReportResponse(sender As Object, e As StiExportReportResponseEventArgs) Handles RV.ExportReportResponse
            If AdvancedOptions.IsPrintOptionSelected Then
                MakeBlackAndWhite(e.Report)
            End If
    End Sub
    Private Sub RV_PrintReport(sender As Object, e As StiPrintReportEventArgs) Handles RV.PrintReport
            If AdvancedOptions.IsPrintOptionSelected Then
                MakeBlackAndWhite(e.Report)
            End If
    End Sub

 Public Shared Sub MakeBlackAndWhite(ByVal report As StiReport)

        For Each page As StiPage In report.Pages
            Dim comps As StiComponentsCollection = page.GetComponents()
            For Each comp As StiComponent In comps
                Select Case comp.GetType.Name
                    Case "StiText"
                        Dim TextComp As StiText
                        TextComp = report.GetComponentByName(comp.Name)
                        TextComp.Brush = New StiSolidBrush(Color.Transparent)
                        TextComp.TextBrush = New StiSolidBrush(Color.Black)
                        TextComp.Border.Color = Color.Black
                        TextComp.ComponentStyle = ""
                End Select
            Next
        Next


    End Sub
Last edited by a.ebbini on Tue Sep 20, 2016 5:12 pm, edited 1 time in total.
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: How to print report in black and white?

Post by HighAley »

Hello.

Could you specify the version of our product and the name of the component that you use?

Thank you.
a.ebbini
Posts: 101
Joined: Thu Jun 05, 2014 8:10 am
Location: Jordan

Re: How to print report in black and white?

Post by a.ebbini »

Hello,
i'm using StiWebViewer component under Stimulsoft.Report.Web assembly with version 2016.1.28

i suggest when user submit a ticket in stimulsoft forum to fill compenent ,assembly, version and other fields that can help your support team to
serve the ticket and by this way you can help user to describe his\her issue and decrease the time form your side to serve the ticket.
for example usually i mention at least the version number in my ticket but sometimes i forget this thing like this ticket and by doing this i wast my and your time "it take two posts from you to ask the question and from me to answer it".

Please don't forget my main question :D
thank you.
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: How to print report in black and white?

Post by HighAley »

Hello.

The rendered pages of the report are stored in the RenderedPages collection of the report.
If you want to change the color of the rendered components, you should do it with the components of the rendered pages.
Or if you change color of the components of the report template, please, render the report again.

As about adding information about the using product and its version. Some our customers use different products and can use different versions of our product simultaneously, so please specify necessary information in each your request.

Thank you.
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: How to print report in black and white?

Post by HighAley »

Hello

Also you should use the ExportReport event instead of the ExportReportResponse event.

Thank you.
a.ebbini
Posts: 101
Joined: Thu Jun 05, 2014 8:10 am
Location: Jordan

Re: How to print report in black and white?

Post by a.ebbini »

Hello,
What do you mean by this
If you want to change the color of the rendered components, you should do it with the components of the rendered pages.
i try to walk through report.RenderedPages instead of report.Pages,but still there is colors

Code: Select all

  Public Shared Sub MakeBlackAndWhite(ByVal report As StiReport)

        For Each page As StiPage In report.RenderedPages
            Dim comps As StiComponentsCollection = page.GetComponents()
            For Each comp As StiComponent In comps
                Select Case comp.GetType.Name
                    Case "StiText"
                        Dim TextComp As StiText
                        TextComp = report.GetComponentByName(comp.Name)
                        TextComp.Brush = New StiSolidBrush(Color.Transparent)
                        TextComp.TextBrush = New StiSolidBrush(Color.Black)
                        TextComp.Border.Color = Color.Black
                        TextComp.ComponentStyle = ""
                End Select
            Next
        Next
    End Sub
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: How to print report in black and white?

Post by HighAley »

Hello.

Could you send us a sample project that reproduces the issue?
We need to reproduce the issue on our side to help you.

Thank you.
a.ebbini
Posts: 101
Joined: Thu Jun 05, 2014 8:10 am
Location: Jordan

Re: How to print report in black and white?

Post by a.ebbini »

Hello,
Sorry it is hard to send project but mainly i made report preparing in page_Load,but I made a step by adding code at ExportReport and PrintReport events

Code: Select all

    Private Sub RV_ExportReport(sender As Object, e As Stimulsoft.Report.Web.StiExportReportEventArgs) Handles RV.ExportReport
        Sky.Bayan.Business.Reports.Functions.MakeBlackAndWhite(e.Report)
        e.Report.Compile()
        e.Report.Render()
        RV.Report = e.Report
    End Sub

    Private Sub RV_PrintReport(sender As Object, e As Stimulsoft.Report.Web.StiPrintReportEventArgs) Handles RV.PrintReport
        Sky.Bayan.Business.Reports.Functions.MakeBlackAndWhite(e.Report)
        e.Report.Compile()
        e.Report.Render()
        RV.Report = e.Report
    End Sub
By doing this i achieve my objective,but also i have two problems
1)when i export report without colors then press on sort or collapse the report appears without colors
2)when press sort or collapse then i try to export the report an error appear Report already compiled "attached"
Please i need help
Attachments
Report already compiled.rar
(2.21 KiB) Downloaded 400 times
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: How to print report in black and white?

Post by HighAley »

Hello.

I will try to explain the issue one more time.

Before the exporting or printing you have rendered report in Viewer.
Then the ExportReport or PrintReport event are fired you need to change the color of the components of the rendered report.

So you should NOT compile and render the report.

Now the main issue. You go through rendered components and look for the StiText. And you already have this component in comp variable. So you should not call

Code: Select all

TextComp = report.GetComponentByName(comp.Name)
Especially because you get the component of the report template. Just remove this line and change the color of the comp.

Thank you.
a.ebbini
Posts: 101
Joined: Thu Jun 05, 2014 8:10 am
Location: Jordan

Re: How to print report in black and white?

Post by a.ebbini »

Hello,
first i solve the first problem
1)when i export report without colors then press on sort or collapse the report appears without colors
By doing this

Code: Select all

    Private Sub RV_ExportReport(sender As Object, e As Stimulsoft.Report.Web.StiExportReportEventArgs) Handles RV.ExportReport
        If Session(PrintInColors) <> Session(PrintInColorsLastState) Then
            Session(PrintInColorsLastState) = Session(PrintInColors)
            ChangeEvenStyle(e.Report, Session(PrintInColors))
            e.Report.Compile()
            e.Report.Render()
            If Not Session(PrintInColors) Then
                MakeBlackAndWhite(e.Report)
            End If
        End If
    End Sub

    Private Sub RV_PrintReport(sender As Object, e As Stimulsoft.Report.Web.StiPrintReportEventArgs) Handles RV.PrintReport
        If Session(PrintInColors) <> Session(PrintInColorsLastState) Then
            Session(PrintInColorsLastState) = Session(PrintInColors)
            ChangeEvenStyle(e.Report, Session(PrintInColors))
            e.Report.Compile()
            e.Report.Render()
            If Not Session(PrintInColors) Then
                MakeBlackAndWhite(e.Report)
            End If
        End If
    End Sub
    Public Shared Sub MakeBlackAndWhite(ByVal report As StiReport)

        For Each page In report.RenderedPages
            Dim comps As StiComponentsCollection = page.GetComponents()
            For Each comp As StiComponent In comps
                Select Case comp.GetType.Name
                    Case "StiText"
                        Dim TextComp As StiText = comp
                        TextComp.Brush = New StiSolidBrush(Color.Transparent)
                        TextComp.TextBrush = New StiSolidBrush(Color.Black)
                        TextComp.Border.Color = Color.Black
                        TextComp.ComponentStyle = ""
                End Select
            Next
        Next


    End Sub
    Public Shared Sub ChangeEvenStyle(ByVal report As StiReport, ByVal Add As Boolean)
        If Not report.Styles.Contains("EvenStyle") Then Exit Sub
        Dim EvenStyle As String = Nothing
        If Add Then
            EvenStyle = "EvenStyle"
        End If
        For Each page In report.Pages
            Dim comps As StiComponentsCollection = page.GetComponents()
            For Each comp As StiComponent In comps
                Select Case comp.GetType.Name
                    Case "StiDataBand"
                        Dim DataBandComp As StiDataBand = comp
                        DataBandComp.EvenStyle = EvenStyle
                    Case "StiHierarchicalBand"
                        Dim DataBandComp As StiHierarchicalBand = comp
                        DataBandComp.EvenStyle = EvenStyle
                End Select
            Next
        Next
    End Sub
But the second problem still yet
2)when press sort or collapse then i try to export the report an error appear Report already compiled "attached"
You advise me to should NOT compile and render the report at export and print events ,but i need to compile and render because some times there is components have style and as i tried change style property need compile and render as i mentioned MakeBlackAndWhite function that i attached in the first post

I need you advise.
Post Reply