static void Main(string[] args) { // Initialize the engine Report.Init(); // Open template file and create output file FileStream template = File.OpenRead("../../../Samples/JSON - Template.docx"); FileStream output = File.Create("../../../Samples/Report.pdf"); // Create report process Report myReport = new ReportPdf(template, output); // Connect to our JSON database IReportDataSource data = new JsonDataSourceImpl("http://json.windward.net/Northwind.json", JsonDataSourceImpl.MODE.CONNECTION_STRING); // Run the report process myReport.ProcessSetup(); // The second parameter is "" to tell the process that our data is the default data source myReport.ProcessData(data, ""); myReport.ProcessComplete(); // Close out of our template file and output output.Close(); template.Close(); // Opens the finished report string fullPath = Path.GetFullPath("../../../Samples/Report.pdf"); System.Diagnostics.Process.Start(fullPath); }
protected void Page_Load(object sender, EventArgs e) { string basePath = Request.PhysicalApplicationPath + "\\"; // Initialize the engine. License and configuration settings in web.config. Report.Init(); // Open template file FileStream template = File.OpenRead(basePath + "JSON - Template.docx"); // Create report process Report myReport = new ReportPdf(template); // Open data file WebClient client = new WebClient(); Stream Json = client.OpenRead("http://json.windward.net/northwind.json"); // Make a data object to connect to our xml file IReportDataSource data = new JsonDataSourceImpl(Json); // Run the report process myReport.ProcessSetup(); // The second parameter is "" to tell the process that our data is the unnamed data source myReport.ProcessData(data, ""); myReport.ProcessComplete(); // Close out of our template file template.Close(); Json.Close(); // Opens the finished report //Response.ContentType = "application/pdf"; // this would have the pdf open in the browser (disable content-disposition:attachment if you want this) Response.ContentType = "application/save"; // this is used with content-disposition to give the proper name of the file Response.AppendHeader("content-disposition", "attachment; filename=\"Report.pdf\""); Response.BinaryWrite(((MemoryStream)myReport.GetReport()).ToArray()); Response.End(); // Must be called for MS Office documents }