Как мне преобразовать один файл cshtml в pdf, используя pechkin и wkhtml2pdf?
Я пытаюсь конвертировать Cshtml файл в PDF. Мой код правильно создает файл pdf, но он всегда пуст. Я действительно плохо знаком с бритвой, так что это моя первая попытка.
public static void ConvertToPdf()
{
GlobalConfig gc = new GlobalConfig();
gc.SetMargins(new Margins(300, 100, 150, 100))
.SetDocumentTitle("My document")
.SetPaperSize(PaperKind.Letter);
IPechkin pechkin = new SimplePechkin(gc);
ObjectConfig oc = new ObjectConfig();
var sourceFile = @"pathtofile\test.cshtml";
oc.SetAllowLocalContent(true)
.SetPageUri(@"file:///" + sourceFile);
byte[] pdfContent = pechkin.Convert(oc);
var fileDestination = @"destinationLocation\myFile.pdf";
FileStream fileStream = new FileStream(fileDestination, FileMode.Create, FileAccess.Write);
fileStream.Write(pdfContent, 0, pdfContent.Length);
fileStream.Close();
}
Мой тестовый файл cshtml выглядит так:
@using System;
@using System.Collections.Generic;
namespace MRMS.HTML
{
class test
{
}
}
<html>
<body>
<h5>some text here</h5>
</body>
</html>