Asp.net mvc 保存编辑器内容时出错
在我的应用程序中,我允许用户创建PDF文件。在我的应用程序中使用了CKEDITORAsp.net mvc 保存编辑器内容时出错,asp.net-mvc,Asp.net Mvc,在我的应用程序中,我允许用户创建PDF文件。在我的应用程序中使用了CKEDITOR function create_PDF(box) { var filename = $("#filename").val(); if (filename == "") { alert("Enter filename"); return false; } var content = CKEDITOR.in
function create_PDF(box) {
var filename = $("#filename").val();
if (filename == "") {
alert("Enter filename");
return false;
}
var content = CKEDITOR.instances["message"].getData();
if (content == "") {
alert("Enter Content in The Editor");
return false;
}
content = content.trim();
dhtmlx.modalbox.hide(box);
dhtmlx.message("Saving file...");
$.post("/FileUpload/CreateNewPDFile",
{
filename: '' + filename + '', content: '' + content + ''
}, function (data) {
alert("PDF File created succesfully");
CKEDITOR.instances["message"].setData("");
});
}
CreateNewPdfile控制器代码为:
public ActionResult CreateNewPDFile(FormCollection data)
{
var filename = data["filename"];
var htmlContent = data["content"];
string sFilePath = Server.MapPath(_createdPDF + filename + ".pdf");
htmlContent = htmlContent.Trim();
if (!System.IO.File.Exists(sFilePath))
{
Document doc = new Document(PageSize.A4, 10, 10, 10, 10);
doc.SetMargins(50, 50, 50, 50);
doc.SetPageSize(new iTextSharp.text.Rectangle(iTextSharp.text.PageSize.LETTER.Width, iTextSharp.text.PageSize.LETTER.Height));
PdfWriter.GetInstance(doc, new System.IO.FileStream(sFilePath, System.IO.FileMode.Create));
iTextSharp.text.Font fnt = FontFactory.GetFont("Times New Roman", 14);
doc.Open();
PdfPTable pdfTab = new PdfPTable(1);
PdfPCell pdfCell = null;
pdfCell = new PdfPCell(new Phrase(new Chunk(htmlContent)));
pdfTab.AddCell(pdfCell);
doc.Add(pdfTab);
doc.Close();
Response.ContentType = "application/pdf";
System.Web.HttpContext.Current.Response.Write(doc);
Response.Flush();
Response.End();
}
return View();
}
PDF文件已成功创建,但其中显示HTML内容
例如:如果我在文件中插入了单选按钮,而不是在新创建的文件中插入了单选按钮,则会显示
<input name="age" type="radio"
而不是单选按钮。
如何避免html内容?PDF不支持html单选按钮。你真的想要打印屏幕吗?@Shivan Raptor我想允许用户在PDF中的光标位置添加表单字段。我该怎么做呢?PDF不像HTML那样动态。您不能允许用户在PDF中的光标位置添加表单字段
@Shivan Raptor如何允许用户在新的PDF文件中添加表单字段。请使用Acrobat或其他类似软件(但不是asp.net)使其: