주의 : image, pdf 는 모두 Server 에 저장됩니다. 사용자가 다운을 받으면서 pdf 로 받는 방법은 aspx 페이지의 header 를 설정해서 받는 방법이 있습니다.
HTML 을 PDF 로 변환하는 exe 를 이용해서 작업을 하게됐다.
ASP.NET_WebBrowser_HTMLtoPDF.zip
1.
http://wkhtmltopdf.org/ 사이트에서 각 시스템에 맞는 설치 파일을 깐다.
아니면, 소스를 받아서 컴파일을 한다.
현재 64bit 의 설치 파일을 다음과 같다.
wkhtmltox-0.12.1.2_msvc2013-win64.exe
2.
VS 2012 소스이고, aspx 페이지에는 아무 것도 기술되지 않는다.
그냥 아무렇게나 aspx 페이지 하나 만들면 된다.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="ASP.NET_WebBrowser._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>제목 없음</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
3.
cs 단에는 다음과 같이 기술한다.
using System;
using System.Web;
//add
using System.Diagnostics;
namespace ASP.NET_WebBrowser
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string sRootPath = Server.MapPath("/");
ProcessStartInfo processStartInfo = new ProcessStartInfo();
processStartInfo.FileName = sRootPath + @"wkhtmltopdf.exe";
//processStartInfo.Arguments = "http://google.com " + s + @"google.pdf";
processStartInfo.Arguments = "http://naver.com " + sRootPath + @"naver.pdf";
Process.Start(processStartInfo);
}
}
}
- 우선 테스트를 각 사이트의 root 에 해당하는 곳에 wkhtmltopdf.exe 를 copy 한다.
1) wkhtmltopdf.exe 는 wkhtmltopdf 설치 한 후에 C:\Program Files\wkhtmltopdf 에 위치하니 복사하면 되겠다.
- Default.aspx 를 호출하면 사이트 root 에 naver.pdf 가 생성된다.