Question

In onw of our application, we have some reports that need very specific margins that are dependant of the printer the user have. It is used to print into preformated paper with blanks to fill and depending of the printer, the printing is off by some margins. To make things worse, we don't actually control what printer is used because it is not an internal application.

The only solution I could think of is to let the user configure the margins somehow. I though I could just dinamycally change the report margins like I did with datasources and actual report ( I have one control that is used to display every reports from my application and it works alright), but I can't seem to find that damn property to do so. There is a margin property on the report viewer but it's for the form display so it doesn't cut it.

Does anyone knows how to. What I was thinking to do is to define the margins before the user loads the report, i.e. when he clicks on the report button, I load the report, set the margins (or vice-versa is necessary) and then display it.

Before someone mention it, I know the user can, once the report is loaded, change the page setup to fit his needs, but this has two drawbakcs. First one is that it is not saved each time and I need it to be 'saveable' and by users. The second one is that Report viewer seems to have some bugs when the regional setting aren't set to what it's expecting and we can't force the users to changes their setting to accomodate one application.

Thank you.

Eidt : Forgot to mention, it this is of any uses. My reports are all local reports.

Was it helpful?

Solution

You can't do this directly. Try controlling your margins in the report with report parameters.

OTHER TIPS

    'creates a new page setting
    Dim instance As New PageSettings()
    'create the new margin values (left,right,top,bottom)
    Dim value As New Margins(0, 0, 0, 0)
    'gives your new pagesetting a value
    instance.Margins = value

    'report viewer now sets your margins
    ReportViewer1.SetPageSettings(instance)

Well, I just had this similar problem; needed a report to have 0" margins, otherwise the blasted thing went from 2 pages to 6, and it split the data vertically, so the pages made no sense. I was having to set it manually in the Print Setup to print, but the end goal of this report is to be emailed to customers as a PDF, and guess what, when I set the margins manually and exported, it still split into 6 pages and bombed out. So risking everything, I tried one last supreme effort to fix this blasted thing - I opened up the .rdlc with word pad, and miracle of miracles, found 1in, etc. I set all those buggers to 0in, saved, ran my .net code (2008), opened up Print Setup, and hallelujah, there was my 0in settings. Now for the supreme test - I exported it as a PDF, went to the file, and son of a gun! Sweet. There were two crisp clean perfectly laid out pages. All was beneficent in the universe, I calmed down and let the midiclorians flow through me, and just basked in a moment so rare that it is rarely realized by some - a simple fix.

Check out the ReportPageSettings class, part of the report viewer control. Setting those values looks like it should get you what you need.

More settings;

        Dim myPageSettings As New PageSettings()
        myPageSettings.Margins = New Margins(0, 0, 0 , 0)
        Dim paperSize As PaperSize = New PaperSize()
        'ToDo: update with the PaperKind 
        'that your printer uses
        paperSize.RawKind = PaperKind.A4
        ' paperSize.RawKind = System.Drawing.Printing.PaperKind.A4
        myPageSettings.PaperSize = paperSize
        'False for "Portrait"
        'True for "Landscape"
        myPageSettings.Landscape = False

        'report viewer now sets your margins
        ReportViewer1.SetPageSettings(myPageSettings)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top