zoukankan      html  css  js  c++  java
  • 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 .
  • 相关阅读:
    你必须会的 JDK 动态代理和 CGLIB 动态代理
    Dubbo 扩展点加载机制:从 Java SPI 到 Dubbo SPI
    volatile 手摸手带你解析
    Dubbo之服务消费原理
    Dubbo之服务暴露
    ElasticSearch之映射常用操作
    Redis5新特性Streams作消息队列
    .NET 开源项目 StreamJsonRpc 介绍[下篇]
    .NET 开源项目 StreamJsonRpc 介绍[中篇]
    .NET 开源项目 StreamJsonRpc 介绍 [上篇]
  • 原文地址:https://www.cnblogs.com/lovebanyi/p/1202586.html
Copyright © 2011-2022 走看看