Sdp
Sdp

Reputation: 192

Render a report to pdf

i have a c# code that renders a report into pdf form.

         Random rand = new Random();
         num = rand.Next(1111, 999999);
        Warning[] warnings;
        string[] streamids;
        string mimeType;
        string encoding;
        string extension;
        String deviceInf = "<DeviceInfo><PageHeight>8.27in</PageHeight><PageWidth>11.69in</PageWidth><MarginTop>0in</MarginTop><MarginBottom>0in</MarginBottom><MarginLeft>0in</MarginLeft><MarginRight>0in</MarginRight></DeviceInfo>";
        byte[] bytes = reportViewer1.LocalReport.Render
            (
           "PDF", deviceInf, out mimeType, out encoding,
            out extension,
           out streamids, out warnings);

        var folderPath = "D:\\ICard\\STAFFPDF\\";
        if (!Directory.Exists(folderPath))
        {
            Directory.CreateDirectory(folderPath);
        }

        FileStream fs = new FileStream(@"D:\ICard\STAFFPDF\" + num + ".pdf", FileMode.Create);
        fs.Write(bytes, 0, bytes.Length);
        this.reportViewer1.Refresh();
        fs.Close();

What i am trying to do is save the pdf in a mirror form because the pdf needs to be printed as mirror image, is there any way i can achieve this ?

Upvotes: 1

Views: 3199

Answers (1)

Ria Sen
Ria Sen

Reputation: 94

Try this piece of code. Source is here.

 private string ExportReport()
            {
                Warning[] warnings;
                string[] streamids;
                string mimeType;
                string encoding;
                string filenameExtension;


            ReportParameterInfoCollection pInfo = reportViewer1.ServerReport.GetParameters();
            string filenameParams = "";


            byte[] bytes;
            if (reportViewer1.ProcessingMode == ProcessingMode.Local)
            {
               bytes = reportViewer1.LocalReport.Render("PDF", null, out mimeType,
                out encoding, out filenameExtension, out streamids, out warnings);
            }
            else
            {
               bytes = reportViewer1.ServerReport.Render("PDF", null, out mimeType,
                out encoding, out filenameExtension, out streamids, out warnings);
            }


            string filename = Path.Combine(Path.GetTempPath(), filenameParams + ".pdf");
            using (FileStream fs = new FileStream(filename, FileMode.Create))
            { fs.Write(bytes, 0, bytes.Length); }


            return filename;
        }

Upvotes: 1

Related Questions