探知,不断发现
探知不断发现
Some Times we need make a series PDF from an single PDF template

from above two article we know how to make an single pdf. and how to add page to new pdf.



From some other actile of internet we may be get  writer.CopyAcroForm(reader)
but i find just the last PDF(copy from the single pdf) have these values.
other fields are empty

Ok How to do it.
MemoryStream stream = new MemoryStream();
            Document doc 
= new Document();
            PdfCopy writer 
= new PdfCopy(doc, stream);
            doc.Open();


            
string path;
            path 
= HttpContext.Current.Server.MapPath("~/templae.pdf");
            
string sessionID = HttpContext.Current.Session.LCID.ToString();
            
string path2 = HttpContext.Current.Server.MapPath("~/PDFTemplate/Temp" + sessionID + ".pdf");
            PdfImportedPage page;


            
for (int i = 0; i < list.Count; i++)
            
{

                
//MemoryStream itemStream = new MemoryStream();
                FileStream itemStream = new FileStream(path2, FileMode.Create);
                PdfReader reader 
= new PdfReader(path);
                
int kk = reader.NumberOfPages;
                PdfStamper stamper 
= new PdfStamper(reader, itemStream);
                AcroFields af 
= stamper.AcroFields;

                af.SetField(
"CurrentDate", DateTime.Now.ToString());
              
                af.RenameField(
"CurrentDate""CurrentDate_" + i);
                          stamper.Close();

               
                PdfReader pf 
= new PdfReader(path2);

                page 
=  writer.GetImportedPage(pf, 1);
                writer.AddPage(page);
                page 
= writer.GetImportedPage(pf, 2);
                writer.AddPage(page);

                pf.Close();

              
            }

            File.Delete(path2); 
/// delete the temp file
            doc.Close();
            
return stream;


as you see i am use filestream. i can't use MemoryStream. some error was occur.

lovebanyi lookcode.net 风云

如何去合并一个含有多个acroform数据的pdf
How to merge more AcroForm .
posted on 2008-05-19 15:16  lovebanyi  阅读(533)  评论(0编辑  收藏  举报