• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 493
  • Last Modified:

Generate pdf from microsoft report

Hi all,

I'm able to create a report with a dataset with 2 datatables in it.
Now I want to auomaticly save that report to a PDF file somewhere...

How can I do this?
Below the code on how I create my report...

_DsDoc = _localReport.ReportsDocument(document_id);
  this.ReportDocumentBindingSource.DataSource = _DsDoc;
  this.ReportDocument1BindingSource.DataSource = _DsDoc;

Open in new window

1 Solution
Something like below
using System.IO;
Next, we only need a few lines of code to generate the PDF.
      Warning[] warnings;
      string[] streamids;
      string mimeType;
      string encoding;
      string extension;
      byte[] bytes = reportViewer1.LocalReport.Render(
        "PDF", null, out mimeType, out encoding, out extension,
        out streamids, out warnings);
      FileStream fs = new FileStream(@"D:\ReportOutput.pdf", FileMode.Create);
      fs.Write(bytes, 0, bytes.Length);

Open in new window

Pit76Author Commented:
Thx man, that works!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now