PDF を生成して画面に表示したり、ユーザーがアクセスしやすい場所に保存したりできる必要がある ASP.Net MVC アプリを作成しています。ドキュメントの生成には PdfSharp を使用しています。完了したら、ユーザーがドキュメントを保存したり、リーダーで開いたりするにはどうすればよいでしょうか? PDFはサーバー側で生成されますが、クライアント側で表示したいので、特に混乱しています。
これまでに作成したレポートを作成するための MVC コントローラーは次のとおりです。
public class ReportController : ApiController
{
private static readonly string filename = "report.pdf";
[HttpGet]
public void GenerateReport()
{
ReportPdfInput input = new ReportPdfInput()
{
//Empty for now
};
var manager = new ReportPdfManagerFactory().GetReportPdfManager();
var documentRenderer = manager.GenerateReport(input);
documentRenderer.PdfDocument.Save(filename); //Returns a PdfDocumentRenderer
Process.Start(filename);
}
}
これを実行すると、行が実行UnauthorizedAccessException
されたときに何が起こるかわかりません。documentRenderer.PdfDocument.Save(filename);
Access to the path 'C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer\10.0\report.pdf' is denied.
Process.Start(filename);
のコードは次のmanager.GenerateReport(input)
とおりです。
public class ReportPdfManager : IReportPdfManager
{
public PdfDocumentRenderer GenerateReport(ReportPdfInput input)
{
var document = CreateDocument(input);
var renderer = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.Always);
renderer.Document = document;
renderer.RenderDocument();
return renderer;
}
private Document CreateDocument(ReportPdfInput input)
{
//Put content into the document
}
}