0

大家好,我已经在网络服务http://www.hiqpdf.com/demo/ConvertHtmlToPdf.aspx中编写了这段代码,如下所示

[WebMethod]
    public void convert(string strURL)
    {
        HtmlToPdf htmlToPdfConverter = new HtmlToPdf();
        string url = strURL;
        byte[] pdfBuffer = htmlToPdfConverter.ConvertUrlToMemory(url);

        HttpContext.Current.Response.AddHeader("Content-Type", "application/pdf");

        // let the browser know how to open the PDF document, attachment or inline, and the file name
        HttpContext.Current.Response.AddHeader("Content-Disposition", String.Format("attachment; filename=ConvertHtmlPart.pdf; size={0}",
                    pdfBuffer.Length.ToString()));

        // write the PDF buffer to HTTP response
        HttpContext.Current.Response.BinaryWrite(pdfBuffer);

        // call End() method of HTTP response to stop ASP.NET page processing
        HttpContext.Current.Response.End();
    }

我从本地主机将其作为参考添加到我的项目中,但是在尝试转换时,我遇到了异常,因为Client found response content type of 'application/pdf', but expected 'text/xml'. The request failed with the error message:有人可以帮助我。

4

1 回答 1

0

".ToString()" - 没必要

是吗?

于 2013-01-05T08:23:47.383 回答