는 MVC의 행동에 자신의 안녕 세계 예를 반환 Report.NET 코드를 사용한다 :
이
public void MyPDFAction()
{
Root.Reports.Report report = new Root.Reports.Report(new PdfFormatter());
FontDef fd = new FontDef(report, "Helvetica");
FontProp fp = new FontPropMM(fd, 25);
Page page = new Page(report);
page.AddCB_MM(80, new RepString(fp, "Hello World!"));
RT.ViewPDF(report, "HelloWorld.pdf");
}
작업의 반환 형식이 void Report.NET 코드는 응답을 직접 업데이트하므로 기본적으로 void 동작에 대해 반환됩니다. 이것은 브라우저에서 직접 PDF 뷰어를 엽니 다. System.Web.UI 처리하는 일에 찬성되지 않는 것으로 응답을 얻으려면
그러나이 방법이 표시되어
RT.ResponsePDF(report, System.Web.HttpContext.Current.Response);
와 RT.ViewPDF 라인을 교체하지 않고 다운로드보다 페이지로 반환 .페이지. 불행히도 MVC 응용 프로그램의 컨텍스트에서 Page 객체를 다루는 방법을 모르겠습니다.
Report.NET을 다운로드하여 PDF 파일 다운로드를 시작하지 못했습니다.
Report.NET here 다운로드
PDFSharp 최근에 Report.NET보다 유지 관리 된 것 같습니다. MIT 라이센스하에도 제공됩니다. here에서 다운로드 할 수 있습니다. 많은 예제가있는 광범위한 wiki도 있습니다. 그것이 제공으로 MigraDoc 체크 아웃 잘 가치,
[HttpGet]
public ActionResult MyPdfAction()
{
using (MemoryStream stream = new MemoryStream())
{
PdfDocument document = new PdfDocument();
PdfPage page = document.AddPage();
XGraphics gfx = XGraphics.FromPdfPage(page);
XFont font = new XFont("Verdana", 20, XFontStyle.Bold);
gfx.DrawString("Hello, World!", font, XBrushes.Black, new XRect(0, 0, page.Width, page.Height), XStringFormats.Center);
document.Save(stream, false);
return File(stream.ToArray(), "application/pdf", "HelloWorld.pdf");
}
}
또 다른 편집 당신이 테이블에 주로 텍스트 기반 문서를 생산하는 흥미로운 경우 :
기본 코드는 MVC에서 다운로드 할 파일을 반환 PDFSharp 프리미티브 위에 유용한 추상화 레이어. MigraDoc은 PDFSharp 다운로드에 포함되어 있습니다. PDFSharp, PDFSharp.Charting, MigraDoc.DocumentObjectModel 및 MigraDoc.Rendering 프로젝트를 프로젝트에 추가하여 모든 작업을 수행해야합니다.
코드는 여기에서 다운로드 할 PDF를 생성 :
[HttpGet]
public ActionResult MyPdfAction()
{
using (MemoryStream stream = new MemoryStream())
{
Document document = CreateDocument();
document.UseCmykColor = true;
const bool unicode = false;
const PdfFontEmbedding embedding = PdfFontEmbedding.Always;
PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(unicode, embedding);
pdfRenderer.Document = document;
pdfRenderer.RenderDocument();
pdfRenderer.PdfDocument.Save(stream, false);
return File(stream.ToArray(), "application/pdf", "HelloWorld.pdf");
}
}
/// <summary>
/// Creates an absolutely minimalistic document.
/// </summary>
static Document CreateDocument()
{
Document document = new Document();
Section section = document.AddSection();
Paragraph paragraph = section.AddParagraph();
paragraph.Format.Font.Color = Color.FromCmyk(100, 30, 20, 50);
paragraph.AddFormattedText("Hello, World!", TextFormat.Bold);
return document;
}
요약 내가 PDFSharp/MigraDoc을 사용하고, C# MVC를위한 PDF 솔루션의 숫자 바라 보았다 가졌어요. iTextSharp 및 프로젝트를 기반으로 프로젝트를 할인했습니다. 왜냐하면 상업적으로 사용하는 경우 비용이 많이 드는 라이센스 비용 때문입니다 (제 경우에는 2500 유로). Report.NET은 ASP.NET 클래식을 염두에두고 개발되었으며 2006 년부터 업데이트를받지 못했습니다.
중복 : http://stackoverflow.com/questions/779430/asp-net-mvc-how-to-get -view-to-generate-pdf –
보기에서 PDF를 생성하지 않으므로 동일한 질문이 아닙니다. – hminaya
@hminaya : http://stackoverflow.com/questions/1244109/generating-pdf-file-in-net –