顯示具有 iTextSharp 標籤的文章。 顯示所有文章
顯示具有 iTextSharp 標籤的文章。 顯示所有文章

2018年3月14日 星期三

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

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

2018-03-14

iText 7 represents the next level of SDKs for developers that want to take advantage of the benefits PDF can bring. Equipped with a better document engine, high- and low-level programming capabilities and the ability to create, edit and enhance PDF documents, iText 7 can be a boon to nearly every workflow. iText 7 allows you to build custom PDF scenarios for web, mobile, desktop or cloud apps in Java and .NET.

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.2 版











Default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="iText7Test.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 iText.Kernel.Pdf;
using iText.Layout;
using iText.Layout.Element;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            // https://developers.itextpdf.com/content/itext-7-jump-start-tutorial/sharp/chapter-1-introducing-basic-building-blocks

            // 請自己在 Visual Studio 的專案目錄下建立 pdf 目錄供產生存放檔案
            // 也就是手動建立 D:\CodeTemp\iText7Test\iText7Test\pdf 目錄
            string dest = Server.MapPath("pdf2\\Hello.pdf");
            var writer = new PdfWriter(dest);
            var pdf = new PdfDocument(writer);
            var document = new Document(pdf);
            document.Add(new Paragraph("Hello World!"));
            document.Close();
        }
    }
}


測試

(下圖) 如果 pdf 沒有手動建立,會出現錯誤


(下圖) 產生的 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


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 版



iTextSharp.5.5.13.3 會安裝2個套件:
BouncyCastle.1.8.9
iTextSharp.5.5.13.3

若要 NuGet 移除,依序為
itextsharp.xmlworker 5.5.13.3 => iTextSharp.5.5.13.3 => BouncyCastle 1.8.9
因為 'MimeKit.4.5.0, NPOI.2.7.0' 相依於它,所以無法解除安裝 'BouncyCastle.Cryptography.2.3.0'。


(下圖) 如果要安裝 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

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