Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 42334

Merge rdlc's rendered as pdf in ActionResult

$
0
0
I have an ActionResult that returns a FileContentResult that is working fine.

c# Code:
  1. [AllowAgencyUser]
  2.         public ActionResult TrainingHours(int id)
  3.         {
  4.             EmployeeModel model = new EmployeeModel(id);
  5.             if (!model.CheckEmployeeAccess())
  6.                 throw new HttpException(403, "Access Denied");
  7.  
  8.             byte[] report = model.GetTrainingHoursReport(id);
  9.             return File(report, Constants.PdfMimeType, model.EmployeeHoursReportFileName);
  10.         }

byte[] report is returning LocalReport.Render("PDF", deviceInfo) of an rdlc.

The customer has requested a button on the page where they can get a whole bunch of these reports merged into 1 file.

c# Code:
  1. [AllowAgencyUser]
  2.         public ActionResult MassTrainingHours(int[] employeeIds)
  3.         {
  4.             if (employeeIds == null)
  5.                 return new EmptyResult();
  6.  
  7.             List<byte[]> reportsList = new List<byte[]>();
  8.             foreach (int employeeId in employeeIds)
  9.             {
  10.                 EmployeeModel model = new EmployeeModel(employeeId);
  11.                 byte[] fileBytes = model.GetTrainingHoursReport(employeeId);
  12.                 reportsList.Add(model.GetTrainingHoursReport(employeeId));
  13.             }
  14.             PdfMerger merger = new PdfMerger();
  15.             byte[] report = merger.MergeFiles(reportsList);
  16.             return File(report, Constants.PdfMimeType, "training_hours.pdf");
  17.         }

The merge files method:

c# Code:
  1. public byte[] MergeFiles(List<byte[]> inputFiles)
  2.         {
  3.             MemoryStream outputMS = new MemoryStream();
  4.             Document document = new Document();
  5.             PdfCopy writer = new PdfCopy(document, outputMS);
  6.             PdfImportedPage page = null;
  7.  
  8.             document.Open();
  9.  
  10.             foreach (byte[] fileData in inputFiles)
  11.             {
  12.                 PdfReader reader = new PdfReader(fileData);
  13.                 int n = reader.NumberOfPages;
  14.  
  15.                 for (int i = 1; i <= n; i++)
  16.                 {
  17.                     page = writer.GetImportedPage(reader, i);
  18.                     writer.AddPage(page);
  19.                 }
  20.  
  21.                 PRAcroForm form = reader.AcroForm;
  22.                 if (form != null)
  23.                     writer.CopyAcroForm(reader);
  24.             }
  25.  
  26.             document.Close();
  27.  
  28.             return outputMS.ToArray();
  29.         }

The problem is that no file is downloaded at all.

Everything seems to be working properly, I can step through the code all the way through returning the FileContentResult with no problems.

Anyone have any ideas as to what's wrong with the way I'm trying to do this or have a different approach to merging the files?

Viewing all articles
Browse latest Browse all 42334

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>