IIS7 PHP ve C # iletişim (dinamik PDF oluşturmak için)

1 Cevap

Arka plan:

Ben C # PDF dönüşüm programları için herhangi bir iyi ücretsiz HTML bulamadı. Kapsamlı dokümantasyon, destek ve CSS desteği ile PHP için onlara 100'ler vardır. Yani html2ps and html2pdf (php) kullanıyorum.

PHP 5.2 IIS7 ve oluşturmak için güzel çalışma PDF'leri yüklü.

Ben getPDF.aspx de şu var

<!-- Output the header -->
<DM:header runat="server" ID="header" />

<asp:Placeholder id="content" runat="server" />

<!-- Output the footer -->
<DM:footer runat="server" ID="footer" />

ve 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");
}

ve 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 the output is HTML.

So how can I get getPDF.aspx çıkışı olan HTML gibi generatePDF.php tarafından oluşturulan PDF

1 Cevap

Ben O zaman doğru denklemin dışında php kesebilir iText (Java Tabanlı PDF Lib) ve iTextSharp ücretsiz. NET noktasına bakarak öneririm.

iTextSharp bakın lütfen kullanarak HTML dönüştürmek için This Post (Found using google)

Update

Bu olay yapısını götürmek için bir System.Web.Page oluşturmak (yani tek bir denetim ve kontroller ile bir sayfa render) ASP.NET Formlar Partials Rendering.

İşte benim bir proje için uyarlanmış bir kod örneği var:

    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();
    }

Bu gibi deniyor:

MyHelper.Render<MyControlBase>("~/SomePath/SomeControl.ascx", p => { p.SomeProperty = "Initializer" });

Bu kod neye ihtiyacınız olmayabilir, ama sen Sunucu / Sayfa nesneleri kullanarak bir sonuç hale getirebilir görebileceğiniz gibi, bu götürmelidir yol olabilir.