nuget 에서 iTextSharp 검색해여 "iTextSharp" 를 설치하면 iTextSharp 이 참조됩니다.
참고로 4.1.6 버전까지는 상용제품에 포함하는데 문제는 없습니다.
Version 5.0.0 and up is licensed under the AGPL (strong copyleft).
Version 4.1.6 and previous are still licensed under the MPL/LGPL (weak copyleft).
이를 설치하기 위에 nuget 의 command 에 실행합니다. 어려우시면 iTextSharp.zip 파일을 다운로드 받으세요.
Install-Package iTextSharp-LGPL
코드 시작~~
using iTextSharp.text; using iTextSharp.text.pdf; public ActionResult Sample() { string jpgfile = @"c:\users\lucks\documents\visual studio 2015\Projects\WebApplication2\WebApplication2\사이즈조절.PNG"; string pdf = @"c:\users\lucks\documents\visual studio 2015\Projects\WebApplication2\WebApplication2\sample.pdf"; ConvertJPG2PDF(jpgfile, pdf); return View(); } void ConvertJPG2PDF(string jpgfile, string pdf) { var document = new Document(iTextSharp.text.PageSize.A4, 25, 25, 25, 25); using (var stream = new FileStream(pdf, FileMode.Create, FileAccess.Write, FileShare.None)) { PdfWriter.GetInstance(document, stream); document.Open(); using (var imageStream = new FileStream(jpgfile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { var image = Image.GetInstance(imageStream); if (image.Height > iTextSharp.text.PageSize.A4.Height - 25) { image.ScaleToFit(iTextSharp.text.PageSize.A4.Width - 25, iTextSharp.text.PageSize.A4.Height - 25); } else if (image.Width > iTextSharp.text.PageSize.A4.Width - 25) { image.ScaleToFit(iTextSharp.text.PageSize.A4.Width - 25, iTextSharp.text.PageSize.A4.Height - 25); } image.Alignment = iTextSharp.text.Image.ALIGN_MIDDLE; document.Add(image); } document.Close(); } }
'닷넷관련 > ASP.NET MVC & Core' 카테고리의 다른 글
ASP.NET MVC 의 Controller 에 put, delete 작동 안 될 경우 (web api 도 포함) (0) | 2016.05.17 |
---|---|
ASP.NET MVC 의 razor 에 c# 구문과 문자열 구별처리 하기 (0) | 2016.05.16 |
image to pdf 를 iTextSharp 로 개발하기 (1) | 2016.05.12 |
asp.net mvc 의 post 배열 방식으로 전송 및 받기 (0) | 2016.05.11 |
Visual Studio 2015 에서 razor Intellisense 인텔리센스 안될 경우 (0) | 2016.04.27 |
global.asax 에서 http 및 www 여부 분기 체크 (0) | 2016.04.19 |
안녕하세요. 글 잘읽었습니다.
MVC에서 그리드를 PDF로 저장하려는데요,
Server-Side측 코드는 저렇게 구현한다면, Client-Side측 코드는 어떻게 선언하고 받아서 저장하는건지 궁금합니다..