0
PDF这是我的控制器类: -错误生成使用iTextSharp的
public class PlantHeadController : Controller
{
private WOMSEntities2 db = new WOMSEntities2();
//
// GET: /PlantHead/
Document doc = new Document();
static String[] tt=new String[20];
public ActionResult Index()
{
ViewBag.productCode = new SelectList(db.Product, "ID","code");
return View();
}
public void Convert()
{
PdfWriter.GetInstance(doc, new
FileStream((Request.PhysicalApplicationPath + "\\Receipt3.pdf"),
FileMode.Create));
doc.Open();
PdfPTable table = new PdfPTable(2);
doc.AddCreationDate();
PdfPCell cell = new PdfPCell(new Phrase("Receipt"));
cell.Colspan = 3;
cell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
table.AddCell(cell);
table.AddCell("ahym");
table.AddCell("ram";
table.AddCell("good");
table.AddCell("morning");
String rawGroup = "";
foreach (String lll in raw)
rawGroup = rawGroup + lll+" ";
table.AddCell("" + rawGroup);
doc.Add(table);
doc.Close();
Response.Redirect("~/Receipt3.pdf");
}
}
每当我按下提交按钮,使PDF文件,则该错误窗口打开: -
意味着PDF是不是成功生成。在某些情况下,会显示旧的pdf。请给我建议我该怎么办?
+1在浏览器问题上。在尝试浏览到PDF文件时,我在许多网站上得到了完全相同的错误....但是,然后右键单击+另存为,它工作正常。 – maciek
使用语句的Sie正在创建错误,请告诉我该怎么做。 –
@Pushpendra Kuntal,我降级了上面的代码,你现在应该可以使用 –