我尝试使用 pechkin.dll 将 HTML 文件转换为 PDF。在本地主机它工作。但是当我将项目上传到服务器时,我无法转换文件。我收到一个错误:“内部服务器错误 500”。你能告诉如何解决这个问题吗?请帮忙。
这是 ajax 脚本(它工作正常)
var HTML = document.documentElement.outerHTML.toString();
console.log(HTML.toString());
var dataToSend = JSON.stringify({'test': HTML});
console.log(dataToSend);
$.ajax({
url: "medicalPrintForm.aspx/test",
data: dataToSend,
type: "POST",
dataType: "json",
contentType: "application/json; charset-utf-8",
success: OnSuccess,
error: OnError
});
这是我在后面的代码中转换文件的代码
[System.Web.Services.WebMethod(EnableSession = true)]
public static string test(string test)
{
convertFunction(test);
return test;
}
private static void convertFunction(string test)
{
int id = Convert.ToInt32(HttpContext.Current.Session["insertID"].ToString());
string fileName1 = @"D:\web\Mcer\HtmlPage1.html";
if (!Directory.Exists(Path.GetDirectoryName(fileName1)))
{
Directory.CreateDirectory(Path.GetDirectoryName(fileName1));
FileStream file = File.Create(fileName1);
StreamWriter wt = new StreamWriter(file, Encoding.UTF8);
wt.WriteLine(test);
file.Close();
}
else
{
File.Delete(fileName1);
FileStream file = File.Create(fileName1);
StreamWriter wt = new StreamWriter(file, Encoding.UTF8);
wt.WriteLine(test);
file.Close();
}
//convert html to pdf
var pechkin = Factory.Create(new GlobalConfig());
var pdf = pechkin.Convert(new ObjectConfig()
.SetLoadImages(true).SetZoomFactor(1.5)
.SetPrintBackground(true)
.SetScreenMediaType(true)
.SetCreateExternalLinks(true)
.SetPageUri("http://192.168.24.36/medcer/HtmlPage1.html"));
//return pdf file
SqlConnection EMR_Conn = new SqlConnection(@"Data Source=192.168.24.36;Initial Catalog=EMR;Persist Security Info=True;User ID=sa;Password=bpk$1234");
EMR_Conn.Open();
SqlCommand cmd = new SqlCommand("select hncode from MED_main where rowID = '" + id + "'", EMR_Conn);
SqlDataReader dr;
DataTable dt;
String hn = "";
string printerName = HttpContext.Current.Session["pathPrint"].ToString();
dr = cmd.ExecuteReader();
dt = new DataTable();
dt.Load(dr);
if (dt.Rows.Count != 0)
{
hn = dt.Rows[0]["hncode"].ToString().Trim();
}
dr.Close();
EMR_Conn.Close();
if (hn != "")
{
string fileName = @"D:\web\Mcer\PDFs\" + id + ")" + hn + ".pdf";
if (!Directory.Exists(Path.GetDirectoryName(fileName)))
{
Directory.CreateDirectory(Path.GetDirectoryName(fileName));
FileStream file = File.Create(fileName);
file.Write(pdf, 0, pdf.Length);
file.Close();
//print function
Process printJob = new Process();
printJob.StartInfo.FileName = fileName;
printJob.StartInfo.Arguments = printerName;
printJob.StartInfo.Verb = "printto";
printJob.StartInfo.CreateNoWindow = true;
printJob.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
PrinterSettings setting = new PrinterSettings();
setting.DefaultPageSettings.Landscape = true;
printJob.Start();
printJob.Close();
}
else
{
File.Delete(fileName);
FileStream file = File.Create(fileName);
file.Write(pdf, 0, pdf.Length);
file.Close();
//print function
Process printJob = new Process();
printJob.StartInfo.FileName = fileName;
printJob.StartInfo.Arguments = printerName;
printJob.StartInfo.Verb = "printto";
printJob.StartInfo.CreateNoWindow = true;
printJob.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
PrinterSettings setting = new PrinterSettings();
setting.DefaultPageSettings.Landscape = true;
printJob.Start();
printJob.Close();
}
}
}
请帮帮我。太感谢了。