Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 生成pdf时出错 protectedvoid txt\u btn\u单击(对象发送方,事件参数e) { Response.ContentType=“application/pdf”; AddHeader(“内容处置”、“附件;文件名=TestResult.pdf”); Response.Cache.SetCacheability(HttpCacheability.NoCache); StringBuilder htmlText=新的StringBuilder(); 附加(“创建pdf abcdef”); StringReader StringReader=新的StringReader(htmlText.ToString()); 文档文档=新文档(PageSize.A4); 列表元素= iTextSharp.text.html.simpleparser.HTMLWorker.parsetList(stringReader,null); doc.Open(); foreach(元素中的对象项) { 单据新增((IElement)项); } doc.Close(); //响应输出 GetInstance(doc,Response.OutputStream); doc.Open(); //doc.Close(); 响应。写入(“创建PDF”); }_Asp.net - Fatal编程技术网

Asp.net 生成pdf时出错 protectedvoid txt\u btn\u单击(对象发送方,事件参数e) { Response.ContentType=“application/pdf”; AddHeader(“内容处置”、“附件;文件名=TestResult.pdf”); Response.Cache.SetCacheability(HttpCacheability.NoCache); StringBuilder htmlText=新的StringBuilder(); 附加(“创建pdf abcdef”); StringReader StringReader=新的StringReader(htmlText.ToString()); 文档文档=新文档(PageSize.A4); 列表元素= iTextSharp.text.html.simpleparser.HTMLWorker.parsetList(stringReader,null); doc.Open(); foreach(元素中的对象项) { 单据新增((IElement)项); } doc.Close(); //响应输出 GetInstance(doc,Response.OutputStream); doc.Open(); //doc.Close(); 响应。写入(“创建PDF”); }

Asp.net 生成pdf时出错 protectedvoid txt\u btn\u单击(对象发送方,事件参数e) { Response.ContentType=“application/pdf”; AddHeader(“内容处置”、“附件;文件名=TestResult.pdf”); Response.Cache.SetCacheability(HttpCacheability.NoCache); StringBuilder htmlText=新的StringBuilder(); 附加(“创建pdf abcdef”); StringReader StringReader=新的StringReader(htmlText.ToString()); 文档文档=新文档(PageSize.A4); 列表元素= iTextSharp.text.html.simpleparser.HTMLWorker.parsetList(stringReader,null); doc.Open(); foreach(元素中的对象项) { 单据新增((IElement)项); } doc.Close(); //响应输出 GetInstance(doc,Response.OutputStream); doc.Open(); //doc.Close(); 响应。写入(“创建PDF”); },asp.net,Asp.net,} 我正在尝试创建pdf文件。但pdf仅创建了0kb。意思是当我打开此文件时,可能是shw错误,pdf已损坏我假设您正在使用iTextSharp库 protected void txt_btn_Click(object sender, EventArgs e) { Response.ContentType = "application/pdf"; Response.AddHeader("content-disposition", "attachment;filename=Tes

}


我正在尝试创建pdf文件。但pdf仅创建了0kb。意思是当我打开此文件时,可能是shw错误,pdf已损坏

我假设您正在使用iTextSharp库

 protected void txt_btn_Click(object sender, EventArgs e)
{
    Response.ContentType = "application/pdf";
    Response.AddHeader("content-disposition", "attachment;filename=TestResult.pdf");
    Response.Cache.SetCacheability(HttpCacheability.NoCache);

    StringBuilder htmlText = new StringBuilder();
    htmlText.Append("<table style='color:red;' border='1'><tr><th>createing pdf</th><tr><td> abcdef</td></tr></table>");

    StringReader stringReader = new StringReader(htmlText.ToString());
    Document doc = new Document(PageSize.A4);
    List<iTextSharp.text.IElement> elements =
            iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(stringReader, null);
    doc.Open();
    foreach (object item in elements)
    {
        doc.Add((IElement)item);
    }
    doc.Close();
    // Response Output
    PdfWriter.GetInstance(doc, Response.OutputStream);
    doc.Open();

    //doc.Close();

    Response.Write("PDF is created");
}

这很好,但我还需要设计,所以您可以在字符串生成器对象中附加设计。我可以在将asp.page转换为pdf文件时使用样式吗(我正在使用itextsharp.dll进行转换)。主要的问题是当我使用'sb.Append(“'hello”);某人附加(“ww”“lkl”);'这会将此div样式写入pdf文件,但我需要在转换为帖子下方的pdfcheck时应用此样式。
private void GeneratePDF()
    {
        try
        {
            string pdfPath = "~/PDF/File_1.pdf";
            StringBuilder sb = new StringBuilder();
            sb.Append("Name : chamara" + Environment.NewLine);
            sb.Append("Address : sri lanaka" + Environment.NewLine);
            sb.Append("Institute : SLIIT" + Environment.NewLine);
            Document doc = new Document();
            PdfWriter.GetInstance(doc, new FileStream(Server.MapPath(pdfPath), FileMode.Create));
            doc.Open();
            doc.Add(new Paragraph(sb.ToString()));
            doc.Close();

        }
        catch (Exception ex)
        {
            throw ex;
        }
    }