0

我正在尝试使用 .NET 生成动态 PDF。我找到的图书馆是 QuickPDFLibrary。我知道还有其他几个库可以做到这一点,例如 iTextSharp;但是,它们需要商业应用程序的许可证。QuickPDFLibrary 声明它们支持 ASP.NET;但是,我似乎无法让它工作,也无法在他们的网站上找到一个教程,该教程记录了将它与 ASP.NET 一起使用的文档。我按照程序设置 DLL 和 ActiveX,但无法让它们中的任何一个在 aspx 页面的上下文中工作。我的代码如下。

public partial class _Default : System.Web.UI.Page
{
    public QuickPDFAX0816.PDFLibrary qp;
    protected void Page_Load(object sender, EventArgs e)
    {
        qp = new QuickPDFAX0816.PDFLibrary(); 
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        qp.UnlockKey("UNLOCK KEY HERE");

        // This function draws text onto a document

        // Setup the parameters
        string fileName = "drawText.pdf";

        // Check to see if the library has been successfully unlocked
        if (qp.Unlocked() == 1)
        {
            // Set origin co-ordinates to top left of page
            qp.SetOrigin(1);

            // Call the DrawText function
            qp.DrawText(100, 100, "Hello world from C# and the ActiveX edition of Quick PDF Library");

            // Save the changes to the document on the local disk (in the debug folder)
            int result = qp.SaveToFile(fileName);

            if (result == 1)
            {
                Console.WriteLine("IT worked!");
            }
            else
            {
                Console.WriteLine("IT failed!");
            }
            // Open PDF automatically
            //System.Diagnostics.Process.Start(fileName);

        }
        else
        {
            // If library could not be unlocked warn the user
            Console.WriteLine("License key could not be validated. The library was not unlocked.");
        }
    }
}
4

1 回答 1

0

试试 PDFSharp http://www.pdfsharp.net/。它是具有 MIT 许可证的开源软件,因此它对商业产品非常友好,完全是 .Net(没有 ActiveX),并且他们有很好的示例http://www.pdfsharp.net/wiki/PDFsharpSamples.ashx可以帮助您入门

于 2012-09-19T02:16:14.030 回答