재우니의 블로그


무료 Html to Pdf Converter For .NET (ASP.NET, MVC, Windows Forms)


http://selectpdf.codeplex.com/


SelectPdf HTML을 PDF 파일로 변환 - Community Edition은 .NET에 대한 완전한 기능을 갖춘 PDF 라이브러리 Select.Pdf에서 찾을 수 있습니다 .NET 용 PDF 변환기에 강력한 html로의 무료 버전입니다. SelectPdf는 모든 윈도우 시스템 및 윈도우 Azure에서 작동합니다. PDF 변환기에 HTML은 모든 .NET 응용 프로그램에서 무료로 사용할 수 있습니다. 그것은 HTML5, CSS3, 자바 스크립트 웹 페이지를 지원합니다. 변환은 5 페이지의 문서에 무료 버전으로 제한됩니다.

html to Pdf Converter For .NET - Community Edition Features

  • Generate pdf documents up to 5 pages
  • Convert any web page to pdf
  • Convert any raw html string to pdf
  • Set pdf page settings (page size, page orientation, page margins)
  • Resize content during conversion to fit the pdf page
  • Set pdf document properties
  • Set pdf viewer preferences
  • Set pdf security (passwords, permissions)
  • Set conversion delay and web page navigation timeout
  • Custom headers and footers
  • Support for html in headers and footers
  • Automatic and manual page breaks
  • Repeat html table headers on each page
  • Support for @media types screen and print
  • Support for internal and external links
  • Generate bookmarks automatically based on html elements
  • Support for HTTP headers
  • Support for HTTP cookies
  • Support for web pages that require authentication
  • Support for proxy servers
  • Enable/disable javascript
  • Modify color space
  • Multithreading support
  • HTML5/CSS3 support
  • Web fonts support

예제 1



protected void BtnCreatePdf_Click(object sender, EventArgs e)
        {
            // read parameters from the webpage
            string htmlString = TxtHtmlCode.Text;
            string baseUrl = TxtBaseUrl.Text;

            string pdf_page_size = DdlPageSize.SelectedValue;
            PdfPageSize pageSize = (PdfPageSize)Enum.Parse(typeof(PdfPageSize), 
                pdf_page_size, true);

            string pdf_orientation = DdlPageOrientation.SelectedValue;
            PdfPageOrientation pdfOrientation = 
                (PdfPageOrientation)Enum.Parse(typeof(PdfPageOrientation), 
                pdf_orientation, true);

            int webPageWidth = 1024;
            try
            {
                webPageWidth = Convert.ToInt32(TxtWidth.Text);
            }
            catch { }

            int webPageHeight = 0;
            try
            {
                webPageHeight = Convert.ToInt32(TxtHeight.Text);
            }
            catch { }

            // instantiate a html to pdf converter object
            HtmlToPdf converter = new HtmlToPdf();

            // set converter options
            converter.Options.PdfPageSize = pageSize;
            converter.Options.PdfPageOrientation = pdfOrientation;
            converter.Options.WebPageWidth = webPageWidth;
            converter.Options.WebPageHeight = webPageHeight;

            // create a new pdf document converting an url
            PdfDocument doc = converter.ConvertHtmlString(htmlString, baseUrl);

            // save pdf document
            doc.Save(Response, false, "Sample.pdf");

            // close pdf document
            doc.Close();
        }


예제 2


        protected void BtnCreatePdf_Click(object sender, EventArgs e) {
         // get parameters
         string headerUrl = Server.MapPath("~/files/header.html");
         string footerUrl = Server.MapPath("~/files/footer.html");

         bool showHeaderOnFirstPage = ChkHeaderFirstPage.Checked;
         bool showHeaderOnOddPages = ChkHeaderOddPages.Checked;
         bool showHeaderOnEvenPages = ChkHeaderEvenPages.Checked;

         int headerHeight = 50;
         try {
          headerHeight = Convert.ToInt32(TxtHeaderHeight.Text);
         } catch {}


         bool showFooterOnFirstPage = ChkFooterFirstPage.Checked;
         bool showFooterOnOddPages = ChkFooterOddPages.Checked;
         bool showFooterOnEvenPages = ChkFooterEvenPages.Checked;

         int footerHeight = 50;
         try {
          footerHeight = Convert.ToInt32(TxtFooterHeight.Text);
         } catch {}

         // instantiate a html to pdf converter object
         HtmlToPdf converter = new HtmlToPdf();

         // header settings
         converter.Options.DisplayHeader = showHeaderOnFirstPage ||
          showHeaderOnOddPages || showHeaderOnEvenPages;
         converter.Header.DisplayOnFirstPage = showHeaderOnFirstPage;
         converter.Header.DisplayOnOddPages = showHeaderOnOddPages;
         converter.Header.DisplayOnEvenPages = showHeaderOnEvenPages;
         converter.Header.Height = headerHeight;

         PdfHtmlSection headerHtml = new PdfHtmlSection(headerUrl);
         headerHtml.AutoFitHeight = HtmlToPdfPageFitMode.AutoFit;
         converter.Header.Add(headerHtml);

         // footer settings
         converter.Options.DisplayFooter = showFooterOnFirstPage ||
          showFooterOnOddPages || showFooterOnEvenPages;
         converter.Footer.DisplayOnFirstPage = showFooterOnFirstPage;
         converter.Footer.DisplayOnOddPages = showFooterOnOddPages;
         converter.Footer.DisplayOnEvenPages = showFooterOnEvenPages;
         converter.Footer.Height = footerHeight;

         PdfHtmlSection footerHtml = new PdfHtmlSection(footerUrl);
         footerHtml.AutoFitHeight = HtmlToPdfPageFitMode.AutoFit;
         converter.Footer.Add(footerHtml);

         // add page numbering element to the footer
         if (ChkPageNumbering.Checked) {
          // page numbers can be added using a PdfTextSection object
          PdfTextSection text = new PdfTextSection(0, 10,
           "Page: {page_number} of {total_pages}  ",
           new System.Drawing.Font("Arial", 8));
          text.HorizontalAlign = PdfTextHorizontalAlign.Right;
          converter.Footer.Add(text);
         }

         // create a new pdf document converting an url
         PdfDocument doc = converter.ConvertUrl(TxtUrl.Text);

         // save pdf document
         doc.Save(Response, false, "Sample.pdf");

         // close pdf document
         doc.Close();
        }