Click here to Skip to main content
15,895,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am writing an application that creates checks on 8.5 x 7" tractor feed paper. I am developing the app on vs2012 and it is an mvc 4 app with users printing checks on their client side printers. I am rendering the report output to PDF.

The problem that I am having is that when I render the checks, they print in landscape because width > height. So after reading many posts, I have tried the work around which is to create a square report page of 8.5 x 8.5" and not use the bottom 1.5". When I render this, it prints in portrait mode, but instead of getting the required 8.5 x 7 layout, I am getting a 8.5 x 8.5.

To be more specific about my report layout - here are more details:
Report page size = 8.5 x 8.5
Interactive page size = 8.5 x 8.5
Page margins: .25 top, bottom, right, left
Body size: 8 x 6.5
All report items fit within the body.


Can someone please tell me how to do this?

Thanks

Here is my controller code:
C#
[HttpGet]
       public ActionResult TestReport()
       {
           Ui_ProcessRoyaltyChecks ui = new Ui_ProcessRoyaltyChecks();
           return View(ui);
       }

       [HttpPost]
       public ActionResult TestReport(Ui_ProcessRoyaltyChecks ui)
       {
           string id = ui.SelectedReportFormat;

           var unprintedOwnerChecks = (from upc in context.OilGasCheckRegistries
                                       join or in context.GasRoyalties on upc.PaymentId equals or.PaymentId
                                       join p in context.Payees on upc.OwnerNum equals p.VendorNum
                                       orderby upc.CheckNum ascending
                                       select new
                                       {
                                           upc.PaymentId,
                                           upc.PaidDate,
                                           or.Yyyy,
                                           or.Mm,
                                           upc.AmtPaid,
                                           upc.OwnerName,
                                           upc.OwnerNum,
                                           upc.CheckNum,
                                           upc.CheckWords,
                                           or.IncomeTax,
                                           or.AmountOwed,
                                           p.Address,
                                           p.AddressContd,
                                           p.City,
                                           p.State,
                                           p.Zip
                                       }).AsEnumerable();

           LocalReport lr = new LocalReport();

           // string path = Path.Combine(Server.MapPath("~/Reports"), "GasRoyaltyChecksReport.rdlc");
           string path = Path.Combine(Server.MapPath("~/Reports"), "TestReport.rdlc");
           if (System.IO.File.Exists(path))
           {
               lr.ReportPath = path;
           }
           else
           {
               return View(ui);
           }


           if (unprintedOwnerChecks == null)
           {
               return View(ui);
           }


           ReportDataSource datasource = new ReportDataSource("DataSet_GasRoyaltyChecks", unprintedOwnerChecks);
           lr.DataSources.Clear();
           lr.DataSources.Add(datasource);

           string reportType = id;
           string mimeType;
           string encoding;
           string fileNameExtension;
           //The DeviceInfo settings should be changed based on the reportType
           //http://msdn2.microsoft.com/en-us/library/ms155397.aspx
           string deviceInfo =
           "<DeviceInfo>" +
           "  <OutputFormat>" + id + "</OutputFormat>" +
           "  <Orientation>Portrait</Orientation>" +
           "  <PageWidth>8.5in</PageWidth>" +
           "  <PageHeight>8.5in</PageHeight>" +
           "  <MarginTop>0.25in</MarginTop>" +
           "  <MarginLeft>0.25in</MarginLeft>" +
           "  <MarginRight>0.25in</MarginRight>" +
           "  <MarginBottom>0.25in</MarginBottom>" +
           "</DeviceInfo>";

           Warning[] warnings;
           string[] streams;
           byte[] renderedBytes;

           //Render the report
           renderedBytes = lr.Render(
               reportType,
               deviceInfo,
               out mimeType,
               out encoding,
               out fileNameExtension,
               out streams,
               out warnings);

           return File(renderedBytes, mimeType);
       }
Posted
Updated 18-Feb-15 0:11am
v3

1 solution

I found the solution to this finally.

This solution specifically applies to my case where I have an mvc app without the reportviewer control. I did not want to use the reportviewer which would have meant that I would have to add non aspx mvc pages to my app - yuck. So, my app uses pure rdlc - no report viewer. Hopefully MS will support the report viewer in MVC.

Solution:
I set my report page size in rdlc to 8.5w x 7h. I know that rdlc thinks this is landscape but it does not matter because the rdlc does not make the final determination on how the report prints... it is the print driver settings that determine this. On the client machine printer preferences, I created a new form that is 8.5x7. When I print the report on this printer using this form, it orients the paper correctly as portrait and it looks good.

I hope that this helps someone else.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900