小编Ari*_*Ari的帖子

如何使用iTextSharp将pdf Byte [] Array转换为可下载文件

嘿伙计我有这个字节数组我想转换为pdf并使其可供下载.任何人都知道如何做到这一点?

这是我的动作控制器

public ActionResult DownloadLabTestResult(string labTestResultID)
{
            PdfReader pdfReader = new PdfReader("Xue_Tang.pdf");

            MemoryStream stream = new MemoryStream();
            PdfStamper stamper = new PdfStamper(pdfReader, stream);

            pdfReader.Close();
            stamper.Close();
            stream.Flush();
            stream.Close();
            byte[] pdfByte = stream.ToArray();

            // So i got the byte array of the original pdf at this point. Now how do i convert this
            // byte array to a downloadable pdf? i tried the method below but to no avail.

            MemoryStream ms = new MemoryStream(pdfByte);

            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "attachment;filename=labtest.pdf");
            Response.Buffer = true; …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc itextsharp

18
推荐指数
1
解决办法
7万
查看次数

如何使用HtmlHelper类 - ASP.NET MVC显示图像

我目前坚持使用HtmlHelper类显示图像的问题.

这就是我所拥有的.

我有一个自定义的HtmlHelper类,它应该显示一个图像:

public static string Images(this HtmlHelper helper, ......){

    var writer = new HtmlTextWriter(new StringWriter());
    byte[] bytearray = ... // some image byte array retrieved from an object.

    // begin html image tag - this is where the problem is
    writer.AddAttribute(HtmlTextWriterAttribute.Src, url.Action("GetPhoto", "Clinical", new { image = bytearray })); 
    writer.RenderBeginTag(HtmlTextWriterTag.Img); 
    writer.RenderEndTag();
    // end of image tag

    return writer.InnerWriter.ToString();
}
Run Code Online (Sandbox Code Playgroud)

所以我上面尝试做的是将一个Url.Action注入img源属性.

我有一个控制器"GetPhoto",支持处理该bytearray并返回一个图像.

public FileContentResult GetPhoto(byte[] image)
        {

            return File(image, "image/jpeg");
        }
Run Code Online (Sandbox Code Playgroud)

我设法到达控制器,但图像显示为null.有办法解决吗?或者更好的方法呢?非常感谢您的帮助,谢谢!

c# asp.net-mvc

2
推荐指数
1
解决办法
2万
查看次数

如何在ASP.NET MVC中使用JQuery.Ajax传递多个参数

嗨,大家好,我是JSon的新手,不太清楚如何传递数据.我使用ASP.NET MVC作为我的开发平台.

在视图中:

 $(document).ready(function() {
    $("select#Colors").change(function() {
       var photoCategory = $("#Colors > option:selected").attr("value"); // 1st parameter
       var userID = $(".userID").attr("value"); // 2nd parameter         
       $.ajax({
            type: "GET",
            contentType: "application/json; charset=utf-8",
            url: "/FindPhotos/" + photoCategory ,
            data: "{}",
            dataType: "json",

            success: function(data) {
            $('#ProductsDiv > div').remove(); 
                if (data.length > 0) {
                    var options = ''; 
                } .......
       });
    });
});
Run Code Online (Sandbox Code Playgroud)

在Global.asax中:

routes.MapRoute(
       "FindPhotos",
       "FindPhotos/{category}",
        new { controller = "Clinical", action = "FindPhotosByCategory", category = "" }
       );
Run Code Online (Sandbox Code Playgroud)

所以一切正常,因为我只在$ .ajax网址中传递一个参数'photoCategory'.我现在的目标是传递第二个参数,即userID,所以我可以在下面的控制器方法中使用它们.

在控制器中:

 public JsonResult …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc jquery asp.net-mvc-2

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

asp.net-mvc ×3

c# ×3

asp.net-mvc-2 ×1

itextsharp ×1

jquery ×1