Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Report Viewer Landscape pdf export

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);

            }
        }
like image 286
Jeffrey Avatar asked Jul 04 '09 05:07

Jeffrey


2 Answers

In Design View of your report (rdlc) select report and in the properties pane set the following items in page size

width :11in
height :8.5in
like image 92
Farzin Zaker Avatar answered Sep 28 '22 18:09

Farzin Zaker


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()
like image 27
jgallant Avatar answered Sep 28 '22 18:09

jgallant