首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PHP与C#在IIS7上的通信(生成动态PDF)

PHP与C#在IIS7上的通信(生成动态PDF)
EN

Stack Overflow用户
提问于 2010-05-07 17:46:42
回答 1查看 404关注 0票数 0

背景:

我在C#中找不到任何合适的免费HTML到PDF转换实用程序。在PHP中,有1000多个版本提供了大量的文档、支持和CSS支持。所以我使用的是html2ps和html2pdf (php)。

我在IIS7上安装了PHP5.2,它的工作原理非常好,可以创建PDF。

我在getPDF.aspx中有以下内容

代码语言:javascript
复制
<!-- 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

代码语言:javascript
复制
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

代码语言:javascript
复制
<?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**?**生成的格式

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-05-07 19:06:42

我建议查看iTextSharp,一个免费的iText .NET端口(基于Java的PDF ),然后您就可以将php从等式中删除。

有关使用iTextSharp转换这篇文章的信息,请参见这篇文章(使用谷歌)

更新

在ASP.NET窗体中呈现部分(即呈现单个控件或带有控件的页面)您将创建一个System.Web.Page来驱动事件结构。

下面是我为我的一个项目改编的代码示例:

代码语言:javascript
复制
    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();
    }

它的名字是这样的

代码语言:javascript
复制
MyHelper.Render<MyControlBase>("~/SomePath/SomeControl.ascx", p => { p.SomeProperty = "Initializer" });

这段代码可能不是您所需要的,但是正如您所看到的,您可以使用Server / Page对象呈现结果,这可能是您应该采取的路线。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2790525

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档