Create a PDF file on server using FastReport.NET

I am using FastReport.NET version 2021.4.8. I would like to create a report PDF file, give it a name, and save it to the Temp folder on the server. This will allow me to pop it open to display to the user. Can this be done and if so, can you give me some guidance on how to code it?

Thanks,

Ramon Weston

Comments

  • What I have been doing is to create the Report on the server using a WebReport object and then use PDFSimple (FastReport.OpenSource.Export.PdfSimple) to create and save the PDF file to the server drive.


            WebReport webReport = GetWebReport(ReportData, reportDef);

            _webReport.Report.Prepare();

            using (MemoryStream ms = new MemoryStream())

            {

              PDFSimpleExport pdfExport = new PDFSimpleExport();

              pdfExport.Export(_webReport.Report, ms);


              string dir_path = <<YOUR PATH>>;

              bool exists = System.IO.Directory.Exists(dir_path);

              if (!exists)

              {

                Logger.Information($"Creating directory {dir_path}");

                // This throws an exception if it fails

                System.IO.Directory.CreateDirectory(dir_path);

              }


              string filename = Path.Combine(dir_path, FileName ?? $"{ReportName}.pdf");

              exists = System.IO.File.Exists(filename);

              using (FileStream file = new FileStream(filename, FileMode.Create, FileAccess.Write))

              {

                ms.WriteTo(file);

                file.Close();

                ms.Flush();

              }

            }

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.