• From Single PDF template Make a series PDF


    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 .
  • 相关阅读:
    eharts入门篇一
    手机侧滑导航栏
    用js+cookie实现商城的购物车功能
    实现文字底部居中
    超出两行或三行显示省略号
    clear-fix清除浮动的两种写法
    sass学习入门篇(三)
    如何回答面试中问到的Hibernate和MyBatis的区别
    设计模式之--单例模式
    设计模式之---工厂模式
  • 原文地址:https://www.cnblogs.com/lovebanyi/p/1202586.html
Copyright © 2020-2023  润新知