2018年3月13日 星期二

[研究][C#][ASP.NET] 免費 iTextSharp v5.5.13 產生 pdf 試用 (NuGet 安裝)

[研究][C#][ASP.NET] 免費 iTextSharp v5.5.13 產生 pdf 試用 (NuGet 安裝)

2018-03-13

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.

iText 在 5.x 的時候,for Java 稱為 iText 5,但是 for .NET 用的稱為 iTextSharp。
iText 在 7.x 的時候,for Java 和 for .NET 用的都稱為 iText 7。

iText - 維基百科,自由的百科全書
https://zh.wikipedia.org/wiki/IText

網站
http://itextpdf.com/

軟體下載
https://sourceforge.net/projects/itextsharp/
NuGet iTextSharp 5.5.13
https://www.nuget.org/packages/iTextSharp/
Create/Read Advance PDF Report using iTextSharp in C# .NET: Part I
https://www.codeproject.com/Articles/686994/Create-Read-Advance-PDF-Report-using-iTextSharp-in

********************************************************************************

授權
http://www.gnu.org/licenses/agpl.html
Affero通用公眾授權條款 - 維基百科,自由的百科全書
https://zh.wikipedia.org/wiki/Affero%E9%80%9A%E7%94%A8%E5%85%AC%E5%85%B1%E8%AE%B8%E5%8F%AF%E8%AF%81
因應網路時代與雲端應用而生的 AGPL-3.0 授權條款
最近更新在 2012-09-25 17:41
https://www.openfoundry.org/tw/legal-column-list/8809-introduction-to-agpl3
itext 5 和 itext 7 是在AGPL協議下的,就是凡是用到他的代碼的專案需要開源,除非購買商業版。

iTextPDF 販售

********************************************************************************

官方範例 (好像都是 Java 範例)
iText 7 code examples in practice | iText Developers
https://developers.itextpdf.com/examples-itext7
iText 5 code examples in practice | iText Developers
https://developers.itextpdf.com/examples-itext5

官方  .NET 範例
(這是 iText 7 範例,Visual Studio 2017 NuGet 安裝的是 iText 5,實際測試不能用)
(官方似乎不提供 iText 5 for .NET 範例)
https://developers.itextpdf.com/content/itext-7-jump-start-tutorial-net/itext-7-jump-start-tutorial-net-version

使用ASP .NET (C#) 產生PDF檔的好幫手—iTextSharp library (上)
http://www.cc.ntu.edu.tw/chinese/epaper/0015/20101220_1509.htm

使用ASP .NET (C#) 產生PDF檔的好幫手—iTextSharp library (下)
http://www.cc.ntu.edu.tw/chinese/epaper/0016/20110320_1610.html

ASP.NET轉成PDF檔輸出 (iTextSharp相關範例)
2008-05-06
https://dotblogs.com.tw/mis2000lab/2008/05/06/3799

[ASP.net MVC] 將HTML轉成PDF檔案,使用iTextSharp套件的XMLWorkerHelper (附上解決顯示中文問題)
http://www.dotblogs.com.tw/shadow/archive/2014/02/09/143891.aspx

[msdn範例下載] ASP.NET Chart控制項轉成(輸出)PDF、轉成(輸出) Image圖片檔
http://www.dotblogs.com.tw/mis2000lab/archive/2014/04/07/itextsharp_chart_export_pdf_image_file_20140407.aspx

GridView 資料轉檔到 PDF - 使用 iTextSharp
http://infinite-zoom.blogspot.tw/2014/07/gridview-pdf-itextsharp.html

[ASP.NET]利用itextsharp將GridView匯出PDF檔
http://www.dotblogs.com.tw/puma/archive/2009/10/14/aspnet-gridview-pdf-itextsharp.aspx

Create PDFs in ASP.NET - getting started with iTextSharp
12 October 2008 11:26
https://www.mikesdotnetting.com/article/80/create-pdfs-in-asp-net-getting-started-with-itextsharp

********************************************************************************

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







(下圖) 輸入關鍵字,找到 iTextSharp v5.x 版


(下圖) 如果要安裝 iText 7.x,建議輸入 iText7,但是兩個版本的程式碼不通用




iText is a PDF library that allows you to CREATE, ADAPT, INSPECT and MAINTAIN documents in the Portable Document Format (PDF), allowing you to add PDF functionality to your software projects with ease.  We even have documentation to help you get coding.

We have two currently supported versions: iText 5 and iText 7. Both are available under AGPL and Commercial license.
* iText 5 AGPL
* iText 7 community: https://www.nuget.org/packages/itext7/

iText 5 is a one solution library that is complex, but well documented to help you create your solutions.

iText 7 is a complete re-write of iText 5, allowing you to choose your adventure with add-ons, all based on a simple, modular code structure that is easy to use and well documented.

Both versions allow you to:
- Generate documents and reports based on data from an XML file or a database
- Create maps and books, exploiting numerous interactive features available in PDF
- Add bookmarks, page numbers, watermarks, and other features to existing PDF documents
- Split or concatenate pages from existing PDF files
- Fill out interactive forms
- Serve dynamically generated or manipulated PDF documents to a web browser

iText 7 includes pdfDebug, the first debugging tool that gives you a clear overview of your content streams and document structure as well as pdfCalligraph, allowing you to leverage advanced typography.

iText is available for Java, .NET in both versions, and Android and GAE for iText 5 only.

iTextSharp is the .NET port of iText 5.

Several iText engineers are actively supporting the project on StackOverflow: http://stackoverflow.com/questions/tagged/itext


直接拿這篇的範例試用一下

使用ASP .NET (C#) 產生PDF檔的好幫手—iTextSharp library (上)
http://www.cc.ntu.edu.tw/chinese/epaper/0015/20101220_1509.htm

Default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="iTextSharpTest.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 System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;

namespace iTextSharpTest
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            var doc1 = new Document(PageSize.A4, 50, 50, 80, 50);

            //MemoryStream memoryStream1 = new MemoryStream();
            //PdfWriter pdfWriter1 = PdfWriter.GetInstance(doc1, memoryStream1);
            // or
            //  請自己在 Visual Studio 的專案目錄下建立 pdf 目錄供產生存放檔案
            string path = Server.MapPath("pdf");
            PdfWriter pdfWriter1 = PdfWriter.GetInstance(doc1, new FileStream(path + "/pdfexample.pdf", FileMode.Create));

            BaseFont bfChinese = BaseFont.CreateFont(@"C:\Windows\Fonts\kaiu.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
            Font ChFont = new Font(bfChinese, 12);
            Font ChFont_blue = new Font(bfChinese, 40, Font.NORMAL, new BaseColor(51, 0, 153));
            Font ChFont_msg = new Font(bfChinese, 12, Font.ITALIC, BaseColor.RED);

            doc1.Open();
            doc1.Add(new Paragraph(10f, "Hello, 大家好!", ChFont_blue));
            doc1.Close();
        }
    }
}


產生的 pdf 內容



(完)

相關

[研究][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

沒有留言:

張貼留言