2013-03-06 18 views
6

Rotativa kitaplığı tarafından oluşturulan PDF'de üstbilgileri ve altbilgileri belirtmeye çalışıyorum. Yazar, here nolu yanıtı verdiğinde, CSS kullanılarak (here tarif edilmiştir) mümkün olmalıdır. Ancak, bunu yapamam.Rotativa tarafından oluşturulan PDF'de üstbilgileri ve altbilgileri görüntüleme

Ben meta etiketinde yüklü bir stil var:

<link href="print.css" rel="stylesheet" type="text/css" media="print" /> 

Ve altta stil:

public ActionResult ShowPdf() 
{ 
    var model = new Model(); 
    return new ViewAsPdf("view.cshtml", model) 
       { 
        FileName = "Report.pdf", 
        CustomSwitches = "--print-media-type" 
       }; 
} 

Ve:

@page { 
    @top-left { 
     content: "TOP SECRET"; 
     color: red 
    } 
    @bottom-right { 
     content: counter(page); 
     font-style: italic 
    } 
} 

Ve o zamana kadar üreten PDF sonra hiçbir şey PDF'nin üstbilgisinde ve altbilgisinde görünür. Herhangi bir fikir?

cevap

8

Bir documentation of wkhtmltopdf buldum ve orada üstbilgileri ve altbilgileri nasıl yönetileceği açıklanmıştır.

Temel olarak argüman listesine --header-center "text" (veya benzeri anahtarlar) ekleyebilirsiniz ve hepsi budur.

Yani rotativa ile kullanmaya olurdu:

public ActionResult ShowPdf() 
{ 
    var model = new Model(); 
    return new ViewAsPdf("view.cshtml", model) 
       { 
        FileName = "Report.pdf", 
        CustomSwitches = "--print-media-type --header-center \"text\"" 
       }; 
} 

(. --print-media-type gerekli olup olmadığını bilmiyorum)

+0

Sadece test edilmiş ve size ihtiyacım yok ' --print-media-type ' – Kendrome

5

başlıkta metin yerine Görünüm görüntülemek isteseydik/böyle yapabilirsiniz sonra altbilgim:

public ActionResult ViewPDF() 
{ 
     string customSwitches = string.Format("--print-media-type --allow {0} --footer-html {0} --footer-spacing -10", 
       Url.Action("Footer", "Document", new { area = ""}, "https")); 


    return new ViewAsPdf("MyPDF.cshtml", model) 
       { 
        FileName = "MyPDF.pdf", 
        CustomSwitches = customSwitches 
       }; 
} 

[AllowAnonymous] 
public ActionResult Footer() 
{ 
    return View(); 
} 

aksi Rotatina yoluna erişim elde edemez Altbilgi eylemi [AllowAnonymous] öznitelik eklemek unutmayın.

+0

' http 'için değiştirmek zorunda kaldım ama güzel çalışıyor. Paylaşım için teşekkürler! – joetinger

-1

(tam olarak) nasıl yaptığımı

İşte
2

olan bu% 100

return new ViewAsPdf("MyPDF.cshtml", model) 
      { 
       FileName = "MyPDF.pdf", 
       CustomSwitches = customSwitches 
      }; 

} çalışacak denemek:

public ActionResult PrintPDF(int? selectedSiteRotaId, int selectedSiteId) 
{ 
    string footer = "--footer-center \"Printed on: " + DateTime.Now.Date.ToString("MM/dd/yyyy") + " Page: [page]/[toPage]\"" + " --footer-line --footer-font-size \"9\" --footer-spacing 6 --footer-font-name \"calibri light\""; 

    return new ActionAsPdf("RenderPDF", new { selectedSiteRotaId = selectedSiteRotaId, selectedSiteId = 7 }) 
    { 
     FileName = "PDF_Output.pdf", 
     PageOrientation = Orientation.Landscape, 
     MinimumFontSize = 10, 
     //PageMargins = new Margins(5,5,5,5), 
     PageSize = Size.A3, 
     CustomSwitches = footer 
    }; 

    //var pdfResult = new ActionAsPdf("RenderPDF", new { selectedSiteRotaId = selectedSiteRotaId, selectedSiteId = 7 }) 
    //{ 
    // FileName = "PDF_Output.pdf", 
    // PageOrientation = Orientation.Landscape, 
    // MinimumFontSize = 10 
    //}; 

    //var binary = pdfResult.BuildPdf(this.ControllerContext); 

    //return File(binary, "application/pdf"); 
} 


public ActionResult RenderPDF(int? selectedSiteRotaId, int selectedSiteId) 
{ 
    return RedirectToAction("Index", "PrintPDF", new { selectedSiteRotaId = selectedSiteRotaId, selectedSiteId = 7 }); 
} 
İlgili konular