12

I am rendering an HTML View in ASP.Net MVC to PDF using Rotativa ViewAsPdf method. I am setting the ouput to be of A4 Size, Portrait and no margins, by setting:

new ViewAsPdf(MVCCfpFormatter.Members.Views.FlightPlansFullPagePrint, model)
                    {
                       // FileName = flightPlan.ListingItemDetailsModel.FlightDetails + ".pdf",
                        PageSize = Size.A4,
                        PageOrientation = Orientation.Portrait,
                        PageMargins = new Margins(0, 0, 0, 0),
                        PageWidth = 210,
                        PageHeight = 297
                    };

Then within the CSS, I am setting an element to have 210mm width, which should spread the entire width of the page, yet in the output PDF, the 210mm width is not representing the entire width of the PDF but less. By trial and error, the total width of the generated PDF seems to be around 246mm.

Any ideas why this could be happening?

Mark Cassar
  • 1,842
  • 4
  • 20
  • 27

4 Answers4

13

If you are still having issues ive done more research on rotativa. You can use custom switches from wkhtmltopdf. Try and add

CustomSwitches = "--disable-smart-shrinking". 

That stops the program from auto resizing your things. From there you can adjust your html page correctly to get the size you want on the pdf.

user2612373
  • 181
  • 3
5

I think I can help you out.

 {
               FileName = Name + ".pdf",
               PageOrientation = Rotativa.Options.Orientation.Landscape,
               PageSize = Rotativa.Options.Size.A4

 }

Is what works for me with 1.6.3. Id imagine you would need to follow that syntax to set the other things you want.

user2612373
  • 181
  • 3
  • What do you mean? Isn't that the same syntax like I have showed above, just using the full namespace, `Rotativa.Options...` ? – Mark Cassar Jul 11 '14 at 11:58
  • Yes it is, what I meant was I could not get mine to work correctly without using the full namespace. If that does not help fix your problem it sounds like it may be in your CSS? – user2612373 Jul 11 '14 at 23:28
  • My full namespaces where including using the `using` keywords at the top which I didn't include here. When you managed to try yours, did it work out perfectly with the correct given dimensions? – Mark Cassar Jul 14 '14 at 08:23
  • Yeah it works very well. Maybe just try set the pagesize like I did and see what you get? I have not tried to print out a pdf yet, but in reader it formats perfectly. – user2612373 Jul 15 '14 at 22:04
  • You did the same thing as I did @user2612373 so it will output the same results. Can you please try it out with exact correct dimensions like I asked in my question before? – Mark Cassar Jul 17 '14 at 10:51
  • After experimenting with my own pdf render problem I think I may know. Have you tried setting the Pagesize with no dimeions? or just the width and height? When you specify the page size it has default dimensions it uses. By setting a width and height as well it may be stuffing with it. I am also having trouble trying to fit it all onto one page. – user2612373 Aug 07 '14 at 12:25
0

if you are using mvc 4 ,should use this format

         public ActionResult yourAction()
      {

       var yourModel;


        var yourpdf= new PartialViewAsPdf(yourModel)
        {
            RotativaOptions = new DriverOptions()
            {
                PageOrientation=Orientation.Landscape,
                PageSize = Size.A4,
                IsLowQuality=true
                and other your Customiz

            }
        };
        return yourpdf;

    }
0

for MVC before any thing don't forget to add

using Rotativa.MVC;
using Rotativa;

and for using customizing option do like this

  return new ActionAsPdf
                ("ActionName")
                {
                    FileName = "Filename.pdf",
                    RotativaOptions = new Rotativa.Core.DriverOptions()
                    {
                        PageSize=Rotativa.Core.Options.Size.A4,
                    }
                   
                };
Miad BayaniRad
  • 66
  • 1
  • 11