2018年3月12日 星期一

[研究][C#][ASP.NET] 免費 PDFsharp v1.32.3057.0 產生 pdf 試用 (NuGet 安裝)

[研究][C#][ASP.NET] 免費 PDFsharp v1.32.3057.0 產生 pdf 試用 (NuGet 安裝)

2018-03-12

PDFsharp is the Open Source .NET library that easily creates and processes PDF documents on the fly from any .NET language. The same drawing routines can be used to create PDF documents, draw on the screen, or send output to any printer.

This is PDFsharp based on GDI+. See Project Information for details.

官方網站
http://www.pdfsharp.net/

授權
http://www.pdfsharp.net/PDFsharp_License.ashx

  • PDFsharp is Open Source.
  • You can copy, modify and integrate the source code of PDFsharp in your application without restrictions at all.
  • This also applies to commercial products (both open source and closed source).


PDFsharp的說明可參考:
http://www.pdfsharp.net/wiki/MainPage.ashx
PDFSharp 本身沒有 table,也不能剖析 HTML 語法。

PDFsharp軟體下載網址:
http://sourceforge.net/projects/pdfsharp/

範例
http://www.pdfsharp.net/wiki/PDFsharpSamples.ashx

測試環境:Visual Studio 2017 v15.6.1 版











Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="PDFSharpTest.Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
        </div>
    </form>
</body>
</html>


Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PdfSharp;
using PdfSharp.Drawing;
using PdfSharp.Pdf;
using PdfSharp.Pdf.IO;

namespace PDFSharpTest
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            // http://www.pdfsharp.net/wiki/HelloWorld-sample.ashx

            // Create a new PDF document
            PdfDocument document = new PdfDocument();
            document.Info.Title = "Created with PDFsharp";

            // Create an empty page
            PdfPage page = document.AddPage();

            // Get an XGraphics object for drawing
            XGraphics gfx = XGraphics.FromPdfPage(page);

            // Create a font
            XFont font = new XFont("Verdana", 20, XFontStyle.BoldItalic);

            // Draw the text
            gfx.DrawString("Hello, World!", font, XBrushes.Black,
            new XRect(0, 0, page.Width, page.Height),
            XStringFormats.Center);

            // Save the document...
            // C:\Program Files (x86)\IIS Express
            const string filename = "HelloWorld.pdf";
            document.Save(filename);

            // ...and start a viewer.
            //Process.Start(filename);
        }
    }
}

注意,檔案會產生到  C:\Program Files (x86)\IIS Express 目錄。
(找不到就搜尋一下)

測試完畢要刪除的時候,發現目錄不能刪除,但是實際檢查,Visual Studio 已經關閉,也沒有開啟該目錄中任何檔案,檔案總管也沒開啟該目錄或其子目錄,有點懷疑這套是否適合用於 ASP.NET 網頁上,或只適合用於 WinForm 應用程式上。


(完)

相關

[研究][C#][ASP.NET] 試用 Free Spire.PDF for .NET 建立 pdf 檔案 (NuGet 安裝)
http://shaurong.blogspot.com/2018/03/aspnet-free-spirepdf-for-net-pdf.html

[研究][C#][ASP.NET] SelectPdf 社群版 - 免費 HTML to PDF v17.3.0 的 Url to Pdf 試用 (NuGet 安裝)
http://shaurong.blogspot.com/2018/03/caspnet-selectpdf-html-to-pdf-url-to-pdf.html

[研究][C#][ASP.NET] iTextSharp v7.1.1 產生 pdf 試用 (NuGet 安裝)
http://shaurong.blogspot.com/2018/03/caspnet-itextsharp-v711-pdf-nuget.html

[研究][C#][ASP.NET] iTextSharp v5.5.13 產生 pdf 試用 (NuGet 安裝)
http://shaurong.blogspot.com/2018/03/caspnet-itextsharp-v5513-pdf-nuget.html

[研究][C#][ASP.NET] 免費 PDFsharp v1.32.3057.0 產生 pdf 試用 (NuGet 安裝)
http://shaurong.blogspot.com/2018/03/caspnet-pdfsharp-v13230570-pdf-nuget.html

沒有留言:

張貼留言