Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.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
C# iTextSharp(将aspx页面转换为pdf)_C#_Asp.net_Pdf_Itextsharp - Fatal编程技术网

C# iTextSharp(将aspx页面转换为pdf)

C# iTextSharp(将aspx页面转换为pdf),c#,asp.net,pdf,itextsharp,C#,Asp.net,Pdf,Itextsharp,我正在尝试为我的课程项目实施演示证书颁发。将aspx页面转换为pdf时,图像根本无法显示。此处使用的图像位于我自己的笔记本电脑中,与Certification.aspx文件位于同一文件夹中。在另一台笔记本电脑中,图像会显示一次,但图像不会再次显示。这是随机发生的 请帮忙 谢谢 这是Certification.aspx页面 此页面显示课程门户徽标,以图像和一行关于证书的文本形式显示 <%@ Page Language="C#" AutoEventWireup="true" CodeFile=

我正在尝试为我的课程项目实施演示证书颁发。将aspx页面转换为pdf时,图像根本无法显示。此处使用的图像位于我自己的笔记本电脑中,与Certification.aspx文件位于同一文件夹中。在另一台笔记本电脑中,图像会显示一次,但图像不会再次显示。这是随机发生的

请帮忙

谢谢

这是Certification.aspx页面

此页面显示课程门户徽标,以图像和一行关于证书的文本形式显示

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Certification.aspx.cs" Inherits="Certification" EnableEventValidation="false" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

   <!-- <asp:Image ID="Image1" runat="server" Height="402px" ImageUrl="certi.png" Width="923px" />  -->
    <br />
    <br />
    <br />




    <asp:Panel ID="Panel1" runat="server" Height="120px">

       <!--  <img src = "http://www.aspsnippets.com/images/Blue/Logo.png" /><br />  -->

         <img src="E:\Pictures\1.jpg"  height="402" width="923" alt="Image" /><br/>
        <asp:Label ID="Label3" runat="server"></asp:Label>
    <br />
    <br />
    <b><i>Has successfully completed the requirements to complete the course on</i></b>&nbsp;&nbsp;
    <asp:Label ID="Label4" runat="server"></asp:Label>
        <br />
        <asp:Button ID="Button1" runat="server" Text="Click to download as PDF." OnClick="Button1_Click1" />

    </asp:Panel>




</div>
</form>

点击上面的按钮,aspx页面将转换为pdf。

我看到您正在使用
HTMLWorker
。这已经过时几年了,您应该使用
XMLWorker
。对不起,这不是对你问题的回答,这就是为什么我把它作为评论发布的原因。我假设您使用的是5.5.9版。请尝试
PDFSharp
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html;
using iTextSharp.text.html.simpleparser;
using System.Drawing;
using System.IO;


public partial class Certification : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string marks="",name="",course="";
        int marks1=0;
        string id = Session["email"].ToString();
        SqlConnection conn = new SqlConnection(); //creating connection    reference object

    //conn.ConnectionString = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=E:\My Documents\Final Year Project\finalyear\finalyear\App_Data\newdatabase.mdf;Integrated Security=True";
    conn.ConnectionString = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=E:\My Documents\Final Year Project\finalyear\finalyear\App_Data\newdatabase.mdf;Integrated Security=True";
    conn.Open();  //opening connection
    string q = "select * from selectcourse where selectcourse.s_emailid='" + id + "'";
    SqlCommand cmd = new SqlCommand(q, conn);
    //execute query
    SqlDataReader reader = cmd.ExecuteReader();

    if (reader.Read() == true)
    {
        marks = reader.GetValue(3).ToString();
        marks1 = Convert.ToInt32(marks);

    }
    reader.Dispose();
    cmd.Dispose();

        string q1 = "select * from studentinfo where studentinfo.s_emailid='" + id + "'";
        SqlCommand cmd1 = new SqlCommand(q1, conn);
        //execute query
        SqlDataReader reader1 = cmd1.ExecuteReader();

        if (reader1.Read() == true)
        {
            name = reader1.GetValue(1).ToString();
        }
        course = Session["course"].ToString();

        Label3.Text = name.ToString();
        Label4.Text = course.ToString();


}
public override void VerifyRenderingInServerForm(Control control)
{
}
protected void Button1_Click1(object sender, EventArgs e)
{
    string attachment = "attachment; filename=" + "abc" + ".pdf";
    Response.ClearContent();
    Response.AddHeader("content-disposition", attachment);
    Response.ContentType = "application/pdf";
    StringWriter s_tw = new StringWriter();
    HtmlTextWriter h_textw = new HtmlTextWriter(s_tw);
    h_textw.AddStyleAttribute("font-size", "7pt");
    h_textw.AddStyleAttribute("color", "Black");
    Panel1.RenderControl(h_textw);//Name of the Panel
    Document doc = new Document();
    doc = new Document(PageSize.A4, 5, 5, 15, 5);
    FontFactory.GetFont("Verdana", 80);
    PdfWriter.GetInstance(doc, Response.OutputStream);
    doc.Open();
    StringReader s_tr = new StringReader(s_tw.ToString());
    HTMLWorker html_worker = new HTMLWorker(doc);
    html_worker.Parse(s_tr);
    /*var logo = iTextSharp.text.Image.GetInstance(Server.MapPath("certi.png"));
    logo.SetAbsolutePosition(0, 0);
    doc.Add(logo);*/ 
    doc.Close();
    Response.Write(doc);

}
}