我想使用下面的代码保存pdf文件,以便我可以将它发送到用户的电子邮件请帮我使用评论的代码 [英] I want to use the below code to save pdf file so that I can send it to user's email Please help me to use that the commented code

查看:42
本文介绍了我想使用下面的代码保存pdf文件,以便我可以将它发送到用户的电子邮件请帮我使用评论的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用粗体标记代码生成pdf,但我想保存该pdf



I am using the bold marked code to generate pdf but I want to save that pdf

public ActionResult ReportSample(tbbooking tbbook)
        {
            var uemail = Convert.ToString(Session["uemail"]);
            var bookingid = tbbook.bookingid;
            var getticket = db.tbbookings.Where(a => a.bookingid == tbbook.bookingid).ToList();
            return new RazorPDF.PdfResult(getticket, "ReportSample");

            //var sb = new System.Text.StringBuilder();
            //TextWriter tw = new System.IO.StringWriter(sb);
            //myResult.View.Render(getticket, tw);
            //var resultCache = sb.ToString();
            //XmlParser parser;
            //using (var reader = GetXmlReader(resultCache))
            //{
            //    while (reader.Read() && reader.NodeType != XmlNodeType.Element)
            //    {
            //        // no-op
            //    }

            //    if (reader.NodeType == XmlNodeType.Element && reader.Name == "itext")
            //        parser = new XmlParser();
            //    else
            //        parser = new HtmlParser();
            //}

            //// Create a document processing context
            //var document = new Document();
            //document.Open();

            //// Associate output with response stream
            //var pdfWriter = PdfWriter.GetInstance(document, viewContext.HttpContext.Response.OutputStream);
            //pdfWriter.CloseStream = false;

            //// Create the pdf file in the directory system
            //var fileStream = new FileStream("~/Content/pdf", FileMode.Create);
            //var pdfWriter2 = PdfWriter.GetInstance(document, fileStream);

            //// this is as close as we can get to being "success" before writing output
            //// so set the content type now
            //viewContext.HttpContext.Response.ContentType = "application/pdf";

            //// parse memory through document into output
            //using (var reader = GetXmlReader(resultCache))
            //{
            //    parser.Go(document, reader);
            //}

            //fileStream.Close();
            //pdfWriter.Close();
            //pdfWriter2.Close();
        }

推荐答案

其实我下载了一个演示使用注释代码,我想用这段代码来保存我的pdf,我:

返回新的RazorPDF.PdfResult(getticket,ReportSample);

我得到了只有生成的pdf,但我想将pdf保存在一个文件夹中。




你不能只是下载一个演示并期望它做你正在做的事不过,你可以走进超市购买一些食物,并期待它是美食,热和准备吃。



当你从互联网获取代码,你必须查看它,阅读它,理解它,然后(并且只有那时)开始改变它以适合你的任务。如果没有对其进行一些更改,或者您的代码支持它,您将找不到解决问题的代码。



如果您下载代码并且只是扔进去你的应用程序然后你非常愚蠢:代码是做什么的?它是否像它所说的那样做,或者它是否加密你的硬盘并需要钱来加密它像一些木马软件那样?它是否找到您的信用卡详细信息并将其发送给作者?除非你阅读并理解代码,否则你不会知道 - 直到为时已晚。



因此请停止查找代码并将其添加到您的应用中开始思考:这是如何运作的?因为当你拥有它时,它将:

1)下次快点

2)当你需要更换你的应用程序时工作得更好

3)可能会让你免于悲痛。

4)在这种情况下,节省你很多时间:这是一个简单的代码,你不应该花半个多小时来理解你只有很少的经验。你现在可以自己解决这个问题......
"Actually I downloaded a demo where the commented codes are used, I want to use this code to save my pdf which I :
return new RazorPDF.PdfResult(getticket, "ReportSample");
I am getting only the generated pdf but I want to save that pdf in a folder."


You can't just "download a demo" and expect it to do exactly what you want, any more than you can walk into a supermarket and buy "some food" and expect it to be a gourmet meal, hot and ready to eat.

When you get code form the internet, you have to look at it, read it, understand it, and then (and only then) start changing it to fit your task. You will not find code that solves your problem without some changes to it, or your code to support it.

And if you do download code and just "throw it into your app" then you are being extremely silly: what does the code do? Does it do what it says it does, or does it encrypt your HDD and demand money to encrypt it as some trojan software does? Does it find your credit card details and send it to the author? Unless you read and understand the code, you will not know - until it is too late.

So stop "finding code" and "adding it to your app" and start thinking: "How does this work?" because when you have that, it will:
1) Be faster next time
2) Work better when you have to change your app
3) Possibly save you from a lot of grief.
4) In this case, save you a lot of time: that is trivial code which shouldn't take you more than half an hour to understand if you only have little experience. You could have solved this for yourself by now...


这篇关于我想使用下面的代码保存pdf文件,以便我可以将它发送到用户的电子邮件请帮我使用评论的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆