본문 바로가기
HTML

asp.net 에서 html 문서 pdf 파일 변환해서 다운로드하기

by JUNG-2503 2024. 2. 22.

asp 환경에서 무료 콤포넌트를 사용해서 asp.net 에서 html 문서를 pdf 다운로드하는 방법

 

1.http://selectpdf.com/ 사이트에서 SelectPdf-HtmlToPdf-v2.3.0.zip 다운로드하기

 

2. 다운 받은 파일 중 아래 파일을 웹서버(IIS) /Bin 폴더에 복사하기

 

ColorCode.dll

Select.HtmlToPdf.dll

Select.HtmlToPdf.xml

Select.Html.dep

 

3. 참고문서

https://code.msdn.microsoft.com/Convert-from-HTML-to-PDF-09ce2a1d

http://selectpdf.com/community-edition/

 

4. 다운로드 링크

http://selectpdf.com/free-downloads/

 

5. 작업 소스

사용방법은 아래 aspx 파일 링크를 클릭하면 자동으로 다운로드 됨...

 

pdf.aspx

--------------

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="pdf.aspx.cs" Inherits="_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> pdf download </title>

</head>

<body>

    <form id="form1" runat="server">

    </form>

</body>

</html>

 

--------------

 

pdf.aspx.cs

--------------

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using SelectPdf;

using ColorCode;

 

public partial class _Default : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

// instantiate a html to pdf converter object

HtmlToPdf converter = new HtmlToPdf();

 

// create a new pdf document converting an url

PdfDocument doc = converter.ConvertUrl("http://aaa.co.kr/convert_pdf.asp?idx=" + Request["id"]);

 

//Request["id"]

// 1024 px

 

// save pdf document

doc.Save(Response, false, "Transcript_" + Request["id"] + ".pdf");

 

// close pdf document

doc.Close();

}

}

 

--------------

반응형