Skip to Content
0

How to add page setup and print layout option in crystal report viewer?

Mar 19 at 01:38 PM

58

avatar image
Former Member

I am using crystal report in a WPF application designed in visual studio 2010. I have used two report viewers to display crystal report;

1: Microsoft.ReportViewer.WinForms

Code :

<Window x:Class="HelloWorld.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:rv="clr- namespace:Microsoft.Reporting.WinForms;assembly=Microsoft.ReportViewer.WinForms"
        Title="WFReportViewer" Height="800" Width="900">
    <Grid>
        <WindowsFormsHost Height="700" Name="windowsFormsHost1" Width="800">
            <rv:ReportViewer x:Name="_reportViewer" />
        </WindowsFormsHost>
    </Grid>
    </Window>

Output : [Post I run the above code, below is the output][1]

[1]:

[When I click on page setup, I get this option ][2]

[2]:

So, I can do page setup, view the changes, and can print the report then.

2: SAP CrystalReportsViewer

Code :

 <Window x:Class="HelloWorld.CrystalReportWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:my="clr-namespace:SAPBusinessObjects.WPF.Viewer;assembly=SAPBusinessObjects.WPF.Viewer"
            Title="CrystalReportWindow" Height="800" Width="900" Loaded="Window_Loaded">
        <Grid Name="grid1">
            <my:CrystalReportsViewer HorizontalAlignment="Left" Name="crystalRptVwr1" VerticalAlignment="Top" Height="700" Width="850" ShowOpenFileButton="False" ShowPrintButton="True" ShowExportButton="True" SnapsToDevicePixels="False" UseLayoutRounding="False" />
        </Grid>
    </Window>

Output : [When I run this code, I get this output][3]

[3]:

Now, an only print option is available here. there is no layout option or page setup option in crystal report viewer. I need to add them so that after we run crystal report, a user should be able to change page setup and check it's preview. I have searched on the internet a lot, but not able to find any solution. Can anyone please advice and help me on this?

Thanks in advance.

wfreport.png (18.8 kB)
wfpagesetup.png (77.6 kB)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Don Williams
Mar 22 at 01:17 PM
0

Not many people use the WPF viewer so R&D has not spent a lot of time bringing it up to the abilities the WinForm viewer has.

Due to the platform differences some things are not possible with that viewer.

On the Download Wiki Page my printer test app will get all of the values CR saves in the RPT file:

Printing Crystal Reports in .NET

Using it as an example should get all of the properties you need. It's not the viewer generating the Print job, it's just some place to put a button to start the print job.

Don

Show 1 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Thanks Don for the info and giving you time on this. Really appreciate that..

0
Don Williams
Mar 19 at 02:14 PM
0

Hi Adnan,

Our Viewers need to send the print job from the viewer code and cannot hook into the WPF's print buttons.

There is a way to hook into the Windows Form viewer, see this Post:

https://answers.sap.com/questions/459835/adding-controls-to-the-viewer-toolbar.html

If you go into the properties of the WPF viewer and click on the CR viewer in the Miscellaneous area you can turn on/off our various buttons. If you can figure out how to hook into our buttons in the WPF viewer you could replace our buttons with your own and do the coding behind it to print.

Otherwise you don't want to use the standard WPF print buttons. Or possibly you could hide our Print button and do the CR Printer code using the PrintOutputController to do the printing.

On the CR for download WIKI there is a printer test app that has all of the code in it to use.

Don

Show 1 Share
10 |10000 characters needed characters left characters exceeded
Former Member

First of all, thanks for giving your time and looking into this issue

The suggestion of hiding crystal report viewer print button and adding a custom print button that will do the print job has been done by me. An issue with that is to find all printer settings (like margins, paper selection, orientation etc)and display a custom window from where a user can apply those settings and then view the changes. I am able to make a couple of those printer settings customization but not all.

These all things I have to do since this crystal report viewer of WPF is not having page layout, print preview option, although the same was available in windows form's viewer.

Can you please tell me why crystal report viewer designed for WPF is not having this option of page layout, as the same was available with windows forms?

0