views:

2541

answers:

2

hi,

what is to do to set landscape for a pdf export ?

using of System.Drawing.Printing.PageSettings before a refresh doesn't work.

        Type tip = reportViewer1.GetType();
        FieldInfo[] pr = tip.GetFields(BindingFlags.Instance | BindingFlags.NonPublic);
        System.Drawing.Printing.PageSettings ps = new System.Drawing.Printing.PageSettings();
        ps.Landscape = true;

       // ps.PaperSource=
        foreach (FieldInfo item in pr)
        {
            if (item.Name == "m_pageSettings")
            {
                item.SetValue(reportViewer1, ps);

            }
        }
A: 

You need to set the report size in the report definition. Here is someone with the same problem:

http://forums.asp.net/t/1138481.aspx

Shiraz Bhaiji
A: 

Best way is to pass DeviceInformation during the render of the export.

Check out http://msdn.microsoft.com/en-us/library/ms154682.aspx

You can pass the PageHeight and PageWidth as DeviceInformation, so you can specify 8.5x11 for your landscape format.

Code example below:

Dim warnings As Warning() = Nothing
Dim streamids As String() = Nothing
Dim mimeType As String = Nothing
Dim encoding As String = Nothing
Dim extension As String = Nothing
Dim bytes As Byte()
Dim deviceInf as String

deviceInf = "<DeviceInfo><PageHeight>8.5in</PageHeight><PageWidth>11in</PageWidth></DeviceInfo>"

bytes = ReportViewer1.LocalReport.Render("PDF", deviceInf, mimeType, encoding, extension, streamids, warnings)
Dim fs As New FileStream(FILENAME, FileMode.Create)
fs.Write(bytes, 0, bytes.Length)
fs.Close()
Jon