PDF或其它"报告观众QUOT;对于Asp.net C#的选项 [英] PDF or Other "report viewer" options for Asp.net C#

查看:104
本文介绍了PDF或其它"报告观众QUOT;对于Asp.net C#的选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的当前项目的绑定。这是一个工资单应用程序,我在ASP.net web表单用C#开发。我的老板说,这个网站的理想功能是点击付费检查日期和PDF打开并显示薪水信息。我已经做过研究了几天,试图找出最佳的解决方案。到目前为止,我有没有运气。我已经找到了一些不同的东西,如iTextSharp的,但一年的许可证是太贵了现在。我也看到它是基于PHP的TCPDF。我也看着水晶报表和活动报告。要购买许可证太贵也是如此。我特地为XML为PDF解决方案还,但我没有找到任何明确的。因为我是pretty新的软件开发的商业世界,不具备高级开发人员依靠,我是pretty在水中多死了。我知道我们将下载到薪水从DOS基础的应用,做我们的时钟来龙去脉CSV文件。然后,我将导入CSV文件导入到SQL Server 2012的前preSS。你的想法大大AP preciated,因为我不知道在哪里可以从这里走!先谢谢你!

I'm in a bind with my current project. It's a payroll application and I'm developing in ASP.net webforms with C#. My boss said that the ideal function of this site is to click on the pay check date, and a PDF opens and shows the paycheck information. I have done research for a few days to try to find the best solution. So far, I have had no luck. I have found a few different things such as iTextSharp but the license for one year is too expensive right now. I have also seen the tcpdf which is php based. I have also looked into CrystalReports, and Active Reports. To purchase the license is too expensive as well. I have looked into XML to PDF solutions also but I'm not finding anything definite. Since I'm pretty new to the business world of software development and don't have senior developers to rely on, I'm pretty much dead in the water. I know we will be downloading the paychecks into a CSV file from a DOS based application that does our clock-ins and outs. I will then be importing the CSV files into SQL Server 2012 Express. Your ideas are greatly appreciated as I don't know where to go from here! Thank you in advance!

推荐答案

一个HTML到PDF转换器,我最近发现是的 WKHTMLtoPDF

A HTML to PDF converter that I've recently discovered is WKHTMLtoPDF

它是开源的,并且使用的WebKit为HTML转换为PDF因此它的pretty符合标准。

It's open source and uses WebKit to convert HTML to PDF so it's pretty standards compliant.

您可能如何使用它的一个例子是

An example of how you might use it is

using (var pdfStream = new FileStream(dlg.FileName, FileMode.OpenOrCreate))
{
    // pass in the HTML you want to appear in the PDF, and the file stream it writes to
    Printer.GeneratePdf(htmlStream, pdfStream);
}

其中, GeneratePdf 定义为

    public static void GeneratePdf(Stream html, Stream pdf) 
    {
        Process process;
        StreamWriter stdin;
        var psi = new ProcessStartInfo();

        psi.FileName = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\Lib", "wkhtmltopdf.exe");
        psi.WorkingDirectory = Path.GetDirectoryName(psi.FileName);

        // run the conversion utility
        psi.UseShellExecute = false;
        psi.CreateNoWindow = true;
        psi.RedirectStandardInput = true;
        psi.RedirectStandardOutput = true;
        psi.RedirectStandardError = true;

        psi.Arguments = "-q -n --disable-smart-shrinking - -";
        process = Process.Start(psi);

        try
        {
            stdin = process.StandardInput;
            stdin.AutoFlush = true;
            //stdin.Write(html.ReadToEnd());
            stdin.Write(new StreamReader(html).ReadToEnd());
            stdin.Dispose();

            process.StandardOutput.BaseStream.CopyTo(pdf);

            process.StandardOutput.Close();
            pdf.Position = 0;

            process.WaitForExit(10000);
        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally
        {
            process.Dispose();
        }
    }

在你的情况,而不是将其写入文件流,你把它写到HTTP输出流为PDF。

In your case, instead of writing it to a file stream, you'd write it to the HTTP output stream as a PDF.

请注意,这个例子是比较适合的PDF文件写入磁盘,而不是输出流所以你需要做的稍微不同的为它为你工作。

Please note however, that this example is more suitable to writing PDF files to disk, rather than the output stream so you'd need to do it differently slightly for it to work for you.

这篇关于PDF或其它"报告观众QUOT;对于Asp.net C#的选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆