1

我有这个例子以编程方式填充 FDF 并将其可视化。

private readonly string pdfFormFileName = "PDFForm.pdf";

protected void OpenPDF_Click(object sender, EventArgs e)
{
    Response.Clear();
    Response.ContentType = "application/vnd.fdf";

    FdfWriter fdfWriter = new FdfWriter();

    fdfWriter.File = GetAbsolutePath() + pdfFormFileName;

    fdfWriter.SetFieldAsName("txtFirstName", FirstName.Text);
    fdfWriter.SetFieldAsName("txtLastName", LastName.Text);

    Response.AddHeader("Content-disposition", "inline; filename=FlatPDFForm.fdf");        
    fdfWriter.WriteTo(Response.OutputStream);        
    Response.End();
}

我需要将其保存到文件中,而不是显示文件。

你能帮帮我吗?

4

2 回答 2

2

我找到了解决方案!

string newFile = Server.MapPath("~/") + "ModF23_Final.pdf";
string pdfTemplate = Server.MapPath("~/") + "ModF23.pdf";

PdfReader pdfReader = new PdfReader(pdfTemplate);
PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileStream(newFile, FileMode.Create));
AcroFields pdfFormFields = pdfStamper.AcroFields;
pdfFormFields.SetField("2", FirstName.Text);
pdfFormFields.SetField("2-1", LastName.Text);
pdfStamper.FormFlattening = true;
pdfStamper.Close();
于 2012-11-27T21:16:09.680 回答
0

安德里亚你能尝试使用这行代码吗

Response.ClearHeaders();
Response.ContentType = "application/vnd.fdf";
Response.Clear();
Response.AppendHeader("Content-Disposition", "attachment;Filename=FlatPDFForm.fdf");
Response.TransmitFile("FlatPDFForm.fdf");
Response.End();

注释掉这一行 fdfWriter.WriteTo(Response.OutputStream);

添加了正确的 ContentType

于 2012-11-27T18:50:50.510 回答