我的代码可以很好地创建pdf,但是我没有正确的代码将我的doc文件转换为字节。
我知道如何添加到数据库中。我只想知道我们如何将动态创建的pdf转换为字节。
string attachment = "attachment; filename=" + TextBox1.Text + ".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("Times New Roman", 14);
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);
//doc.Close();//Response.Write(doc);
//Response.End();
在这两个代码之间寻找正确的代码[将文档转换为字节]
using (MySqlCommand cmd1 = new MySqlCommand(query1))
{
cmd1.Connection = con1;
cmd1.Parameters.AddWithValue("@clientid1", TextBox1.Text);
cmd1.Parameters.AddWithValue("@username", Session["username"].ToString());
cmd1.Parameters.AddWithValue("@Name", filename);
cmd1.Parameters.AddWithValue("@ContentType", contentType);
cmd1.Parameters.AddWithValue("@Data", bytes);
con1.Open();
cmd1.ExecuteNonQuery();
con1.Close();
// }
}
}
}
}
Response.Redirect("mydoc.aspx");
}