iTextSharp,处理模板 [英] iTextSharp, deal with template

查看:81
本文介绍了iTextSharp,处理模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我是iTextSharp的新手,我想通过更新现有的模板pdf获得一个新的pdf文件,我按照本教程

http://simpledotnetsolutions.wordpress.com/2012/04/08/itextsharp-few-c-examples/



i有问题fillPDFForm()

这是我的代码:

  public   string  P_InputStream =  模板/检验.pdf; 
public string P_OutputStream = output / test.pdf;

public template()
{
InitializeComponent();
}

private void template_Load( object sender,EventArgs e)
{
string formFile = P_InputStream;
string newFile = P_OutputStream;
PdfReader reader = new PdfReader(formFile);
使用(PdfStamper stamper = new PdfStamper(reader, new FileStream(newFile,FileMode.Create)))
{
AcroFields fields = stamper.AcroFields;

// 设置表单字段
fields.SetField(< span class =code-string>
customerName John Doe);
fields.SetField( Address xxxxx,yyyy);
fields.SetField( 测试 12345);

// 展平表单字段和关闭文档
压模。 FormFlattening = true ;
stamper.Close();
}
}





表单加载后,pdf文件中的数据仍然相同,din不要更新。也许我dint正确创建PDF文件?这就是我的方式:

1.我打开一个开放的办公室作家

2.在变量选项卡下插入字段>>为类型选择设置变量和一般为格式

3.输入名称,然后点击插入。

4.文件>导出为PDF



我这样做了吗?

解决方案

代码没有问题,是我们创建pdf文件的方式,请按照本教程:



http://michaellenahan.blogspot .com / 2008/08 / server-side-pdf-form-generation-with.html [ ^ ]


hey everyone, im new to iTextSharp, i wanted to have a new pdf file by update the existing template pdf, and i followed this tutorial
http://simpledotnetsolutions.wordpress.com/2012/04/08/itextsharp-few-c-examples/

i have a problem with fillPDFForm()
this is my code:

public string P_InputStream = "template/test.pdf";
public string P_OutputStream = "output/test.pdf";

 public template()
 {
     InitializeComponent();
 }
 
private void template_Load(object sender, EventArgs e)
 {
     string formFile = P_InputStream;
     string newFile = P_OutputStream;
     PdfReader reader = new PdfReader(formFile);
     using (PdfStamper stamper = new PdfStamper(reader, new FileStream(newFile, FileMode.Create)))
     {
         AcroFields fields = stamper.AcroFields;

         // set form fields
         fields.SetField("customerName", "John Doe");
         fields.SetField("Address", "xxxxx, yyyy");
         fields.SetField("Test", "12345");

         // flatten form fields and close document
         stamper.FormFlattening = true;
         stamper.Close();
     }
 }



after the form load, the data inside the pdf file is still the same, din''t update. perhaps i dint create the pdf file properly? this is how i did:
1. i open a open office writer
2.Insert Fields>under Variables tab>choose "Set Variable" for Type and "General for Format
3.type the name, and click Insert.
4. File>Export as PDF

am i doing this right?

解决方案

nothing wrong with the code, is the way how we create the pdf file, follow this tutorial:

http://michaellenahan.blogspot.com/2008/08/server-side-pdf-form-generation-with.html[^]


这篇关于iTextSharp,处理模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆