背景:
我在C#中找不到任何合适的免费HTML到PDF转换实用程序。在PHP中,有1000多个版本提供了大量的文档、支持和CSS支持。所以我使用的是html2ps和html2pdf (php)。
我在IIS7上安装了PHP5.2,它的工作原理非常好,可以创建PDF。
我在getPDF.aspx中有以下内容
<!-- Output the header -->
<DM:header runat="server" ID="header" />
<asp:Placeholder id="content" runat="server" />
<!-- Output the footer -->
<DM:footer runat="server" ID="footer" />在getPDF.aspx.cs中
protected void Page_Load(object sender, EventArgs e){
// AddContentControl simples adds a controls to the content Placeholder.
AddContentControl("controls/page1.ascx");
AddContentControl("controls/page2.ascx");
AddContentControl("controls/page3.ascx");
}在generatePDF.php中
<?php
/* ... includes and stuff here ... */
$data = "THE HTML GOES HERE!";
// creates the PDF from the $data and Outputs the created file.
convert_to_pdf($data);
?>-- getPDF.aspx works perfectly...except输出为perfectly...except。
因此,我如何使getPDF.aspx 输出由 generatePDF.php**?**生成的格式
发布于 2010-05-07 19:06:42
我建议查看iTextSharp,一个免费的iText .NET端口(基于Java的PDF ),然后您就可以将php从等式中删除。
有关使用iTextSharp转换这篇文章的信息,请参见这篇文章(使用谷歌)
更新
在ASP.NET窗体中呈现部分(即呈现单个控件或带有控件的页面)您将创建一个System.Web.Page来驱动事件结构。
下面是我为我的一个项目改编的代码示例:
public static string Render<T>(string controlPath, Action<T> initControlCallback) where T : Control
{
Page renderPage = new Page();
// Load the control & add to page
T control = (T) renderPage.LoadControl(controlPath);
renderPage.Controls.Add(control);
// Initialize the control
initControlCallback.Invoke(control);
renderPage.DataBind();
StringWriter result = new StringWriter();
HttpContext.Current.Server.Execute(renderPage, result, false); // Render Process
return result.ToString();
}它的名字是这样的
MyHelper.Render<MyControlBase>("~/SomePath/SomeControl.ascx", p => { p.SomeProperty = "Initializer" });这段代码可能不是您所需要的,但是正如您所看到的,您可以使用Server / Page对象呈现结果,这可能是您应该采取的路线。
https://stackoverflow.com/questions/2790525
复制相似问题